blob: bf2c78dabdeb75c6258f58f4d09e8932d7b1aa61 [file] [log] [blame]
Skyler Grey0409e462022-08-19 23:40:48 +01001{
2 description = "Minion's NixOS configuration (since 2022-08-19)";
Skyler Greybcb2cb72022-08-21 07:24:35 +01003 inputs = {
4 nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
Skyler Grey5a423222023-05-01 08:11:28 +00005 nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-22.05";
Skyler Grey1db35a02023-02-26 12:52:37 +00006
Skyler Greyd757e7b2023-01-25 21:29:18 +00007 nix-index-database.url = "github:Mic92/nix-index-database";
8 nix-index-database.inputs.nixpkgs.follows = "nixpkgs";
9
Skyler Grey1db35a02023-02-26 12:52:37 +000010 nixpkgs-unfree.url = "github:numtide/nixpkgs-unfree";
11 nixpkgs-unfree.inputs.nixpkgs.follows = "nixpkgs";
12
Skyler Grey2f9904e2022-09-05 03:18:02 +010013 nixpkgs-minion.url = "github:Minion3665/nixpkgs";
Skyler Greybcb2cb72022-08-21 07:24:35 +010014 flake-utils.url = "github:numtide/flake-utils";
Skyler Grey6be25172022-10-30 22:58:55 +000015 flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus";
Skyler Grey1db35a02023-02-26 12:52:37 +000016 crane.url = "github:ipetkov/crane";
Skyler Grey2a7ca382022-09-01 23:15:31 +010017 vscode-extensions.url = "github:AmeerTaweel/nix-vscode-marketplace";
Skyler Greybcb2cb72022-08-21 07:24:35 +010018 registry = {
19 url = "github:nixos/flake-registry";
20 flake = false;
21 };
Skyler Greya7884fe2023-02-19 22:57:46 +000022 mommy = {
23 url = "github:sudofox/shell-mommy/b4e9f50cecd4ebbf39f8c426315e2040c5623db7";
24 flake = false;
25 };
Skyler Greyf8f06532022-11-04 10:58:38 +000026 home-manager.url = "github:nix-community/home-manager";
Skyler Greybcb2cb72022-08-21 07:24:35 +010027 sops-nix.url = "github:Mic92/sops-nix";
28 impermanence.url = "github:nix-community/impermanence";
Skyler Grey2a7ca382022-09-01 23:15:31 +010029 gtimelog = {
30 url = "git+https://gitlab.collabora.com/collabora/gtimelog.git";
31 flake = false;
32 };
Skyler Grey934f1422022-09-04 11:50:04 +010033 fzf-tab = {
34 url = "github:Aloxaf/fzf-tab";
35 flake = false;
36 };
Skyler Greya589ea12022-10-31 00:03:57 +000037 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 Grey61635852022-10-31 00:27:04 +000045 fenix.url = "github:nix-community/fenix";
Skyler Grey5631f962023-02-19 23:31:19 +000046 nps.url = "github:OleMussmann/Nix-Package-Search";
Skyler Grey14027172023-01-15 09:49:53 +000047 lanzaboote.url = "github:nix-community/lanzaboote";
Skyler Greybcb2cb72022-08-21 07:24:35 +010048
Skyler Grey5a423222023-05-01 08:11:28 +000049 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 Grey61635852022-10-31 00:27:04 +000068 fenix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey6be25172022-10-30 22:58:55 +000069 flake-utils-plus.inputs.flake-utils.follows = "flake-utils";
Skyler Greybcb2cb72022-08-21 07:24:35 +010070 home-manager.inputs.nixpkgs.follows = "nixpkgs";
71 sops-nix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey5631f962023-02-19 23:31:19 +000072 nps.inputs.nixpkgs.follows = "nixpkgs";
73 nps.inputs.flake-utils.follows = "flake-utils";
Skyler Grey1db35a02023-02-26 12:52:37 +000074 crane.inputs.nixpkgs.follows = "nixpkgs";
75 crane.inputs.flake-utils.follows = "flake-utils";
Skyler Grey14027172023-01-15 09:49:53 +000076 lanzaboote.inputs.nixpkgs.follows = "nixpkgs";
77 lanzaboote.inputs.flake-utils.follows = "flake-utils";
78 lanzaboote.inputs.crane.follows = "crane";
Skyler Grey5a423222023-05-01 08:11:28 +000079 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 Grey7dfe5c62022-08-20 21:41:30 +010089 };
Skyler Grey0409e462022-08-19 23:40:48 +010090
Skyler Grey252927a2022-10-18 22:18:15 +010091 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 Grey7dfe5c62022-08-20 21:41:30 +010098 inherit system;
Skyler Greybcc63992023-01-25 21:43:55 +000099 overlays = import ./overlays nixpkgs.lib (inputs // {
100 inherit inputs
101 username;
102 });
Skyler Grey48c9b9a2023-04-15 14:37:49 +0000103 replaceStdenv = { pkgs }: pkgs.ccacheStdenv;
Skyler Grey7dfe5c62022-08-20 21:41:30 +0100104 };
Skyler Grey252927a2022-10-18 22:18:15 +0100105
Skyler Grey3a9a2b12023-02-13 08:04:05 +0000106 utils = import ./utils pkgs;
Skyler Grey252927a2022-10-18 22:18:15 +0100107
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 Greybcc63992023-01-25 21:43:55 +0000154
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 Greyd757e7b2023-01-25 21:29:18 +0000165 else lib.throwIfNot (traceHead == "config") ''You need to trace either home.** or config.** (found "${traceHead}" in "${trace}")'' [ ]
166 )
Skyler Greybcc63992023-01-25 21:43:55 +0000167 ++ 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 Greyd757e7b2023-01-25 21:29:18 +0000183 error =
184 if error == false
185 then ''"${key}" does not exist in set "${builtins.toJSON value}"''
186 else error;
Skyler Greybcc63992023-01-25 21:43:55 +0000187 })
188 {
Skyler Grey95a223c2023-02-26 12:48:24 +0000189 value = config;
Skyler Greybcc63992023-01-25 21:43:55 +0000190 error = false;
191 })
Skyler Grey95a223c2023-02-26 12:48:24 +0000192 (data: lib.warnIf (data.error != false) ''trace/${trace} is invalid; the key ${data.error}'' data)
Skyler Greybcc63992023-01-25 21:43:55 +0000193 ({ value
194 , error
195 ,
196 }: {
197 value = builtins.toJSON value;
198 inherit error;
199 })
200 ({ value
201 , error
202 ,
203 }: {
Skyler Grey5631f962023-02-19 23:31:19 +0000204 value = "trace/${trace}: ${value}";
Skyler Greybcc63992023-01-25 21:43:55 +0000205 inherit error;
206 })
207 ({ value
208 , error
209 ,
210 }:
Skyler Grey95a223c2023-02-26 12:48:24 +0000211 lib.warnIf (!error) value null)
Skyler Greybcc63992023-01-25 21:43:55 +0000212 ]
213 );
Skyler Grey252927a2022-10-18 22:18:15 +0100214 in
215 {
Skyler Greyd757e7b2023-01-25 21:29:18 +0000216 packages = {
217 nixosConfigurations =
218 let
219 nixosSystem = (nixpkgs.lib.nixosSystem
220 {
221 inherit system;
Skyler Grey252927a2022-10-18 22:18:15 +0100222
Skyler Grey725f2bd2023-03-26 11:18:13 +0000223 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 Grey252927a2022-10-18 22:18:15 +0100246
Skyler Greyd757e7b2023-01-25 21:29:18 +0000247 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 Greyc767aa82023-02-24 09:04:17 +0000255 inherit pkgs;
Skyler Greyd757e7b2023-01-25 21:29:18 +0000256 } // (import ./overlays/packages.nix
Skyler Greyc767aa82023-02-24 09:04:17 +0000257 { inherit (inputs) fenix crane nixpkgs-minion; }
Skyler Greyd757e7b2023-01-25 21:29:18 +0000258 pkgs
259 pkgs);
Skyler Grey252927a2022-10-18 22:18:15 +0100260 devShell = pkgs.mkShell {
261 nativeBuildInputs = with pkgs; [ nodePackages.prettier nixpkgs-fmt ];
262 buildInputs = [ ];
263 };
264 formatter = pkgs.nixpkgs-fmt;
265 });
Skyler Grey0409e462022-08-19 23:40:48 +0100266}