blob: 5ea37b73e8615d7e07882df2b929fdd38cd8a6b1 [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 ]
117 else lib.errorIfNot (traceHead == "config") [ ]
118 )
119 ++ traceTail;
120 in
121 (
122 lib.pipe resolvedTrace [
123 (lib.foldl
124 ({ value
125 , error
126 ,
127 }: key:
128 if builtins.hasAttr key value
129 then {
130 value = value.${key};
131 inherit error;
132 }
133 else {
134 value = { };
135 error = true;
136 })
137 {
138 value = { };
139 error = false;
140 })
Skyler Grey5631f962023-02-19 23:31:19 +0000141 (data: lib.warnIf data.error "trace/${trace} is invalid; the key does not exist" data)
Skyler Greybcc63992023-01-25 21:43:55 +0000142 ({ value
143 , error
144 ,
145 }: {
146 value = builtins.toJSON value;
147 inherit error;
148 })
149 ({ value
150 , error
151 ,
152 }: {
Skyler Grey5631f962023-02-19 23:31:19 +0000153 value = "trace/${trace}: ${value}";
Skyler Greybcc63992023-01-25 21:43:55 +0000154 inherit error;
155 })
156 ({ value
157 , error
158 ,
159 }:
160 lib.traceIf (!error) value null)
161 ]
162 );
Skyler Grey252927a2022-10-18 22:18:15 +0100163 in
164 {
165 packages.nixosConfigurations = {
Skyler Greybcc63992023-01-25 21:43:55 +0000166 default = nixpkgs.lib.traceValFn
Skyler Grey5631f962023-02-19 23:31:19 +0000167 (nixosSystem: map (evalTrace nixosSystem.config)
168 nixosSystem.config.internal.traces)
169 (nixpkgs.lib.nixosSystem
170 {
171 inherit system;
Skyler Grey252927a2022-10-18 22:18:15 +0100172
Skyler Grey5631f962023-02-19 23:31:19 +0000173 modules = [
174 (nixpkgs.lib.pipe ./modules [
175 utils.nixFilesIn
176 (utils.interpretNonstandardModule (args:
177 args
178 // {
179 home = args.config.home-manager.users.${username};
180 home-options =
181 nixpkgs.lib.traceVal (normalizeOptions
182 (args.options.home-manager.users.type.getSubOptions [ ]));
183 inherit system utils;
184 }))
185 ])
186 {
187 minion = import ./config.nix;
188 }
189 ];
Skyler Grey252927a2022-10-18 22:18:15 +0100190
Skyler Grey5631f962023-02-19 23:31:19 +0000191 specialArgs = inputs // { inherit inputs username; };
192 });
Skyler Grey252927a2022-10-18 22:18:15 +0100193 };
194 devShell = pkgs.mkShell {
195 nativeBuildInputs = with pkgs; [ nodePackages.prettier nixpkgs-fmt ];
196 buildInputs = [ ];
197 };
198 formatter = pkgs.nixpkgs-fmt;
199 });
Skyler Grey0409e462022-08-19 23:40:48 +0100200}