blob: e13519e7d2d7d597c0d4ad04886e8b58f22bd90e [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 Grey2f9904e2022-09-05 03:18:02 +01005 nixpkgs-minion.url = "github:Minion3665/nixpkgs";
Skyler Grey5631f962023-02-19 23:31:19 +00006 nixpkgs-yubioath-flutter.url = "github:lukegb/nixpkgs/yubioath-flutter";
Skyler Greybcb2cb72022-08-21 07:24:35 +01007 flake-utils.url = "github:numtide/flake-utils";
Skyler Grey6be25172022-10-30 22:58:55 +00008 flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus";
Skyler Grey2a7ca382022-09-01 23:15:31 +01009 vscode-extensions.url = "github:AmeerTaweel/nix-vscode-marketplace";
Skyler Greybcb2cb72022-08-21 07:24:35 +010010 registry = {
11 url = "github:nixos/flake-registry";
12 flake = false;
13 };
Skyler Greyf8f06532022-11-04 10:58:38 +000014 home-manager.url = "github:nix-community/home-manager";
Skyler Greybcb2cb72022-08-21 07:24:35 +010015 sops-nix.url = "github:Mic92/sops-nix";
16 impermanence.url = "github:nix-community/impermanence";
Skyler Grey2a7ca382022-09-01 23:15:31 +010017 gtimelog = {
18 url = "git+https://gitlab.collabora.com/collabora/gtimelog.git";
19 flake = false;
20 };
Skyler Grey934f1422022-09-04 11:50:04 +010021 fzf-tab = {
22 url = "github:Aloxaf/fzf-tab";
23 flake = false;
24 };
Skyler Greya589ea12022-10-31 00:03:57 +000025 omnisharp-language-server = {
26 url = "github:coc-extensions/coc-omnisharp";
27 flake = false;
28 };
29 kmonad = {
30 url = "github:kmonad/kmonad?dir=nix";
31 inputs.nixpkgs.follows = "nixpkgs";
32 };
Skyler Grey61635852022-10-31 00:27:04 +000033 fenix.url = "github:nix-community/fenix";
Skyler Grey5631f962023-02-19 23:31:19 +000034 nps.url = "github:OleMussmann/Nix-Package-Search";
Skyler Greybcb2cb72022-08-21 07:24:35 +010035
Skyler Grey61635852022-10-31 00:27:04 +000036 fenix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey6be25172022-10-30 22:58:55 +000037 flake-utils-plus.inputs.flake-utils.follows = "flake-utils";
Skyler Greybcb2cb72022-08-21 07:24:35 +010038 home-manager.inputs.nixpkgs.follows = "nixpkgs";
39 sops-nix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey5631f962023-02-19 23:31:19 +000040 nps.inputs.nixpkgs.follows = "nixpkgs";
41 nps.inputs.flake-utils.follows = "flake-utils";
Skyler Grey7dfe5c62022-08-20 21:41:30 +010042 };
Skyler Grey0409e462022-08-19 23:40:48 +010043
Skyler Grey252927a2022-10-18 22:18:15 +010044 outputs = inputs:
45 let
46 inherit (inputs) self nixpkgs flake-utils;
47 in
48 flake-utils.lib.eachDefaultSystem (system:
49 let
50 pkgs = import nixpkgs {
Skyler Grey7dfe5c62022-08-20 21:41:30 +010051 inherit system;
Skyler Greybcc63992023-01-25 21:43:55 +000052 overlays = import ./overlays nixpkgs.lib (inputs // {
53 inherit inputs
54 username;
55 });
Skyler Grey7dfe5c62022-08-20 21:41:30 +010056 };
Skyler Grey252927a2022-10-18 22:18:15 +010057
58 utils = import ./utils nixpkgs.lib;
59
60 username = "minion";
61
62 isAttrType = type:
63 if builtins.elem type.name [ "submodule" ]
64 then true
65 else if type ? nestedTypes.elemType
66 then isAttrType type.nestedTypes.elemType
67 else false;
68
69 normalizeOptions = options:
70 if
71 nixpkgs.lib.traceSeqN 2
72 {
73 inherit options;
74 type = builtins.typeOf options;
75 }
76 builtins.typeOf
77 options
78 == "set"
79 then
80 nixpkgs.lib.mapAttrs
81 (
82 name: value:
83 if
84 nixpkgs.lib.traceSeqN 3
85 {
86 inherit name value;
87 hasGetSubOpts = value ? getSubOptions;
88 hasType = value ? type;
89 isAttrType = value ? type && isAttrType value.type;
90 typeName = value.type.name or "unnamed";
91 type = builtins.typeOf value;
92 }
93 (builtins.typeOf value)
94 == "set"
95 then
96 nixpkgs.lib.traceVal
97 (normalizeOptions (
98 if value ? type && isAttrType value.type
99 then nixpkgs.lib.traceVal (value.type.getSubOptions [ ])
100 else nixpkgs.lib.traceVal value
101 ))
102 else value
103 )
104 options
105 else options;
Skyler Greybcc63992023-01-25 21:43:55 +0000106
107 evalTrace = config: trace:
108 let
109 lib = nixpkgs.lib;
110 splitTrace = lib.splitString "." trace;
111 traceHead = builtins.head splitTrace;
112 traceTail = builtins.tail splitTrace;
113 resolvedTrace =
114 (
115 if traceHead == "home"
116 then [ "home-manager" "users" username ]
Skyler Grey95a223c2023-02-26 12:48:24 +0000117 else lib.throwIfNot (traceHead == "config") ''You need to trace either home.** or config.** (found "${traceHead}" in "${trace}")'' [ ])
Skyler Greybcc63992023-01-25 21:43:55 +0000118 ++ traceTail;
119 in
120 (
121 lib.pipe resolvedTrace [
122 (lib.foldl
123 ({ value
124 , error
125 ,
126 }: key:
127 if builtins.hasAttr key value
128 then {
129 value = value.${key};
130 inherit error;
131 }
132 else {
133 value = { };
Skyler Grey95a223c2023-02-26 12:48:24 +0000134 error = if error == false
135 then ''"${key}" does not exist in set "${builtins.toJSON value}"''
136 else error;
Skyler Greybcc63992023-01-25 21:43:55 +0000137 })
138 {
Skyler Grey95a223c2023-02-26 12:48:24 +0000139 value = config;
Skyler Greybcc63992023-01-25 21:43:55 +0000140 error = false;
141 })
Skyler Grey95a223c2023-02-26 12:48:24 +0000142 (data: lib.warnIf (data.error != false) ''trace/${trace} is invalid; the key ${data.error}'' data)
Skyler Greybcc63992023-01-25 21:43:55 +0000143 ({ value
144 , error
145 ,
146 }: {
147 value = builtins.toJSON value;
148 inherit error;
149 })
150 ({ value
151 , error
152 ,
153 }: {
Skyler Grey5631f962023-02-19 23:31:19 +0000154 value = "trace/${trace}: ${value}";
Skyler Greybcc63992023-01-25 21:43:55 +0000155 inherit error;
156 })
157 ({ value
158 , error
159 ,
160 }:
Skyler Grey95a223c2023-02-26 12:48:24 +0000161 lib.warnIf (!error) value null)
Skyler Greybcc63992023-01-25 21:43:55 +0000162 ]
163 );
Skyler Grey252927a2022-10-18 22:18:15 +0100164 in
165 {
Skyler Grey95a223c2023-02-26 12:48:24 +0000166 packages.nixosConfigurations =
167 let
168 nixosSystem = (nixpkgs.lib.nixosSystem
Skyler Grey5631f962023-02-19 23:31:19 +0000169 {
170 inherit system;
Skyler Grey252927a2022-10-18 22:18:15 +0100171
Skyler Grey5631f962023-02-19 23:31:19 +0000172 modules = [
173 (nixpkgs.lib.pipe ./modules [
174 utils.nixFilesIn
175 (utils.interpretNonstandardModule (args:
176 args
177 // {
178 home = args.config.home-manager.users.${username};
179 home-options =
180 nixpkgs.lib.traceVal (normalizeOptions
181 (args.options.home-manager.users.type.getSubOptions [ ]));
182 inherit system utils;
183 }))
184 ])
185 {
186 minion = import ./config.nix;
187 }
188 ];
Skyler Grey252927a2022-10-18 22:18:15 +0100189
Skyler Grey5631f962023-02-19 23:31:19 +0000190 specialArgs = inputs // { inherit inputs username; };
191 });
Skyler Grey95a223c2023-02-26 12:48:24 +0000192 in
193 {
194 default = builtins.deepSeq
195 (map (evalTrace nixosSystem.config) nixosSystem.config.internal.traces)
196 nixosSystem;
197 };
Skyler Grey252927a2022-10-18 22:18:15 +0100198 devShell = pkgs.mkShell {
199 nativeBuildInputs = with pkgs; [ nodePackages.prettier nixpkgs-fmt ];
200 buildInputs = [ ];
201 };
202 formatter = pkgs.nixpkgs-fmt;
203 });
Skyler Grey0409e462022-08-19 23:40:48 +0100204}