blob: 6672843150ebb56a00cf0efcb8644913509fce93 [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 Greyf8f06532022-11-04 10:58:38 +000021 home-manager.url = "github:nix-community/home-manager";
Skyler Greybcb2cb72022-08-21 07:24:35 +010022 sops-nix.url = "github:Mic92/sops-nix";
23 impermanence.url = "github:nix-community/impermanence";
Skyler Grey2a7ca382022-09-01 23:15:31 +010024 gtimelog = {
25 url = "git+https://gitlab.collabora.com/collabora/gtimelog.git";
26 flake = false;
27 };
Skyler Grey934f1422022-09-04 11:50:04 +010028 fzf-tab = {
29 url = "github:Aloxaf/fzf-tab";
30 flake = false;
31 };
Skyler Greya589ea12022-10-31 00:03:57 +000032 omnisharp-language-server = {
33 url = "github:coc-extensions/coc-omnisharp";
34 flake = false;
35 };
36 kmonad = {
37 url = "github:kmonad/kmonad?dir=nix";
38 inputs.nixpkgs.follows = "nixpkgs";
39 };
Skyler Grey61635852022-10-31 00:27:04 +000040 fenix.url = "github:nix-community/fenix";
Skyler Grey5631f962023-02-19 23:31:19 +000041 nps.url = "github:OleMussmann/Nix-Package-Search";
Skyler Grey14027172023-01-15 09:49:53 +000042 lanzaboote.url = "github:nix-community/lanzaboote";
Skyler Greybcb2cb72022-08-21 07:24:35 +010043
Skyler Grey61635852022-10-31 00:27:04 +000044 fenix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey6be25172022-10-30 22:58:55 +000045 flake-utils-plus.inputs.flake-utils.follows = "flake-utils";
Skyler Greybcb2cb72022-08-21 07:24:35 +010046 home-manager.inputs.nixpkgs.follows = "nixpkgs";
47 sops-nix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey5631f962023-02-19 23:31:19 +000048 nps.inputs.nixpkgs.follows = "nixpkgs";
49 nps.inputs.flake-utils.follows = "flake-utils";
Skyler Grey1db35a02023-02-26 12:52:37 +000050 crane.inputs.nixpkgs.follows = "nixpkgs";
51 crane.inputs.flake-utils.follows = "flake-utils";
Skyler Grey14027172023-01-15 09:49:53 +000052 lanzaboote.inputs.nixpkgs.follows = "nixpkgs";
53 lanzaboote.inputs.flake-utils.follows = "flake-utils";
54 lanzaboote.inputs.crane.follows = "crane";
Skyler Grey7dfe5c62022-08-20 21:41:30 +010055 };
Skyler Grey0409e462022-08-19 23:40:48 +010056
Skyler Grey252927a2022-10-18 22:18:15 +010057 outputs = inputs:
58 let
59 inherit (inputs) self nixpkgs flake-utils;
60 in
61 flake-utils.lib.eachDefaultSystem (system:
62 let
63 pkgs = import nixpkgs {
Skyler Grey7dfe5c62022-08-20 21:41:30 +010064 inherit system;
Skyler Greybcc63992023-01-25 21:43:55 +000065 overlays = import ./overlays nixpkgs.lib (inputs // {
66 inherit inputs
67 username;
68 });
Skyler Grey7dfe5c62022-08-20 21:41:30 +010069 };
Skyler Grey252927a2022-10-18 22:18:15 +010070
Skyler Grey3a9a2b12023-02-13 08:04:05 +000071 utils = import ./utils pkgs;
Skyler Grey252927a2022-10-18 22:18:15 +010072
73 username = "minion";
74
75 isAttrType = type:
76 if builtins.elem type.name [ "submodule" ]
77 then true
78 else if type ? nestedTypes.elemType
79 then isAttrType type.nestedTypes.elemType
80 else false;
81
82 normalizeOptions = options:
83 if
84 nixpkgs.lib.traceSeqN 2
85 {
86 inherit options;
87 type = builtins.typeOf options;
88 }
89 builtins.typeOf
90 options
91 == "set"
92 then
93 nixpkgs.lib.mapAttrs
94 (
95 name: value:
96 if
97 nixpkgs.lib.traceSeqN 3
98 {
99 inherit name value;
100 hasGetSubOpts = value ? getSubOptions;
101 hasType = value ? type;
102 isAttrType = value ? type && isAttrType value.type;
103 typeName = value.type.name or "unnamed";
104 type = builtins.typeOf value;
105 }
106 (builtins.typeOf value)
107 == "set"
108 then
109 nixpkgs.lib.traceVal
110 (normalizeOptions (
111 if value ? type && isAttrType value.type
112 then nixpkgs.lib.traceVal (value.type.getSubOptions [ ])
113 else nixpkgs.lib.traceVal value
114 ))
115 else value
116 )
117 options
118 else options;
Skyler Greybcc63992023-01-25 21:43:55 +0000119
120 evalTrace = config: trace:
121 let
122 lib = nixpkgs.lib;
123 splitTrace = lib.splitString "." trace;
124 traceHead = builtins.head splitTrace;
125 traceTail = builtins.tail splitTrace;
126 resolvedTrace =
127 (
128 if traceHead == "home"
129 then [ "home-manager" "users" username ]
Skyler Greyd757e7b2023-01-25 21:29:18 +0000130 else lib.throwIfNot (traceHead == "config") ''You need to trace either home.** or config.** (found "${traceHead}" in "${trace}")'' [ ]
131 )
Skyler Greybcc63992023-01-25 21:43:55 +0000132 ++ traceTail;
133 in
134 (
135 lib.pipe resolvedTrace [
136 (lib.foldl
137 ({ value
138 , error
139 ,
140 }: key:
141 if builtins.hasAttr key value
142 then {
143 value = value.${key};
144 inherit error;
145 }
146 else {
147 value = { };
Skyler Greyd757e7b2023-01-25 21:29:18 +0000148 error =
149 if error == false
150 then ''"${key}" does not exist in set "${builtins.toJSON value}"''
151 else error;
Skyler Greybcc63992023-01-25 21:43:55 +0000152 })
153 {
Skyler Grey95a223c2023-02-26 12:48:24 +0000154 value = config;
Skyler Greybcc63992023-01-25 21:43:55 +0000155 error = false;
156 })
Skyler Grey95a223c2023-02-26 12:48:24 +0000157 (data: lib.warnIf (data.error != false) ''trace/${trace} is invalid; the key ${data.error}'' data)
Skyler Greybcc63992023-01-25 21:43:55 +0000158 ({ value
159 , error
160 ,
161 }: {
162 value = builtins.toJSON value;
163 inherit error;
164 })
165 ({ value
166 , error
167 ,
168 }: {
Skyler Grey5631f962023-02-19 23:31:19 +0000169 value = "trace/${trace}: ${value}";
Skyler Greybcc63992023-01-25 21:43:55 +0000170 inherit error;
171 })
172 ({ value
173 , error
174 ,
175 }:
Skyler Grey95a223c2023-02-26 12:48:24 +0000176 lib.warnIf (!error) value null)
Skyler Greybcc63992023-01-25 21:43:55 +0000177 ]
178 );
Skyler Grey252927a2022-10-18 22:18:15 +0100179 in
180 {
Skyler Greyd757e7b2023-01-25 21:29:18 +0000181 packages = {
182 nixosConfigurations =
183 let
184 nixosSystem = (nixpkgs.lib.nixosSystem
185 {
186 inherit system;
Skyler Grey252927a2022-10-18 22:18:15 +0100187
Skyler Greyd757e7b2023-01-25 21:29:18 +0000188 modules = [
189 (nixpkgs.lib.pipe ./modules [
190 utils.nixFilesIn
191 (utils.interpretNonstandardModule (args:
192 args
193 // {
194 home = args.config.home-manager.users.${username};
195 home-options =
196 nixpkgs.lib.traceVal (normalizeOptions
197 (args.options.home-manager.users.type.getSubOptions [ ]));
198 inherit system utils;
199 }))
200 ])
201 {
202 minion = import ./config.nix;
203 }
204 ];
Skyler Grey252927a2022-10-18 22:18:15 +0100205
Skyler Greyd757e7b2023-01-25 21:29:18 +0000206 specialArgs = inputs // { inherit inputs username; };
207 });
208 in
209 {
210 default = builtins.deepSeq
211 (map (evalTrace nixosSystem.config) nixosSystem.config.internal.traces)
212 nixosSystem;
213 };
214 } // (import ./overlays/packages.nix
215 { inherit (inputs) fenix crane; }
216 pkgs
217 pkgs);
Skyler Grey252927a2022-10-18 22:18:15 +0100218 devShell = pkgs.mkShell {
219 nativeBuildInputs = with pkgs; [ nodePackages.prettier nixpkgs-fmt ];
220 buildInputs = [ ];
221 };
222 formatter = pkgs.nixpkgs-fmt;
223 });
Skyler Grey0409e462022-08-19 23:40:48 +0100224}