blob: 009d5309d16ea9cb8cb54477824ae6bfb3e4c556 [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 Grey1db35a02023-02-26 12:52:37 +00005
Skyler Greyd757e7b2023-01-25 21:29:18 +00006 nix-index-database.url = "github:Mic92/nix-index-database";
7 nix-index-database.inputs.nixpkgs.follows = "nixpkgs";
8
Skyler Grey1db35a02023-02-26 12:52:37 +00009 nixpkgs-unfree.url = "github:numtide/nixpkgs-unfree";
10 nixpkgs-unfree.inputs.nixpkgs.follows = "nixpkgs";
11
Skyler Grey2f9904e2022-09-05 03:18:02 +010012 nixpkgs-minion.url = "github:Minion3665/nixpkgs";
Skyler Greybcb2cb72022-08-21 07:24:35 +010013 flake-utils.url = "github:numtide/flake-utils";
Skyler Grey6be25172022-10-30 22:58:55 +000014 flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus";
Skyler Grey1db35a02023-02-26 12:52:37 +000015 crane.url = "github:ipetkov/crane";
Skyler Grey2a7ca382022-09-01 23:15:31 +010016 vscode-extensions.url = "github:AmeerTaweel/nix-vscode-marketplace";
Skyler Greybcb2cb72022-08-21 07:24:35 +010017 registry = {
18 url = "github:nixos/flake-registry";
19 flake = false;
20 };
Skyler Greya7884fe2023-02-19 22:57:46 +000021 mommy = {
22 url = "github:sudofox/shell-mommy/b4e9f50cecd4ebbf39f8c426315e2040c5623db7";
23 flake = false;
24 };
Skyler Greyf8f06532022-11-04 10:58:38 +000025 home-manager.url = "github:nix-community/home-manager";
Skyler Greybcb2cb72022-08-21 07:24:35 +010026 sops-nix.url = "github:Mic92/sops-nix";
27 impermanence.url = "github:nix-community/impermanence";
Skyler Grey2a7ca382022-09-01 23:15:31 +010028 gtimelog = {
29 url = "git+https://gitlab.collabora.com/collabora/gtimelog.git";
30 flake = false;
31 };
Skyler Grey934f1422022-09-04 11:50:04 +010032 fzf-tab = {
33 url = "github:Aloxaf/fzf-tab";
34 flake = false;
35 };
Skyler Greya589ea12022-10-31 00:03:57 +000036 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 Grey61635852022-10-31 00:27:04 +000044 fenix.url = "github:nix-community/fenix";
Skyler Grey5631f962023-02-19 23:31:19 +000045 nps.url = "github:OleMussmann/Nix-Package-Search";
Skyler Grey14027172023-01-15 09:49:53 +000046 lanzaboote.url = "github:nix-community/lanzaboote";
Skyler Greybcb2cb72022-08-21 07:24:35 +010047
Skyler Grey61635852022-10-31 00:27:04 +000048 fenix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey6be25172022-10-30 22:58:55 +000049 flake-utils-plus.inputs.flake-utils.follows = "flake-utils";
Skyler Greybcb2cb72022-08-21 07:24:35 +010050 home-manager.inputs.nixpkgs.follows = "nixpkgs";
51 sops-nix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey5631f962023-02-19 23:31:19 +000052 nps.inputs.nixpkgs.follows = "nixpkgs";
53 nps.inputs.flake-utils.follows = "flake-utils";
Skyler Grey1db35a02023-02-26 12:52:37 +000054 crane.inputs.nixpkgs.follows = "nixpkgs";
55 crane.inputs.flake-utils.follows = "flake-utils";
Skyler Grey14027172023-01-15 09:49:53 +000056 lanzaboote.inputs.nixpkgs.follows = "nixpkgs";
57 lanzaboote.inputs.flake-utils.follows = "flake-utils";
58 lanzaboote.inputs.crane.follows = "crane";
Skyler Grey7dfe5c62022-08-20 21:41:30 +010059 };
Skyler Grey0409e462022-08-19 23:40:48 +010060
Skyler Grey252927a2022-10-18 22:18:15 +010061 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 Grey7dfe5c62022-08-20 21:41:30 +010068 inherit system;
Skyler Greybcc63992023-01-25 21:43:55 +000069 overlays = import ./overlays nixpkgs.lib (inputs // {
70 inherit inputs
71 username;
72 });
Skyler Grey48c9b9a2023-04-15 14:37:49 +000073 replaceStdenv = { pkgs }: pkgs.ccacheStdenv;
Skyler Grey7dfe5c62022-08-20 21:41:30 +010074 };
Skyler Grey252927a2022-10-18 22:18:15 +010075
Skyler Grey3a9a2b12023-02-13 08:04:05 +000076 utils = import ./utils pkgs;
Skyler Grey252927a2022-10-18 22:18:15 +010077
78 username = "minion";
79
80 isAttrType = type:
81 if builtins.elem type.name [ "submodule" ]
82 then true
83 else if type ? nestedTypes.elemType
84 then isAttrType type.nestedTypes.elemType
85 else false;
86
87 normalizeOptions = options:
88 if
89 nixpkgs.lib.traceSeqN 2
90 {
91 inherit options;
92 type = builtins.typeOf options;
93 }
94 builtins.typeOf
95 options
96 == "set"
97 then
98 nixpkgs.lib.mapAttrs
99 (
100 name: value:
101 if
102 nixpkgs.lib.traceSeqN 3
103 {
104 inherit name value;
105 hasGetSubOpts = value ? getSubOptions;
106 hasType = value ? type;
107 isAttrType = value ? type && isAttrType value.type;
108 typeName = value.type.name or "unnamed";
109 type = builtins.typeOf value;
110 }
111 (builtins.typeOf value)
112 == "set"
113 then
114 nixpkgs.lib.traceVal
115 (normalizeOptions (
116 if value ? type && isAttrType value.type
117 then nixpkgs.lib.traceVal (value.type.getSubOptions [ ])
118 else nixpkgs.lib.traceVal value
119 ))
120 else value
121 )
122 options
123 else options;
Skyler Greybcc63992023-01-25 21:43:55 +0000124
125 evalTrace = config: trace:
126 let
127 lib = nixpkgs.lib;
128 splitTrace = lib.splitString "." trace;
129 traceHead = builtins.head splitTrace;
130 traceTail = builtins.tail splitTrace;
131 resolvedTrace =
132 (
133 if traceHead == "home"
134 then [ "home-manager" "users" username ]
Skyler Greyd757e7b2023-01-25 21:29:18 +0000135 else lib.throwIfNot (traceHead == "config") ''You need to trace either home.** or config.** (found "${traceHead}" in "${trace}")'' [ ]
136 )
Skyler Greybcc63992023-01-25 21:43:55 +0000137 ++ traceTail;
138 in
139 (
140 lib.pipe resolvedTrace [
141 (lib.foldl
142 ({ value
143 , error
144 ,
145 }: key:
146 if builtins.hasAttr key value
147 then {
148 value = value.${key};
149 inherit error;
150 }
151 else {
152 value = { };
Skyler Greyd757e7b2023-01-25 21:29:18 +0000153 error =
154 if error == false
155 then ''"${key}" does not exist in set "${builtins.toJSON value}"''
156 else error;
Skyler Greybcc63992023-01-25 21:43:55 +0000157 })
158 {
Skyler Grey95a223c2023-02-26 12:48:24 +0000159 value = config;
Skyler Greybcc63992023-01-25 21:43:55 +0000160 error = false;
161 })
Skyler Grey95a223c2023-02-26 12:48:24 +0000162 (data: lib.warnIf (data.error != false) ''trace/${trace} is invalid; the key ${data.error}'' data)
Skyler Greybcc63992023-01-25 21:43:55 +0000163 ({ value
164 , error
165 ,
166 }: {
167 value = builtins.toJSON value;
168 inherit error;
169 })
170 ({ value
171 , error
172 ,
173 }: {
Skyler Grey5631f962023-02-19 23:31:19 +0000174 value = "trace/${trace}: ${value}";
Skyler Greybcc63992023-01-25 21:43:55 +0000175 inherit error;
176 })
177 ({ value
178 , error
179 ,
180 }:
Skyler Grey95a223c2023-02-26 12:48:24 +0000181 lib.warnIf (!error) value null)
Skyler Greybcc63992023-01-25 21:43:55 +0000182 ]
183 );
Skyler Grey252927a2022-10-18 22:18:15 +0100184 in
185 {
Skyler Greyd757e7b2023-01-25 21:29:18 +0000186 packages = {
187 nixosConfigurations =
188 let
189 nixosSystem = (nixpkgs.lib.nixosSystem
190 {
191 inherit system;
Skyler Grey252927a2022-10-18 22:18:15 +0100192
Skyler Grey725f2bd2023-03-26 11:18:13 +0000193 modules =
194 let
195 modulesIn = folder:
196 (nixpkgs.lib.pipe folder [
197 utils.nixFilesIn
198 (utils.interpretNonstandardModule (args:
199 args
200 // {
201 home = args.config.home-manager.users.${username};
202 home-options =
203 nixpkgs.lib.traceVal (normalizeOptions
204 (args.options.home-manager.users.type.getSubOptions [ ]));
205 inherit system utils;
206 }))
207 ]);
208 in
209 [
210 (modulesIn ./modules)
211 (modulesIn ./internal)
212 {
213 minion = import ./config.nix;
214 }
215 ];
Skyler Grey252927a2022-10-18 22:18:15 +0100216
Skyler Greyd757e7b2023-01-25 21:29:18 +0000217 specialArgs = inputs // { inherit inputs username; };
218 });
219 in
220 {
221 default = builtins.deepSeq
222 (map (evalTrace nixosSystem.config) nixosSystem.config.internal.traces)
223 nixosSystem;
224 };
Skyler Greyc767aa82023-02-24 09:04:17 +0000225 inherit pkgs;
Skyler Greyd757e7b2023-01-25 21:29:18 +0000226 } // (import ./overlays/packages.nix
Skyler Greyc767aa82023-02-24 09:04:17 +0000227 { inherit (inputs) fenix crane nixpkgs-minion; }
Skyler Greyd757e7b2023-01-25 21:29:18 +0000228 pkgs
229 pkgs);
Skyler Grey252927a2022-10-18 22:18:15 +0100230 devShell = pkgs.mkShell {
231 nativeBuildInputs = with pkgs; [ nodePackages.prettier nixpkgs-fmt ];
232 buildInputs = [ ];
233 };
234 formatter = pkgs.nixpkgs-fmt;
235 });
Skyler Grey0409e462022-08-19 23:40:48 +0100236}