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