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