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