blob: 0f79ccd353965c1b652a8729faa306d01d43403b [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
6 nixpkgs-unfree.url = "github:numtide/nixpkgs-unfree";
7 nixpkgs-unfree.inputs.nixpkgs.follows = "nixpkgs";
8
Skyler Grey2f9904e2022-09-05 03:18:02 +01009 nixpkgs-minion.url = "github:Minion3665/nixpkgs";
Skyler Greybcb2cb72022-08-21 07:24:35 +010010 flake-utils.url = "github:numtide/flake-utils";
Skyler Grey6be25172022-10-30 22:58:55 +000011 flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus";
Skyler Grey1db35a02023-02-26 12:52:37 +000012 crane.url = "github:ipetkov/crane";
Skyler Grey2a7ca382022-09-01 23:15:31 +010013 vscode-extensions.url = "github:AmeerTaweel/nix-vscode-marketplace";
Skyler Greybcb2cb72022-08-21 07:24:35 +010014 registry = {
15 url = "github:nixos/flake-registry";
16 flake = false;
17 };
Skyler Greyf8f06532022-11-04 10:58:38 +000018 home-manager.url = "github:nix-community/home-manager";
Skyler Greybcb2cb72022-08-21 07:24:35 +010019 sops-nix.url = "github:Mic92/sops-nix";
20 impermanence.url = "github:nix-community/impermanence";
Skyler Grey2a7ca382022-09-01 23:15:31 +010021 gtimelog = {
22 url = "git+https://gitlab.collabora.com/collabora/gtimelog.git";
23 flake = false;
24 };
Skyler Grey934f1422022-09-04 11:50:04 +010025 fzf-tab = {
26 url = "github:Aloxaf/fzf-tab";
27 flake = false;
28 };
Skyler Greya589ea12022-10-31 00:03:57 +000029 omnisharp-language-server = {
30 url = "github:coc-extensions/coc-omnisharp";
31 flake = false;
32 };
33 kmonad = {
34 url = "github:kmonad/kmonad?dir=nix";
35 inputs.nixpkgs.follows = "nixpkgs";
36 };
Skyler Grey61635852022-10-31 00:27:04 +000037 fenix.url = "github:nix-community/fenix";
Skyler Grey5631f962023-02-19 23:31:19 +000038 nps.url = "github:OleMussmann/Nix-Package-Search";
Skyler Grey14027172023-01-15 09:49:53 +000039 lanzaboote.url = "github:nix-community/lanzaboote";
Skyler Greybcb2cb72022-08-21 07:24:35 +010040
Skyler Grey61635852022-10-31 00:27:04 +000041 fenix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey6be25172022-10-30 22:58:55 +000042 flake-utils-plus.inputs.flake-utils.follows = "flake-utils";
Skyler Greybcb2cb72022-08-21 07:24:35 +010043 home-manager.inputs.nixpkgs.follows = "nixpkgs";
44 sops-nix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey5631f962023-02-19 23:31:19 +000045 nps.inputs.nixpkgs.follows = "nixpkgs";
46 nps.inputs.flake-utils.follows = "flake-utils";
Skyler Grey1db35a02023-02-26 12:52:37 +000047 crane.inputs.nixpkgs.follows = "nixpkgs";
48 crane.inputs.flake-utils.follows = "flake-utils";
Skyler Grey14027172023-01-15 09:49:53 +000049 lanzaboote.inputs.nixpkgs.follows = "nixpkgs";
50 lanzaboote.inputs.flake-utils.follows = "flake-utils";
51 lanzaboote.inputs.crane.follows = "crane";
Skyler Grey7dfe5c62022-08-20 21:41:30 +010052 };
Skyler Grey0409e462022-08-19 23:40:48 +010053
Skyler Grey252927a2022-10-18 22:18:15 +010054 outputs = inputs:
55 let
56 inherit (inputs) self nixpkgs flake-utils;
57 in
58 flake-utils.lib.eachDefaultSystem (system:
59 let
60 pkgs = import nixpkgs {
Skyler Grey7dfe5c62022-08-20 21:41:30 +010061 inherit system;
Skyler Greybcc63992023-01-25 21:43:55 +000062 overlays = import ./overlays nixpkgs.lib (inputs // {
63 inherit inputs
64 username;
65 });
Skyler Grey7dfe5c62022-08-20 21:41:30 +010066 };
Skyler Grey252927a2022-10-18 22:18:15 +010067
68 utils = import ./utils nixpkgs.lib;
69
70 username = "minion";
71
72 isAttrType = type:
73 if builtins.elem type.name [ "submodule" ]
74 then true
75 else if type ? nestedTypes.elemType
76 then isAttrType type.nestedTypes.elemType
77 else false;
78
79 normalizeOptions = options:
80 if
81 nixpkgs.lib.traceSeqN 2
82 {
83 inherit options;
84 type = builtins.typeOf options;
85 }
86 builtins.typeOf
87 options
88 == "set"
89 then
90 nixpkgs.lib.mapAttrs
91 (
92 name: value:
93 if
94 nixpkgs.lib.traceSeqN 3
95 {
96 inherit name value;
97 hasGetSubOpts = value ? getSubOptions;
98 hasType = value ? type;
99 isAttrType = value ? type && isAttrType value.type;
100 typeName = value.type.name or "unnamed";
101 type = builtins.typeOf value;
102 }
103 (builtins.typeOf value)
104 == "set"
105 then
106 nixpkgs.lib.traceVal
107 (normalizeOptions (
108 if value ? type && isAttrType value.type
109 then nixpkgs.lib.traceVal (value.type.getSubOptions [ ])
110 else nixpkgs.lib.traceVal value
111 ))
112 else value
113 )
114 options
115 else options;
Skyler Greybcc63992023-01-25 21:43:55 +0000116
117 evalTrace = config: trace:
118 let
119 lib = nixpkgs.lib;
120 splitTrace = lib.splitString "." trace;
121 traceHead = builtins.head splitTrace;
122 traceTail = builtins.tail splitTrace;
123 resolvedTrace =
124 (
125 if traceHead == "home"
126 then [ "home-manager" "users" username ]
Skyler Grey95a223c2023-02-26 12:48:24 +0000127 else lib.throwIfNot (traceHead == "config") ''You need to trace either home.** or config.** (found "${traceHead}" in "${trace}")'' [ ])
Skyler Greybcc63992023-01-25 21:43:55 +0000128 ++ traceTail;
129 in
130 (
131 lib.pipe resolvedTrace [
132 (lib.foldl
133 ({ value
134 , error
135 ,
136 }: key:
137 if builtins.hasAttr key value
138 then {
139 value = value.${key};
140 inherit error;
141 }
142 else {
143 value = { };
Skyler Grey95a223c2023-02-26 12:48:24 +0000144 error = if error == false
145 then ''"${key}" does not exist in set "${builtins.toJSON value}"''
146 else error;
Skyler Greybcc63992023-01-25 21:43:55 +0000147 })
148 {
Skyler Grey95a223c2023-02-26 12:48:24 +0000149 value = config;
Skyler Greybcc63992023-01-25 21:43:55 +0000150 error = false;
151 })
Skyler Grey95a223c2023-02-26 12:48:24 +0000152 (data: lib.warnIf (data.error != false) ''trace/${trace} is invalid; the key ${data.error}'' data)
Skyler Greybcc63992023-01-25 21:43:55 +0000153 ({ value
154 , error
155 ,
156 }: {
157 value = builtins.toJSON value;
158 inherit error;
159 })
160 ({ value
161 , error
162 ,
163 }: {
Skyler Grey5631f962023-02-19 23:31:19 +0000164 value = "trace/${trace}: ${value}";
Skyler Greybcc63992023-01-25 21:43:55 +0000165 inherit error;
166 })
167 ({ value
168 , error
169 ,
170 }:
Skyler Grey95a223c2023-02-26 12:48:24 +0000171 lib.warnIf (!error) value null)
Skyler Greybcc63992023-01-25 21:43:55 +0000172 ]
173 );
Skyler Grey252927a2022-10-18 22:18:15 +0100174 in
175 {
Skyler Grey95a223c2023-02-26 12:48:24 +0000176 packages.nixosConfigurations =
177 let
178 nixosSystem = (nixpkgs.lib.nixosSystem
Skyler Grey5631f962023-02-19 23:31:19 +0000179 {
180 inherit system;
Skyler Grey252927a2022-10-18 22:18:15 +0100181
Skyler Grey5631f962023-02-19 23:31:19 +0000182 modules = [
183 (nixpkgs.lib.pipe ./modules [
184 utils.nixFilesIn
185 (utils.interpretNonstandardModule (args:
186 args
187 // {
188 home = args.config.home-manager.users.${username};
189 home-options =
190 nixpkgs.lib.traceVal (normalizeOptions
191 (args.options.home-manager.users.type.getSubOptions [ ]));
192 inherit system utils;
193 }))
194 ])
195 {
196 minion = import ./config.nix;
197 }
198 ];
Skyler Grey252927a2022-10-18 22:18:15 +0100199
Skyler Grey5631f962023-02-19 23:31:19 +0000200 specialArgs = inputs // { inherit inputs username; };
201 });
Skyler Grey95a223c2023-02-26 12:48:24 +0000202 in
203 {
204 default = builtins.deepSeq
205 (map (evalTrace nixosSystem.config) nixosSystem.config.internal.traces)
206 nixosSystem;
207 };
Skyler Grey252927a2022-10-18 22:18:15 +0100208 devShell = pkgs.mkShell {
209 nativeBuildInputs = with pkgs; [ nodePackages.prettier nixpkgs-fmt ];
210 buildInputs = [ ];
211 };
212 formatter = pkgs.nixpkgs-fmt;
213 });
Skyler Grey0409e462022-08-19 23:40:48 +0100214}