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