blob: ba8ab1fdacfa37f6d47c3da2f797d500eb6c8080 [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 Grey7dfe5c62022-08-20 21:41:30 +010073 };
Skyler Grey252927a2022-10-18 22:18:15 +010074
Skyler Grey3a9a2b12023-02-13 08:04:05 +000075 utils = import ./utils pkgs;
Skyler Grey252927a2022-10-18 22:18:15 +010076
77 username = "minion";
78
79 isAttrType = type:
80 if builtins.elem type.name [ "submodule" ]
81 then true
82 else if type ? nestedTypes.elemType
83 then isAttrType type.nestedTypes.elemType
84 else false;
85
86 normalizeOptions = options:
87 if
88 nixpkgs.lib.traceSeqN 2
89 {
90 inherit options;
91 type = builtins.typeOf options;
92 }
93 builtins.typeOf
94 options
95 == "set"
96 then
97 nixpkgs.lib.mapAttrs
98 (
99 name: value:
100 if
101 nixpkgs.lib.traceSeqN 3
102 {
103 inherit name value;
104 hasGetSubOpts = value ? getSubOptions;
105 hasType = value ? type;
106 isAttrType = value ? type && isAttrType value.type;
107 typeName = value.type.name or "unnamed";
108 type = builtins.typeOf value;
109 }
110 (builtins.typeOf value)
111 == "set"
112 then
113 nixpkgs.lib.traceVal
114 (normalizeOptions (
115 if value ? type && isAttrType value.type
116 then nixpkgs.lib.traceVal (value.type.getSubOptions [ ])
117 else nixpkgs.lib.traceVal value
118 ))
119 else value
120 )
121 options
122 else options;
Skyler Greybcc63992023-01-25 21:43:55 +0000123
124 evalTrace = config: trace:
125 let
126 lib = nixpkgs.lib;
127 splitTrace = lib.splitString "." trace;
128 traceHead = builtins.head splitTrace;
129 traceTail = builtins.tail splitTrace;
130 resolvedTrace =
131 (
132 if traceHead == "home"
133 then [ "home-manager" "users" username ]
Skyler Greyd757e7b2023-01-25 21:29:18 +0000134 else lib.throwIfNot (traceHead == "config") ''You need to trace either home.** or config.** (found "${traceHead}" in "${trace}")'' [ ]
135 )
Skyler Greybcc63992023-01-25 21:43:55 +0000136 ++ traceTail;
137 in
138 (
139 lib.pipe resolvedTrace [
140 (lib.foldl
141 ({ value
142 , error
143 ,
144 }: key:
145 if builtins.hasAttr key value
146 then {
147 value = value.${key};
148 inherit error;
149 }
150 else {
151 value = { };
Skyler Greyd757e7b2023-01-25 21:29:18 +0000152 error =
153 if error == false
154 then ''"${key}" does not exist in set "${builtins.toJSON value}"''
155 else error;
Skyler Greybcc63992023-01-25 21:43:55 +0000156 })
157 {
Skyler Grey95a223c2023-02-26 12:48:24 +0000158 value = config;
Skyler Greybcc63992023-01-25 21:43:55 +0000159 error = false;
160 })
Skyler Grey95a223c2023-02-26 12:48:24 +0000161 (data: lib.warnIf (data.error != false) ''trace/${trace} is invalid; the key ${data.error}'' data)
Skyler Greybcc63992023-01-25 21:43:55 +0000162 ({ value
163 , error
164 ,
165 }: {
166 value = builtins.toJSON value;
167 inherit error;
168 })
169 ({ value
170 , error
171 ,
172 }: {
Skyler Grey5631f962023-02-19 23:31:19 +0000173 value = "trace/${trace}: ${value}";
Skyler Greybcc63992023-01-25 21:43:55 +0000174 inherit error;
175 })
176 ({ value
177 , error
178 ,
179 }:
Skyler Grey95a223c2023-02-26 12:48:24 +0000180 lib.warnIf (!error) value null)
Skyler Greybcc63992023-01-25 21:43:55 +0000181 ]
182 );
Skyler Grey252927a2022-10-18 22:18:15 +0100183 in
184 {
Skyler Greyd757e7b2023-01-25 21:29:18 +0000185 packages = {
186 nixosConfigurations =
187 let
188 nixosSystem = (nixpkgs.lib.nixosSystem
189 {
190 inherit system;
Skyler Grey252927a2022-10-18 22:18:15 +0100191
Skyler Greyd757e7b2023-01-25 21:29:18 +0000192 modules = [
193 (nixpkgs.lib.pipe ./modules [
194 utils.nixFilesIn
195 (utils.interpretNonstandardModule (args:
196 args
197 // {
198 home = args.config.home-manager.users.${username};
199 home-options =
200 nixpkgs.lib.traceVal (normalizeOptions
201 (args.options.home-manager.users.type.getSubOptions [ ]));
202 inherit system utils;
203 }))
204 ])
205 {
206 minion = import ./config.nix;
207 }
208 ];
Skyler Grey252927a2022-10-18 22:18:15 +0100209
Skyler Greyd757e7b2023-01-25 21:29:18 +0000210 specialArgs = inputs // { inherit inputs username; };
211 });
212 in
213 {
214 default = builtins.deepSeq
215 (map (evalTrace nixosSystem.config) nixosSystem.config.internal.traces)
216 nixosSystem;
217 };
Skyler Greyc767aa82023-02-24 09:04:17 +0000218 inherit pkgs;
Skyler Greyd757e7b2023-01-25 21:29:18 +0000219 } // (import ./overlays/packages.nix
Skyler Greyc767aa82023-02-24 09:04:17 +0000220 { inherit (inputs) fenix crane nixpkgs-minion; }
Skyler Greyd757e7b2023-01-25 21:29:18 +0000221 pkgs
222 pkgs);
Skyler Grey252927a2022-10-18 22:18:15 +0100223 devShell = pkgs.mkShell {
224 nativeBuildInputs = with pkgs; [ nodePackages.prettier nixpkgs-fmt ];
225 buildInputs = [ ];
226 };
227 formatter = pkgs.nixpkgs-fmt;
228 });
Skyler Grey0409e462022-08-19 23:40:48 +0100229}