Skyler Grey | 0409e46 | 2022-08-19 23:40:48 +0100 | [diff] [blame] | 1 | { |
| 2 | description = "Minion's NixOS configuration (since 2022-08-19)"; |
Skyler Grey | bcb2cb7 | 2022-08-21 07:24:35 +0100 | [diff] [blame] | 3 | inputs = { |
| 4 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; |
Skyler Grey | 1db35a0 | 2023-02-26 12:52:37 +0000 | [diff] [blame] | 5 | |
Skyler Grey | d757e7b | 2023-01-25 21:29:18 +0000 | [diff] [blame] | 6 | nix-index-database.url = "github:Mic92/nix-index-database"; |
| 7 | nix-index-database.inputs.nixpkgs.follows = "nixpkgs"; |
| 8 | |
Skyler Grey | 1db35a0 | 2023-02-26 12:52:37 +0000 | [diff] [blame] | 9 | nixpkgs-unfree.url = "github:numtide/nixpkgs-unfree"; |
| 10 | nixpkgs-unfree.inputs.nixpkgs.follows = "nixpkgs"; |
| 11 | |
Skyler Grey | 2f9904e | 2022-09-05 03:18:02 +0100 | [diff] [blame] | 12 | nixpkgs-minion.url = "github:Minion3665/nixpkgs"; |
Skyler Grey | bcb2cb7 | 2022-08-21 07:24:35 +0100 | [diff] [blame] | 13 | flake-utils.url = "github:numtide/flake-utils"; |
Skyler Grey | 6be2517 | 2022-10-30 22:58:55 +0000 | [diff] [blame] | 14 | flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus"; |
Skyler Grey | 1db35a0 | 2023-02-26 12:52:37 +0000 | [diff] [blame] | 15 | crane.url = "github:ipetkov/crane"; |
Skyler Grey | 2a7ca38 | 2022-09-01 23:15:31 +0100 | [diff] [blame] | 16 | vscode-extensions.url = "github:AmeerTaweel/nix-vscode-marketplace"; |
Skyler Grey | bcb2cb7 | 2022-08-21 07:24:35 +0100 | [diff] [blame] | 17 | registry = { |
| 18 | url = "github:nixos/flake-registry"; |
| 19 | flake = false; |
| 20 | }; |
Skyler Grey | f8f0653 | 2022-11-04 10:58:38 +0000 | [diff] [blame] | 21 | home-manager.url = "github:nix-community/home-manager"; |
Skyler Grey | bcb2cb7 | 2022-08-21 07:24:35 +0100 | [diff] [blame] | 22 | sops-nix.url = "github:Mic92/sops-nix"; |
| 23 | impermanence.url = "github:nix-community/impermanence"; |
Skyler Grey | 2a7ca38 | 2022-09-01 23:15:31 +0100 | [diff] [blame] | 24 | gtimelog = { |
| 25 | url = "git+https://gitlab.collabora.com/collabora/gtimelog.git"; |
| 26 | flake = false; |
| 27 | }; |
Skyler Grey | 934f142 | 2022-09-04 11:50:04 +0100 | [diff] [blame] | 28 | fzf-tab = { |
| 29 | url = "github:Aloxaf/fzf-tab"; |
| 30 | flake = false; |
| 31 | }; |
Skyler Grey | a589ea1 | 2022-10-31 00:03:57 +0000 | [diff] [blame] | 32 | omnisharp-language-server = { |
| 33 | url = "github:coc-extensions/coc-omnisharp"; |
| 34 | flake = false; |
| 35 | }; |
| 36 | kmonad = { |
| 37 | url = "github:kmonad/kmonad?dir=nix"; |
| 38 | inputs.nixpkgs.follows = "nixpkgs"; |
| 39 | }; |
Skyler Grey | 6163585 | 2022-10-31 00:27:04 +0000 | [diff] [blame] | 40 | fenix.url = "github:nix-community/fenix"; |
Skyler Grey | 5631f96 | 2023-02-19 23:31:19 +0000 | [diff] [blame] | 41 | nps.url = "github:OleMussmann/Nix-Package-Search"; |
Skyler Grey | 1402717 | 2023-01-15 09:49:53 +0000 | [diff] [blame] | 42 | lanzaboote.url = "github:nix-community/lanzaboote"; |
Skyler Grey | bcb2cb7 | 2022-08-21 07:24:35 +0100 | [diff] [blame] | 43 | |
Skyler Grey | 6163585 | 2022-10-31 00:27:04 +0000 | [diff] [blame] | 44 | fenix.inputs.nixpkgs.follows = "nixpkgs"; |
Skyler Grey | 6be2517 | 2022-10-30 22:58:55 +0000 | [diff] [blame] | 45 | flake-utils-plus.inputs.flake-utils.follows = "flake-utils"; |
Skyler Grey | bcb2cb7 | 2022-08-21 07:24:35 +0100 | [diff] [blame] | 46 | home-manager.inputs.nixpkgs.follows = "nixpkgs"; |
| 47 | sops-nix.inputs.nixpkgs.follows = "nixpkgs"; |
Skyler Grey | 5631f96 | 2023-02-19 23:31:19 +0000 | [diff] [blame] | 48 | nps.inputs.nixpkgs.follows = "nixpkgs"; |
| 49 | nps.inputs.flake-utils.follows = "flake-utils"; |
Skyler Grey | 1db35a0 | 2023-02-26 12:52:37 +0000 | [diff] [blame] | 50 | crane.inputs.nixpkgs.follows = "nixpkgs"; |
| 51 | crane.inputs.flake-utils.follows = "flake-utils"; |
Skyler Grey | 1402717 | 2023-01-15 09:49:53 +0000 | [diff] [blame] | 52 | lanzaboote.inputs.nixpkgs.follows = "nixpkgs"; |
| 53 | lanzaboote.inputs.flake-utils.follows = "flake-utils"; |
| 54 | lanzaboote.inputs.crane.follows = "crane"; |
Skyler Grey | 7dfe5c6 | 2022-08-20 21:41:30 +0100 | [diff] [blame] | 55 | }; |
Skyler Grey | 0409e46 | 2022-08-19 23:40:48 +0100 | [diff] [blame] | 56 | |
Skyler Grey | 252927a | 2022-10-18 22:18:15 +0100 | [diff] [blame] | 57 | outputs = inputs: |
| 58 | let |
| 59 | inherit (inputs) self nixpkgs flake-utils; |
| 60 | in |
| 61 | flake-utils.lib.eachDefaultSystem (system: |
| 62 | let |
| 63 | pkgs = import nixpkgs { |
Skyler Grey | 7dfe5c6 | 2022-08-20 21:41:30 +0100 | [diff] [blame] | 64 | inherit system; |
Skyler Grey | bcc6399 | 2023-01-25 21:43:55 +0000 | [diff] [blame] | 65 | overlays = import ./overlays nixpkgs.lib (inputs // { |
| 66 | inherit inputs |
| 67 | username; |
| 68 | }); |
Skyler Grey | 7dfe5c6 | 2022-08-20 21:41:30 +0100 | [diff] [blame] | 69 | }; |
Skyler Grey | 252927a | 2022-10-18 22:18:15 +0100 | [diff] [blame] | 70 | |
| 71 | utils = import ./utils nixpkgs.lib; |
| 72 | |
| 73 | username = "minion"; |
| 74 | |
| 75 | isAttrType = type: |
| 76 | if builtins.elem type.name [ "submodule" ] |
| 77 | then true |
| 78 | else if type ? nestedTypes.elemType |
| 79 | then isAttrType type.nestedTypes.elemType |
| 80 | else false; |
| 81 | |
| 82 | normalizeOptions = options: |
| 83 | if |
| 84 | nixpkgs.lib.traceSeqN 2 |
| 85 | { |
| 86 | inherit options; |
| 87 | type = builtins.typeOf options; |
| 88 | } |
| 89 | builtins.typeOf |
| 90 | options |
| 91 | == "set" |
| 92 | then |
| 93 | nixpkgs.lib.mapAttrs |
| 94 | ( |
| 95 | name: value: |
| 96 | if |
| 97 | nixpkgs.lib.traceSeqN 3 |
| 98 | { |
| 99 | inherit name value; |
| 100 | hasGetSubOpts = value ? getSubOptions; |
| 101 | hasType = value ? type; |
| 102 | isAttrType = value ? type && isAttrType value.type; |
| 103 | typeName = value.type.name or "unnamed"; |
| 104 | type = builtins.typeOf value; |
| 105 | } |
| 106 | (builtins.typeOf value) |
| 107 | == "set" |
| 108 | then |
| 109 | nixpkgs.lib.traceVal |
| 110 | (normalizeOptions ( |
| 111 | if value ? type && isAttrType value.type |
| 112 | then nixpkgs.lib.traceVal (value.type.getSubOptions [ ]) |
| 113 | else nixpkgs.lib.traceVal value |
| 114 | )) |
| 115 | else value |
| 116 | ) |
| 117 | options |
| 118 | else options; |
Skyler Grey | bcc6399 | 2023-01-25 21:43:55 +0000 | [diff] [blame] | 119 | |
| 120 | evalTrace = config: trace: |
| 121 | let |
| 122 | lib = nixpkgs.lib; |
| 123 | splitTrace = lib.splitString "." trace; |
| 124 | traceHead = builtins.head splitTrace; |
| 125 | traceTail = builtins.tail splitTrace; |
| 126 | resolvedTrace = |
| 127 | ( |
| 128 | if traceHead == "home" |
| 129 | then [ "home-manager" "users" username ] |
Skyler Grey | d757e7b | 2023-01-25 21:29:18 +0000 | [diff] [blame] | 130 | else lib.throwIfNot (traceHead == "config") ''You need to trace either home.** or config.** (found "${traceHead}" in "${trace}")'' [ ] |
| 131 | ) |
Skyler Grey | bcc6399 | 2023-01-25 21:43:55 +0000 | [diff] [blame] | 132 | ++ traceTail; |
| 133 | in |
| 134 | ( |
| 135 | lib.pipe resolvedTrace [ |
| 136 | (lib.foldl |
| 137 | ({ value |
| 138 | , error |
| 139 | , |
| 140 | }: key: |
| 141 | if builtins.hasAttr key value |
| 142 | then { |
| 143 | value = value.${key}; |
| 144 | inherit error; |
| 145 | } |
| 146 | else { |
| 147 | value = { }; |
Skyler Grey | d757e7b | 2023-01-25 21:29:18 +0000 | [diff] [blame] | 148 | error = |
| 149 | if error == false |
| 150 | then ''"${key}" does not exist in set "${builtins.toJSON value}"'' |
| 151 | else error; |
Skyler Grey | bcc6399 | 2023-01-25 21:43:55 +0000 | [diff] [blame] | 152 | }) |
| 153 | { |
Skyler Grey | 95a223c | 2023-02-26 12:48:24 +0000 | [diff] [blame] | 154 | value = config; |
Skyler Grey | bcc6399 | 2023-01-25 21:43:55 +0000 | [diff] [blame] | 155 | error = false; |
| 156 | }) |
Skyler Grey | 95a223c | 2023-02-26 12:48:24 +0000 | [diff] [blame] | 157 | (data: lib.warnIf (data.error != false) ''trace/${trace} is invalid; the key ${data.error}'' data) |
Skyler Grey | bcc6399 | 2023-01-25 21:43:55 +0000 | [diff] [blame] | 158 | ({ value |
| 159 | , error |
| 160 | , |
| 161 | }: { |
| 162 | value = builtins.toJSON value; |
| 163 | inherit error; |
| 164 | }) |
| 165 | ({ value |
| 166 | , error |
| 167 | , |
| 168 | }: { |
Skyler Grey | 5631f96 | 2023-02-19 23:31:19 +0000 | [diff] [blame] | 169 | value = "trace/${trace}: ${value}"; |
Skyler Grey | bcc6399 | 2023-01-25 21:43:55 +0000 | [diff] [blame] | 170 | inherit error; |
| 171 | }) |
| 172 | ({ value |
| 173 | , error |
| 174 | , |
| 175 | }: |
Skyler Grey | 95a223c | 2023-02-26 12:48:24 +0000 | [diff] [blame] | 176 | lib.warnIf (!error) value null) |
Skyler Grey | bcc6399 | 2023-01-25 21:43:55 +0000 | [diff] [blame] | 177 | ] |
| 178 | ); |
Skyler Grey | 252927a | 2022-10-18 22:18:15 +0100 | [diff] [blame] | 179 | in |
| 180 | { |
Skyler Grey | d757e7b | 2023-01-25 21:29:18 +0000 | [diff] [blame] | 181 | packages = { |
| 182 | nixosConfigurations = |
| 183 | let |
| 184 | nixosSystem = (nixpkgs.lib.nixosSystem |
| 185 | { |
| 186 | inherit system; |
Skyler Grey | 252927a | 2022-10-18 22:18:15 +0100 | [diff] [blame] | 187 | |
Skyler Grey | d757e7b | 2023-01-25 21:29:18 +0000 | [diff] [blame] | 188 | modules = [ |
| 189 | (nixpkgs.lib.pipe ./modules [ |
| 190 | utils.nixFilesIn |
| 191 | (utils.interpretNonstandardModule (args: |
| 192 | args |
| 193 | // { |
| 194 | home = args.config.home-manager.users.${username}; |
| 195 | home-options = |
| 196 | nixpkgs.lib.traceVal (normalizeOptions |
| 197 | (args.options.home-manager.users.type.getSubOptions [ ])); |
| 198 | inherit system utils; |
| 199 | })) |
| 200 | ]) |
| 201 | { |
| 202 | minion = import ./config.nix; |
| 203 | } |
| 204 | ]; |
Skyler Grey | 252927a | 2022-10-18 22:18:15 +0100 | [diff] [blame] | 205 | |
Skyler Grey | d757e7b | 2023-01-25 21:29:18 +0000 | [diff] [blame] | 206 | specialArgs = inputs // { inherit inputs username; }; |
| 207 | }); |
| 208 | in |
| 209 | { |
| 210 | default = builtins.deepSeq |
| 211 | (map (evalTrace nixosSystem.config) nixosSystem.config.internal.traces) |
| 212 | nixosSystem; |
| 213 | }; |
| 214 | } // (import ./overlays/packages.nix |
| 215 | { inherit (inputs) fenix crane; } |
| 216 | pkgs |
| 217 | pkgs); |
Skyler Grey | 252927a | 2022-10-18 22:18:15 +0100 | [diff] [blame] | 218 | devShell = pkgs.mkShell { |
| 219 | nativeBuildInputs = with pkgs; [ nodePackages.prettier nixpkgs-fmt ]; |
| 220 | buildInputs = [ ]; |
| 221 | }; |
| 222 | formatter = pkgs.nixpkgs-fmt; |
| 223 | }); |
Skyler Grey | 0409e46 | 2022-08-19 23:40:48 +0100 | [diff] [blame] | 224 | } |