-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
477 lines (428 loc) · 12.9 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
{
description = "Aftix's NixOS configuration";
inputs = {
lix = {
url = "https://git.lix.systems/lix-project/lix/archive/main.tar.gz";
inputs.nixpkgs.follows = "nixpkgs";
};
lix-module = {
url = "https://git.lix.systems/lix-project/nixos-module/archive/main.tar.gz";
inputs = {
lix.follows = "lix";
nixpkgs.follows = "nixpkgs";
};
};
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
stablepkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
nur.url = "github:nix-community/NUR";
home-manager = {
url = "github:nix-community/home-manager/master";
inputs.nixpkgs.follows = "nixpkgs";
};
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
deploy-rs = {
url = "github:serokell/deploy-rs";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
srvos = {
url = "github:numtide/srvos";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-index-database = {
url = "github:nix-community/nix-index-database";
inputs.nixpkgs.follows = "nixpkgs";
};
preservation.url = "github:willibutz/preservation";
stylix = {
url = "github:danth/stylix";
inputs.nixpkgs.follows = "nixpkgs";
};
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
lanzaboote = {
url = "github:nix-community/lanzaboote/v0.4.1";
inputs.nixpkgs.follows = "nixpkgs";
};
nixos-cli.url = "github:water-sucks/nixos";
carapace = {
url = "github:carapace-sh/carapace-bin";
flake = false;
};
attic.url = "github:zhaofengli/attic";
helix.url = "github:helix-editor/helix";
hostsBlacklist = {
url = "github:Ultimate-Hosts-Blacklist/Ultimate.Hosts.Blacklist";
flake = false;
};
nginxBlacklist = {
url = "github:mitchellkrogza/nginx-ultimate-bad-bot-blocker";
flake = false;
};
hyprland = {
url = "github:hyprwm/hyprland";
flake = false; # Just want the wallpaper image
};
};
outputs = {
self,
nixpkgs,
stablepkgs,
nur,
home-manager,
deploy-rs,
flake-utils,
...
} @ inputs: let
system = "x86_64-linux";
substituters = [
"https://nix-community.cachix.org"
"https://helix.cachix.org"
"https://cache.nixos.org"
"https://attic.aftix.xyz/cfg-actions"
];
trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
"helix.cachix.org-1:ejp9KQpR1FBI2onstMQ34yogDm4OgU2ru6lIwPvuCVs="
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"cfg-actions:R9aJEQdcJT8NrUh1yox2FgZfmzRrKi6MAobbfuRvv3g="
];
overlay = import ./overlay.nix inputs;
getModules = atPath: let
getFilename = path: nixpkgs.lib.lists.last (nixpkgs.lib.strings.split "/" (builtins.toString path));
mapAppendPath = path: f: p: v: f (nixpkgs.lib.path.append path p) v;
recursiveGetModules = path: val:
if val == "regular" && nixpkgs.lib.strings.hasSuffix ".nix" path
then
(
let
fName = getFilename path;
name = nixpkgs.lib.strings.removeSuffix ".nix" fName;
in {${name} = import path;}
)
else if val != "directory" || nixpkgs.lib.strings.hasPrefix "_" (getFilename path)
then {}
else
(let
subdir = builtins.readDir path;
in
if subdir ? "default.nix"
then {${getFilename path} = import path;}
else nixpkgs.lib.attrsets.concatMapAttrs (mapAppendPath path recursiveGetModules) subdir);
in
nixpkgs.lib.attrsets.concatMapAttrs (mapAppendPath atPath recursiveGetModules) (builtins.readDir atPath);
pkgsCfg = {
nixpkgs = {
overlays = [
nur.overlay
inputs.helix.overlays.default
inputs.attic.overlays.default
overlay
];
config = {
allowUnfreePredicate = pkg:
builtins.elem (nixpkgs.lib.getName pkg) [
"discord"
"pay-by-privacy"
"aspell-dict-en-science"
];
permittedInsecurePackages = [
"jitsi-meet-1.0.8043"
"cinny-4.2.3"
"cinny-unwrapped-4.2.3"
];
};
};
};
spkgs = stablepkgs.legacyPackages.${system};
depInject = {lib, ...}: {
options.dep-inject = lib.mkOption {
type = with lib.types; attrsOf unspecified;
default = {};
};
config.dep-inject = {
inherit spkgs inputs commonHmModules;
};
};
depInjectHm = {lib, ...}: {
options.dep-inject = lib.mkOption {
type = with lib.types; attrsOf unspecified;
default = {};
};
config.dep-inject = {
inherit spkgs inputs;
};
};
# Options that are for home-manager, but should be set on a per-host basis
nixosHomeOptions = pkgs: lib: {
my = {
development.nixdConfig = lib.mkOption {
default = {};
description = "Configuration for the nixd LSP";
type = with lib.types; attrsOf anything;
};
swayosd = {
enable = lib.mkEnableOption "swayosd";
package = lib.mkPackageOption pkgs "swayosd" {
default = ["swayosd"];
};
};
};
};
# Nixos module for nixosHomeOptions
# Allows nixos configurations to set options to propagate into each home-manager configuration
nixosHomeModule = {
lib,
pkgs,
...
}: {options = nixosHomeOptions pkgs lib;};
# Inject config from nixosHomeOptions into home-manager
# Leaves a my.nixosCfg option set to the total system configuration, and
# recursively picks out the options defined in nixosHomeOptions and injects them into the home-manager
# configuration so those options in particular won't need a "my.nixosCfg" before the config path.
# Downstream users should get this from the `extra` flake output and use it to generate a hm module
# with their sysCfg injected. The nixos side is already in the default flake nixosModule, so nothing
# extra is needed beyond that.
hmInjectNixosHomeOptions = sysCfg: {
lib,
pkgs,
...
}: let
homeOpts = nixosHomeOptions pkgs lib;
in {
imports = [{options = homeOpts;}];
options.my.nixosCfg = lib.mkOption {
description = "The NixOS configuration";
readOnly = true;
type = lib.types.raw;
};
config = let
inherit (lib.attrsets) mapAttrsRecursiveCond hasAttrByPath getAttrFromPath;
in
lib.mkMerge [
(
mapAttrsRecursiveCond
# Do not recurse into attrsets that are option definitions
(attrs: !(attrs ? "_type" && attrs._type == "option"))
(optPath: _:
if hasAttrByPath optPath sysCfg
then getAttrFromPath optPath sysCfg
else null)
homeOpts
)
{
my.nixosCfg = sysCfg;
}
];
};
commonModules = [
pkgsCfg
(_: {
nixpkgs.overlays = [
inputs.lix-module.overlays.default
(_: prev: {
lix = prev.lix.override {aws-sdk-cpp = null;};
})
];
})
home-manager.nixosModules.home-manager
inputs.sops-nix.nixosModules.sops
inputs.nix-index-database.nixosModules.nix-index
inputs.srvos.nixosModules.mixins-trusted-nix-caches
inputs.nixos-cli.nixosModules.nixos-cli
inputs.preservation.nixosModules.default
nixosHomeModule
depInject
{
programs = {
nix-index-database.comma.enable = true;
command-not-found.enable = false;
};
}
({
pkgs,
lib,
...
}: {
nix = {
package = lib.mkForce pkgs.nix;
settings = {inherit substituters trusted-public-keys;};
};
})
];
extraSpecialArgs = {
inherit (inputs.sops-nix.homeManagerModules) sops;
inherit (inputs.stylix.homeManagerModules) stylix;
};
commonHmModules = [
pkgsCfg
inputs.nix-index-database.hmModules.nix-index
{
imports = [depInjectHm];
programs = {
nix-index-database.comma.enable = true;
command-not-found.enable = false;
};
}
];
genNixosSystem = {
modules,
users,
extraAttrs ? {},
}:
nixpkgs.lib.nixosSystem ({
modules =
[
self.nixosModules.default
]
++ modules
++ [
({config, ...}: let
nixosHomeOptions = hmInjectNixosHomeOptions config;
in {
home-manager = {
useUserPackages = true;
inherit extraSpecialArgs users;
sharedModules = [
nixosHomeOptions
self.homemanagerModules.default
];
};
})
];
}
// extraAttrs);
in
{
overlays.default = overlay;
nixosConfigurations = {
hamilton = genNixosSystem {
modules = [
inputs.disko.nixosModules.disko
inputs.lanzaboote.nixosModules.lanzaboote
./host/hamilton.nix
];
users = {
aftix = import ./home/aftix.nix;
root = import ./home/root.nix;
};
};
fermi = genNixosSystem {
modules = [
inputs.srvos.nixosModules.server
inputs.srvos.nixosModules.mixins-nginx
./host/fermi.nix
];
users = {
aftix = import ./home/aftix-minimal.nix;
root = import ./home/root.nix;
};
};
"iso-minimal" = genNixosSystem {
modules = [
{nixpkgs.hostPlatform = system;}
"${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"
"${nixpkgs}/nixos/modules/installer/cd-dvd/channel.nix"
inputs.disko.nixosModules.disko
./host/iso-minimal.nix
];
users = {
root = ./home/root.nix;
nixos = ./home/nixos.nix;
};
};
"iso-graphical" = genNixosSystem {
modules = [
{nixpkgs.hostPlatform = system;}
"${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"
"${nixpkgs}/nixos/modules/installer/cd-dvd/channel.nix"
inputs.disko.nixosModules.disko
./host/iso-graphical.nix
];
users = {
root = ./home/root.nix;
nixos = ./home/nixos-graphical.nix;
};
};
};
deploy.nodes.fermi = {
hostname = "170.130.165.174";
profiles.system = {
user = "root";
path = deploy-rs.lib.x86_64-linux.activate.nixos self.nixosConfigurations.fermi;
};
};
nixosModules =
{
default = {
imports = commonModules ++ [./host/common];
};
nix-substituters = {
nix.settings = {inherit substituters trusted-public-keys;};
};
}
// getModules ./host/opt;
homemanagerModules =
{
default = {
imports = commonHmModules ++ [./home/common];
};
}
// getModules ./home/opt;
extra = {
# NOTE: you'll need to use these for some optional modules
inherit extraSpecialArgs;
inherit substituters trusted-public-keys nixosHomeOptions hmInjectNixosHomeOptions;
};
}
// flake-utils.lib.eachDefaultSystem (sys: let
pkgs = import nixpkgs {
system = sys;
inherit (pkgsCfg.nixpkgs) config;
overlays = [
nur.overlay
inputs.helix.overlays.default
self.overlays.default
];
};
in {
formatter =
pkgs.alejandra or pkgs.nix-fmt;
checks = nixpkgs.lib.attrsets.optionalAttrs (deploy-rs.lib ? "${sys}") (deploy-rs.lib.${sys}.deployChecks self.deploy);
legacyPackages = {
inherit (pkgs) freshrssExts;
};
packages = {
inherit
(pkgs)
barcodebuddy
carapace
cinny-desktop
coffeepaste
attic
attic-client
attic-server
heisenbridge
helix
nginx_blocker
youtube-operational-api
nu_plugin_audio_hook
nu_plugin_compress
nu_plugin_desktop_notifications
nu_plugin_dns
nu_plugin_endecode
nu_plugin_explore
nu_plugin_port_scan
nu_plugin_port_list
nu_plugin_semver
nu_plugin_strutils
;
lix = inputs.lix-module.packages.${sys}.default.override {aws-sdk-cpp = null;};
};
});
}