forked from colemickens/nixcfg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
486 lines (455 loc) · 16.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
478
479
480
481
482
483
484
485
486
{
# TODO: revisit/checkout: mic92/envfs, nickel, wfvm
description = "colemickens - nixos configs, custom packges, misc";
inputs = {
flake-utils = {
url = "github:numtide/flake-utils";
};
lib-aggregate = {
url = "github:nix-community/lib-aggregate";
}; # TODO: boo name! "libaggregate"?
nixpkgs-stable = {
url = "github:nixos/nixpkgs/nixos-23.05";
}; # any stable to use
cmpkgs = {
url = "github:colemickens/nixpkgs/cmpkgs";
};
mobile-nixos-openstick = {
url = "github:colemickens/mobile-nixos/openstick";
inputs."nixpkgs".follows = "cmpkgs";
};
tow-boot-alirock-h96maxv58 = {
url = "github:colemickens/tow-boot/alirock-h96maxv58";
inputs."nixpkgs".follows = "cmpkgs";
};
tow-boot-radxa-zero = {
url = "github:colemickens/tow-boot/radxa-zero";
inputs."nixpkgs".follows = "cmpkgs";
};
# core system/inputs
firefox-nightly = {
url = "github:nix-community/flake-firefox-nightly";
inputs."nixpkgs".follows = "cmpkgs";
};
home-manager = {
url = "github:colemickens/home-manager/cmhm";
inputs."nixpkgs".follows = "cmpkgs";
};
nixos-hardware = {
url = "github:NixOS/nixos-hardware";
};
nixpkgs-wayland = {
url = "github:nix-community/nixpkgs-wayland/master";
inputs."nixpkgs".follows = "cmpkgs";
};
sops-nix = {
url = "github:Mic92/sops-nix/master";
inputs."nixpkgs".follows = "cmpkgs";
};
lanzaboote = {
url = "github:nix-community/lanzaboote";
};
# devtools:
crate2nix = {
url = "github:kolloch/crate2nix";
flake = false;
};
terranix = {
url = "github:terranix/terranix";
inputs."nixpkgs".follows = "cmpkgs";
}; # packet/terraform deployments
fenix = {
url = "github:nix-community/fenix";
inputs."nixpkgs".follows = "cmpkgs";
}; # used for nightly rust devtools
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs."nixpkgs".follows = "cmpkgs";
};
# also, there's crane, crates2nix, cargo2nix, ??
helix = {
url = "github:helix-editor/helix";
inputs."nixpkgs".follows = "cmpkgs";
};
jj = {
url = "github:martinvonz/jj";
inputs."flake-utils".follows = "flake-utils";
inputs."nixpkgs".follows = "cmpkgs";
};
nix-eval-jobs = {
url = "github:nix-community/nix-eval-jobs";
# inputs."nixpkgs".follows = "cmpkgs";
};
nix-update = {
url = "github:Mic92/nix-update";
inputs."nixpkgs".follows = "cmpkgs";
};
# nix-fast-build = { url = "github:Mic92/nix-fast-build"; };
nix-fast-build = {
url = "github:colemickens/nix-fast-build/e7c7050412040a2fe49a0011ed5e06d4b25ab863";
inputs."nixpkgs".follows = "cmpkgs";
};
fast-flake-update = {
url = "github:Mic92/fast-flake-update";
inputs."nixpkgs".follows = "cmpkgs";
};
# zellij
zellij = {
url = "github:a-kenji/zellij-nix";
inputs."flake-utils".follows = "flake-utils";
inputs."nixpkgs".follows = "cmpkgs";
};
zjstatus = {
url = "github:dj95/zjstatus";
inputs."nixpkgs".follows = "cmpkgs";
};
# experimental/unused:
nix-rice = {
url = "github:colemickens/nix-rice";
inputs."nixpkgs".follows = "cmpkgs";
};
# ai, nvidia, testing on slynux
nixified-ai = {
url = "github:nixified-ai/flake";
};
};
# TODO: re-investigate nixConfig, maybe it will be less soul-crushing one day
## OUTPUTS ##################################################################
outputs =
inputs:
let
defaultSystems = [
"x86_64-linux"
# "aarch64-linux"
# "riscv64-linux"
];
lib = inputs.lib-aggregate.lib;
importPkgs =
npkgs: extraCfg:
(lib.genAttrs defaultSystems (
system:
import npkgs {
inherit system;
overlays = [ overlays.default ];
config =
let
cfg = ({ allowAliases = false; } // extraCfg);
in
cfg;
}
));
pkgs = importPkgs inputs.cmpkgs { };
pkgsStable = importPkgs inputs.nixpkgs-stable { };
pkgsUnfree = importPkgs inputs.cmpkgs { allowUnfree = true; };
mkSystem =
n: v:
(v.pkgs.lib.nixosSystem {
modules =
[ (v.path or (./hosts/${n}/configuration.nix)) ]
++ (
if (!builtins.hasAttr "buildSys" v) then
[ ]
else
[ { config.nixpkgs.buildPlatform.system = v.buildSys; } ]
);
specialArgs = {
inherit inputs;
};
});
## NIXOS CONFIGS + TOPLEVELS ############################################
nixosConfigsEx = {
"x86_64-linux" = rec {
# misc
installer-standard = {
pkgs = inputs.cmpkgs;
path = ./images/installer/configuration-standard.nix;
};
installer-cosmic = {
pkgs = inputs.cmpkgs;
path = ./images/installer/configuration-cosmic.nix;
};
installer-nvidia-ai = {
pkgs = inputs.cmpkgs;
path = ./images/installer/configuration-nvidia-ai.nix;
};
installer-standard-aarch64 = {
pkgs = inputs.cmpkgs;
path = ./images/installer/configuration-standard-aarch64.nix;
buildSys = "x86_64-linux";
};
# actual machines:
raisin = {
pkgs = inputs.cmpkgs;
};
slynux = {
pkgs = inputs.cmpkgs;
};
xeep = {
pkgs = inputs.cmpkgs;
};
zeph = {
pkgs = inputs.cmpkgs;
};
# TODO: decide what the future of this is, I like having a cross-compile targe
# to tinker with, but the device is finnicky when I break it :|
openstick = {
pkgs = inputs.cmpkgs;
path = ./hosts/openstick/cross.nix;
buildSys = "x86_64-linux";
};
openstick2 = {
pkgs = inputs.cmpkgs;
path = ./hosts/openstick2/cross.nix;
buildSys = "x86_64-linux";
};
h96maxv58 = {
pkgs = inputs.cmpkgs;
path = ./hosts/h96maxv58/cross.nix;
buildSys = "x86_64-linux";
};
radxazero1 = {
pkgs = inputs.cmpkgs;
path = ./hosts/radxazero1/cross.nix;
buildSys = "x86_64-linux";
};
rock5b = {
pkgs = inputs.cmpkgs;
path = ./hosts/rock5b/cross.nix;
buildSys = "x86_64-linux";
};
};
};
nixosConfigs = (lib.foldl' (op: nul: nul // op) { } (lib.attrValues nixosConfigsEx));
nixosConfigurations = (lib.mapAttrs (n: v: (mkSystem n v)) nixosConfigs);
toplevels = (lib.mapAttrs (_: v: v.config.system.build.toplevel) nixosConfigurations);
## SPECIAL OUTPUTS ######################################################
extra = {
# must be manually included in ciAttrs
x86_64-linux = {
installer-standard = nixosConfigurations.installer-standard.config.system.build.isoImage;
installer-cosmic = nixosConfigurations.installer-cosmic.config.system.build.isoImage;
installer-nvidia-ai = nixosConfigurations.installer-nvidia-ai.config.system.build.isoImage;
installer-standard-aarch64 =
nixosConfigurations.installer-standard-aarch64.config.system.build.isoImage;
openstick-abootimg = nixosConfigurations.openstick.config.mobile.outputs.android.android-abootimg;
openstick-bootimg = nixosConfigurations.openstick.config.mobile.outputs.android.android-bootimg;
openstick-rootfs = nixosConfigurations.openstick.config.mobile.outputs.generatedFilesystems.rootfs;
h96maxv58-uboot =
inputs.tow-boot-alirock-h96maxv58.outputs.packages.aarch64-linux.radxa-rock5b.outputs.firmware;
h96maxv58-sdimage = nixosConfigurations.h96maxv58.config.system.build.sdImage;
# rock5b -> UEFI build
radxazero-uboot =
inputs.tow-boot-radxa-zero.outputs.packages.aarch64-linux.radxa-zero.outputs.firmware;
};
riscv64-linux = { };
};
## NIXOS_MODULES # TODO: we don't use these? #############################
nixosModules = {
loginctl-linger = import ./modules/loginctl-linger.nix;
ttys = import ./modules/ttys.nix;
other-arch-vm = import ./modules/other-arch-vm.nix;
};
## OVERLAY ###############################################################
overlays = {
default = (
final: prev:
# TODO: must be a better way?
let
__colemickens_nixcfg_pkgs = rec {
alacritty = prev.callPackage ./pkgs/alacritty {
inherit (prev.darwin.apple_sdk.frameworks)
AppKit
CoreGraphics
CoreServices
CoreText
Foundation
OpenGL
;
};
nushell = prev.callPackage ./pkgs/nushell {
doCheck = false; # TODO consider removing
inherit (prev.darwin.apple_sdk.frameworks) AppKit Security;
inherit (prev.darwin.apple_sdk_11_0) Libsystem;
};
git-repo-manager = prev.callPackage ./pkgs/git-repo-manager { fenix = inputs.fenix; };
rio = prev.callPackage ./pkgs/rio { withX11 = false; };
pyamlboot = prev.callPackage ./pkgs/pyamlboot { };
wezterm = prev.darwin.apple_sdk_11_0.callPackage ./pkgs/wezterm {
doCheck = false; # TODO consider removing
inherit (prev.darwin.apple_sdk_11_0.frameworks)
Cocoa
CoreGraphics
Foundation
UserNotifications
;
};
};
in
__colemickens_nixcfg_pkgs // { inherit __colemickens_nixcfg_pkgs; }
);
};
in
lib.recursiveUpdate
({
inherit
nixosConfigs
nixosConfigsEx
nixosConfigurations
toplevels
;
inherit nixosModules overlays;
inherit extra;
inherit pkgs pkgsUnfree;
## HM ENVS #####################################################
})
(
## SYSTEM-SPECIFIC OUTPUTS ############################################
lib.flake-utils.eachSystem defaultSystems (
system:
let
mkShell = (
name:
import ./shells/${name}.nix {
inherit inputs;
pkgs = pkgs.${system};
}
);
mkAppScript = (
name: script: {
type = "app";
program = (pkgsStable.${system}.writeScript "${name}.sh" script).outPath;
}
);
in
rec {
## FORMATTER ######################################################
formatter = pkgs.${system}.nixfmt-rfc-style;
# formatter = pkgs.${system}.nixpkgs-fmt;
# formatter = pkgs.${system}.nixfmt;
# formatter = pkgs.${system}.alejandra;
## DEVSHELLS # some of 'em kinda compose ##########################
devShells =
(lib.flip lib.genAttrs mkShell [
"ci"
"dev"
"uutils"
])
// {
default = devShells.ci;
};
## TODO: coercion is still so silly, I should be able to put
# this at `outputs.homeConfigurations.x86_64-linux.env-ci`
## HM ENVS ########################################################
homeConfigurations = (
lib.genAttrs [ "env-ci" ] (
h:
inputs.home-manager.lib.homeManagerConfiguration {
pkgs = pkgs.${system};
modules = [ ./hm/${h}.nix ];
extraSpecialArgs = {
inherit inputs;
};
}
)
);
tophomes = (lib.mapAttrs (_: v: v.activation-script) homeConfigurations);
## APPS ###########################################################
apps = lib.recursiveUpdate { } (
let
pkgs_ = pkgs.${system};
tfout = import ./cloud {
inherit (inputs) terranix;
pkgs = pkgs_;
};
installer = nixosConfigurations.installer-cosmic.config.system.build;
installerIso = "${installer.isoImage}/iso/${installer.isoImage.isoName}";
in
{
tf = {
type = "app";
program = tfout.tf.outPath;
};
tf-apply = {
type = "app";
program = tfout.apply.outPath;
};
tf-destroy = {
type = "app";
program = tfout.destroy.outPath;
};
test-installer = {
type = "app";
program =
(pkgs_.writeShellScript "test-vm" ''
${pkgs_.qemu}/bin/qemu-img create -f qcow2 /tmp/installer-vm-vdisk1 10G
${pkgs_.qemu}/bin/qemu-system-x86_64 -enable-kvm -nographic -m 2048 -boot d \
-cdrom "${installerIso}" -hda /tmp/installer-vm-vdisk1 \
-net user,hostfwd=tcp::10022-:22 -net nic
'').outPath;
};
test-installer-gui = {
type = "app";
program =
(pkgs_.writeShellScript "test-vm" ''
${pkgs_.qemu}/bin/qemu-img create -f qcow2 /tmp/installer-vm-vdisk1 10G
${pkgs_.qemu}/bin/qemu-system-x86_64 -enable-kvm -m 2048 -boot d \
-cdrom "${installerIso}" -hda /tmp/installer-vm-vdisk1 \
-net user,hostfwd=tcp::10022-:22 -net nic
'').outPath;
# TODO: add a variant that uses libvirt/virsh so we can test libvirt's funshit too
};
}
);
## PACKAGES #######################################################
packages = (pkgs.${system}.__colemickens_nixcfg_pkgs);
legacyPackages = pkgs;
## CI (sorta) #####################################################
bundle = pkgs.${system}.buildEnv {
name = "nixcfg-bundle";
paths = builtins.attrValues checks;
};
## CHECKS #########################################################
# TODO: ask mic92 about this pattern, he doesn't just build .${system} even though these checks are persystem
# TODO: also: we don't filter out toplevels... maybe toplevels.zeph should actually be toplevels.x86_64-linux.zeph ?
# ??? revisit...
# also, we're probably fine to remove ciAttrs now, nix-fast-build does recursive-ness, and ciAttrs doesn't even buildFarm anymore
# TODO: we're still preferring local builds for somemthings, do we need to add back the wrapper?????
# TODO: or look into the allowSubstitutesAlways new flag that lovesegfault commented about?
checks =
let
c_packages = lib.mapAttrs' (n: lib.nameValuePair "package-${n}") inputs.self.packages.${system};
c_devShells = lib.mapAttrs' (n: lib.nameValuePair "devShell-${n}") inputs.self.devShells.${system};
# c_toplevels = lib.mapAttrs'
# (n: v: lib.nameValuePair "toplevel-${n}" toplevels.${n})
# inputs.self.nixosConfigsEx.${system};
c_toplevels = lib.concatMapAttrs (n: v: { "toplevel-${n}" = v; }) ({
inherit (toplevels)
raisin
slynux
xeep
zeph
h96maxv58
openstick
openstick2
radxazero1
rock5b
installer-standard
installer-cosmic
installer-nvidia-ai
installer-standard-aarch64
;
});
c_extra = lib.concatMapAttrs (n: v: { "x86_64-linux-${n}" = v; }) ({
inherit (extra.x86_64-linux)
# installer
openstick-abootimg
openstick-bootimg
# h96maxv58-uboot
;
});
in
c_packages // c_devShells // c_toplevels // c_extra;
}
)
);
}