blob: f401273a3a2b64abcae24840a686d3e1527db503 [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 Greybcb2cb72022-08-21 07:24:35 +010039
Skyler Grey61635852022-10-31 00:27:04 +000040 fenix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey6be25172022-10-30 22:58:55 +000041 flake-utils-plus.inputs.flake-utils.follows = "flake-utils";
Skyler Greybcb2cb72022-08-21 07:24:35 +010042 home-manager.inputs.nixpkgs.follows = "nixpkgs";
43 sops-nix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey5631f962023-02-19 23:31:19 +000044 nps.inputs.nixpkgs.follows = "nixpkgs";
45 nps.inputs.flake-utils.follows = "flake-utils";
Skyler Grey1db35a02023-02-26 12:52:37 +000046 crane.inputs.nixpkgs.follows = "nixpkgs";
47 crane.inputs.flake-utils.follows = "flake-utils";
Skyler Grey7dfe5c62022-08-20 21:41:30 +010048 };
Skyler Grey0409e462022-08-19 23:40:48 +010049
Skyler Grey252927a2022-10-18 22:18:15 +010050 outputs = inputs:
51 let
52 inherit (inputs) self nixpkgs flake-utils;
53 in
54 flake-utils.lib.eachDefaultSystem (system:
55 let
56 pkgs = import nixpkgs {
Skyler Grey7dfe5c62022-08-20 21:41:30 +010057 inherit system;
Skyler Greybcc63992023-01-25 21:43:55 +000058 overlays = import ./overlays nixpkgs.lib (inputs // {
59 inherit inputs
60 username;
61 });
Skyler Grey7dfe5c62022-08-20 21:41:30 +010062 };
Skyler Grey252927a2022-10-18 22:18:15 +010063
64 utils = import ./utils nixpkgs.lib;
65
66 username = "minion";
67
68 isAttrType = type:
69 if builtins.elem type.name [ "submodule" ]
70 then true
71 else if type ? nestedTypes.elemType
72 then isAttrType type.nestedTypes.elemType
73 else false;
74
75 normalizeOptions = options:
76 if
77 nixpkgs.lib.traceSeqN 2
78 {
79 inherit options;
80 type = builtins.typeOf options;
81 }
82 builtins.typeOf
83 options
84 == "set"
85 then
86 nixpkgs.lib.mapAttrs
87 (
88 name: value:
89 if
90 nixpkgs.lib.traceSeqN 3
91 {
92 inherit name value;
93 hasGetSubOpts = value ? getSubOptions;
94 hasType = value ? type;
95 isAttrType = value ? type && isAttrType value.type;
96 typeName = value.type.name or "unnamed";
97 type = builtins.typeOf value;
98 }
99 (builtins.typeOf value)
100 == "set"
101 then
102 nixpkgs.lib.traceVal
103 (normalizeOptions (
104 if value ? type && isAttrType value.type
105 then nixpkgs.lib.traceVal (value.type.getSubOptions [ ])
106 else nixpkgs.lib.traceVal value
107 ))
108 else value
109 )
110 options
111 else options;
Skyler Greybcc63992023-01-25 21:43:55 +0000112
113 evalTrace = config: trace:
114 let
115 lib = nixpkgs.lib;
116 splitTrace = lib.splitString "." trace;
117 traceHead = builtins.head splitTrace;
118 traceTail = builtins.tail splitTrace;
119 resolvedTrace =
120 (
121 if traceHead == "home"
122 then [ "home-manager" "users" username ]
Skyler Grey95a223c2023-02-26 12:48:24 +0000123 else lib.throwIfNot (traceHead == "config") ''You need to trace either home.** or config.** (found "${traceHead}" in "${trace}")'' [ ])
Skyler Greybcc63992023-01-25 21:43:55 +0000124 ++ traceTail;
125 in
126 (
127 lib.pipe resolvedTrace [
128 (lib.foldl
129 ({ value
130 , error
131 ,
132 }: key:
133 if builtins.hasAttr key value
134 then {
135 value = value.${key};
136 inherit error;
137 }
138 else {
139 value = { };
Skyler Grey95a223c2023-02-26 12:48:24 +0000140 error = if error == false
141 then ''"${key}" does not exist in set "${builtins.toJSON value}"''
142 else error;
Skyler Greybcc63992023-01-25 21:43:55 +0000143 })
144 {
Skyler Grey95a223c2023-02-26 12:48:24 +0000145 value = config;
Skyler Greybcc63992023-01-25 21:43:55 +0000146 error = false;
147 })
Skyler Grey95a223c2023-02-26 12:48:24 +0000148 (data: lib.warnIf (data.error != false) ''trace/${trace} is invalid; the key ${data.error}'' data)
Skyler Greybcc63992023-01-25 21:43:55 +0000149 ({ value
150 , error
151 ,
152 }: {
153 value = builtins.toJSON value;
154 inherit error;
155 })
156 ({ value
157 , error
158 ,
159 }: {
Skyler Grey5631f962023-02-19 23:31:19 +0000160 value = "trace/${trace}: ${value}";
Skyler Greybcc63992023-01-25 21:43:55 +0000161 inherit error;
162 })
163 ({ value
164 , error
165 ,
166 }:
Skyler Grey95a223c2023-02-26 12:48:24 +0000167 lib.warnIf (!error) value null)
Skyler Greybcc63992023-01-25 21:43:55 +0000168 ]
169 );
Skyler Grey252927a2022-10-18 22:18:15 +0100170 in
171 {
Skyler Grey95a223c2023-02-26 12:48:24 +0000172 packages.nixosConfigurations =
173 let
174 nixosSystem = (nixpkgs.lib.nixosSystem
Skyler Grey5631f962023-02-19 23:31:19 +0000175 {
176 inherit system;
Skyler Grey252927a2022-10-18 22:18:15 +0100177
Skyler Grey5631f962023-02-19 23:31:19 +0000178 modules = [
179 (nixpkgs.lib.pipe ./modules [
180 utils.nixFilesIn
181 (utils.interpretNonstandardModule (args:
182 args
183 // {
184 home = args.config.home-manager.users.${username};
185 home-options =
186 nixpkgs.lib.traceVal (normalizeOptions
187 (args.options.home-manager.users.type.getSubOptions [ ]));
188 inherit system utils;
189 }))
190 ])
191 {
192 minion = import ./config.nix;
193 }
194 ];
Skyler Grey252927a2022-10-18 22:18:15 +0100195
Skyler Grey5631f962023-02-19 23:31:19 +0000196 specialArgs = inputs // { inherit inputs username; };
197 });
Skyler Grey95a223c2023-02-26 12:48:24 +0000198 in
199 {
200 default = builtins.deepSeq
201 (map (evalTrace nixosSystem.config) nixosSystem.config.internal.traces)
202 nixosSystem;
203 };
Skyler Grey252927a2022-10-18 22:18:15 +0100204 devShell = pkgs.mkShell {
205 nativeBuildInputs = with pkgs; [ nodePackages.prettier nixpkgs-fmt ];
206 buildInputs = [ ];
207 };
208 formatter = pkgs.nixpkgs-fmt;
209 });
Skyler Grey0409e462022-08-19 23:40:48 +0100210}