-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
481 lines (437 loc) · 16.5 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
{
description = "VKleen's flakey nixos configuration";
inputs = {
nixpkgs.url = sourcehut:~vkleen/nixpkgs/local?host=git.sr.ht.kleen.org;
nixpkgs-power9.url = sourcehut:~vkleen/nixpkgs/local-power9?host=git.sr.ht.kleen.org;
nixpkgs-riscv.url = sourcehut:~vkleen/nixpkgs/local-riscv?host=git.sr.ht.kleen.org;
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
agenix = {
url = "github:ryantm/agenix";
inputs.nixpkgs.follows = "nixpkgs";
};
nixos-rocm-power9 = {
url = sourcehut:~vkleen/nixos-rocm?host=git.sr.ht.kleen.org;
flake = false;
inputs.nixpkgs.follows = "nixpkgs-power9";
};
freecad-src = {
#url = github:realthunder/FreeCAD/LinkDaily;
url = github:FreeCAD/FreeCAD;
flake = false;
};
freecad-assembly3-src = {
url = github:realthunder/FreeCAD_assembly3;
flake = false;
};
kicad-src = {
url = github:vkleen/kicad;
flake = false;
};
hledger-src = {
url = github:simonmichael/hledger;
flake = false;
};
alacritty-src = {
url = "github:alacritty/alacritty";
flake = false;
};
emoji-fzf = {
url = sourcehut:~vkleen/emoji-fzf?host=git.sr.ht.kleen.org;
inputs.nixpkgs.follows = "nixpkgs";
};
nix = {
url = "github:NixOS/nix";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-riscv = {
url = "github:NixOS/nix";
inputs.nixpkgs.follows = "nixpkgs-riscv";
};
nix-power9 = {
url = "github:NixOS/nix";
inputs.nixpkgs.follows = "nixpkgs-power9";
};
rmfakecloud-src = {
url = "github:ddvk/rmfakecloud";
flake = false;
};
kikit-src = {
url = "github:yaqwsx/KiKit";
flake = false;
};
eseries-src = {
url = "github:devbisme/eseries";
flake = false;
};
dptrp1-src = {
url = sourcehut:~vkleen/dpt-rp1-py/local?host=git.sr.ht.kleen.org;
flake = false;
};
poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
rmapi-src = {
url = "github:juruen/rmapi";
flake = false;
};
bfd-src = {
url = sourcehut:~vkleen/bfd?host=git.sr.ht.kleen.org;
flake = false;
};
gobgp-src = {
url = "github:osrg/gobgp";
flake = false;
};
lego-src = {
url = sourcehut:~vkleen/lego/zerossl-accounts?host=git.sr.ht.kleen.org;
flake = false;
};
hut-src = {
url = sourcehut:~emersion/hut;
flake = false;
};
lieer-src = {
url = github:gauteh/lieer;
flake = false;
};
utils = {
url = sourcehut:~vkleen/machine-utils?host=git.sr.ht.kleen.org;
inputs.nixpkgs.follows = "nixpkgs";
inputs.macname.follows = "macname";
};
macname = {
url = sourcehut:~vkleen/macname?host=git.sr.ht.kleen.org;
};
macname-power9 = {
url = sourcehut:~vkleen/macname?host=git.sr.ht.kleen.org;
inputs.nixpkgs.follows = "nixpkgs-power9";
};
bfd-monitor = {
url = sourcehut:~vkleen/bfd-monitor?host=git.sr.ht.kleen.org;
inputs.nixpkgs.follows = "nixpkgs";
inputs.poetry2nix.follows = "poetry2nix";
};
matrix-bifrost = {
url = sourcehut:~vkleen/matrix-bifrost?host=git.sr.ht.kleen.org;
inputs.nixpkgs.follows = "nixpkgs";
};
rmrl = {
url = sourcehut:~vkleen/rmrl?host=git.sr.ht.kleen.org;
inputs.nixpkgs.follows = "nixpkgs";
inputs.poetry2nix.follows = "poetry2nix";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
neovim-configuration = {
url = sourcehut:~vkleen/neovim-configuration?host=git.sr.ht.kleen.org;
inputs.utils.follows = "utils";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, ...}@inputs:
let
inherit (builtins)
attrNames
attrValues
elemAt
fromJSON
isNull
pathExists
toJSON
toString
;
inherit (inputs.nixpkgs) lib;
utils = inputs.utils.lib;
inherit (utils) recImport overrideModule;
inherit (lib)
composeManyExtensions
concatLists
concatMap
concatStrings
elem
filterAttrs
genAttrs
getAttrs
hasPrefix
isDerivation
listToAttrs
mapAttrs
mapAttrs'
mapAttrsToList
mkIf
nameValuePair
nixosSystem
optionalAttrs
recursiveUpdate
splitString
unique
;
allSystems = [ "x86_64-linux" "aarch64-linux" "powerpc64le-linux" "riscv64-linux" ];
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = genAttrs allSystems;
forAllSystems' = genAttrs supportedSystems;
forAllUsers = genAttrs (unique (map accountUserName (attrNames self.nixosModules.accounts)));
accountUserName = accountName:
let
accountName' = splitString "@" accountName;
in elemAt accountName' 0;
accountHostName = accountName:
let
accountName' = splitString "@" accountName;
in elemAt accountName' 1;
mkNixosConfiguration = addProfiles: dir: path: hostName: nixosSystem rec {
specialArgs = {
flake = self;
flakeInputs = inputs;
path = ./.;
};
modules =
let
defaultProfiles = with self.nixosModules.systemProfiles;
[ core
];
local = "${toString dir}/${path}";
argsModule._module.args = {
customUtils = utils;
inherit hostName;
};
accountModules = attrValues (filterAttrs accountMatchesHost self.nixosModules.accounts);
accountMatchesHost = n: _v: accountHostName n == hostName;
in attrValues (filterAttrs (n: _v: !(elem n ["systemProfiles" "users" "userProfiles" "accounts"]))
self.nixosModules
)
++ [ argsModule ]
++ defaultProfiles
++ addProfiles
++ [ local ]
++ accountModules;
};
mkSystemProfile = dir: path: profileName: {
imports = [ "${toString dir}/${path}" ];
config = {
system.profiles = [profileName];
};
};
defaultUserProfiles = userName: with self.nixosModules.userProfiles.${userName};
[ core
];
mkUserModule = dir: path: userName:
overrideModule (import "${toString dir}/${path}")
(inputs: inputs // { inherit userName; })
(outputs:
{ _file = "${toString dir}/${path}"; }
// outputs
// { imports = defaultUserProfiles userName ++ (outputs.imports or []); });
mkUserProfile = userName: dir: path: profileName:
let
profileModule = overrideModule (import "${toString dir}/${path}")
(inputs: inputs // { inherit userName; })
(outputs:
{ _file = "${toString dir}/${path}"; }
// outputs);
in {
imports = [ profileModule ];
config = {
users.users.${userName}.profiles = [ profileName ];
};
};
mkAccountModule = dir: path: accountName:
let
userName = accountUserName accountName;
in overrideModule
(import "${toString dir}/${path}")
(inputs: inputs // { inherit userName; })
(outputs: { _file = "${toString dir}/${path}"; }
// outputs
// { imports = [ self.nixosModules.users.${userName} or
({...}: { imports = defaultUserProfiles userName; })
]
++ (outputs.imports or []); });
activateNixosConfigurations = forAllSystems (system:
filterAttrs (_: v: v != null)
(mapAttrs' (hostName: nixosConfig: nameValuePair "${hostName}-activate" (
if system == nixosConfig.config.nixpkgs.pkgs.stdenv.targetPlatform.system
then { type = "app";
program = "${nixosConfig.config.system.build.toplevel}/bin/switch-to-configuration";
}
else null
)
)
self.nixosConfigurations));
onlySystems = systems: overlay:
final: prev: optionalAttrs (elem prev.stdenv.targetPlatform.system systems) (overlay final prev);
forSystemsOverlay = defaultOverlay: overlays: final: prev: (overlays."${prev.stdenv.targetPlatform.system}" or defaultOverlay) final prev;
utilOverlay =
final: prev: {
lib = prev.lib // {
onlySystems = systems: overlay:
optionalAttrs (elem prev.stdenv.targetPlatform.system systems) overlay;
forSystemsOverlay = defaultOverlay: overlays: overlays."${prev.stdenv.targetPlatform.system}" or defaultOverlay;
inherit allSystems supportedSystems;
};
};
overlays =
recImport { dir = ./overlays; } //
{
pkgs = self.overlay;
poetry2nix = inputs.poetry2nix.overlay;
#nix = forSystemsOverlay inputs.nix.overlays.default
# ( { "powerpc64le-linux" = inputs.nix-power9.overlays.default; }
# // { "riscv64-linux" = inputs.nix-riscv.overlays.default; }
# );
macname = forSystemsOverlay
(_: _: {})
(forAllSystems (system: _: _: { inherit (inputs.macname.packages."${system}") macname; })
// { "powerpc64le-linux" = _: _: { inherit (inputs.macname-power9.packages."powerpc64le-linux") macname; }; });
sources = final: prev: {
inherit (inputs)
alacritty-src
bfd-src
dptrp1-src
eseries-src
freecad-assembly3-src
freecad-src
gobgp-src
hledger-src
hut-src
kicad-src
kikit-src
lego-src
lieer-src
rmapi-src
rmfakecloud-src
;
};
};
pkgsImport = system: pkgs:
import pkgs {
inherit system;
overlays = [utilOverlay] ++ attrValues overlays;
config = { allowUnfree = true; allowUnsupportedSystem = true; };
};
pkgsImportCross = localSystem: crossSystem: pkgs:
import pkgs {
inherit localSystem crossSystem;
overlays = [utilOverlay] ++ attrValues overlays;
config = { allowUnfree = true; allowUnsupportedSystem = true; };
};
pkgset =
(forAllSystems' (s: pkgsImport s inputs.nixpkgs))
// { "powerpc64le-linux" = (pkgsImport "powerpc64le-linux" inputs.nixpkgs-power9).extend (import inputs.nixos-rocm-power9); }
// { "riscv64-linux" = pkgsImport "riscv64-linux" inputs.nixpkgs-riscv; };
pkgSources = {
local = inputs.nixpkgs;
local-power9 = inputs.nixpkgs-power9;
local-riscv = inputs.nixpkgs-riscv;
};
installerProfiles = system:
let nixpkgs-path = pkgset.${system}.path;
mkInstallerProfile = dir: path: {
imports = [ "${toString dir}/${path}" ];
};
in mapAttrs (name: {path, output}: {
profile = mkInstallerProfile nixpkgs-path path;
inherit output;
})
{ cd-dvd = {
path = "nixos/modules/installer/cd-dvd/installation-cd-minimal.nix";
output = out: out.config.system.build.isoImage;
};
netboot = {
path = "nixos/modules/installer/netboot/netboot-minimal.nix";
output = out: (pkgset.${system}.symlinkJoin {
name = "netboot";
paths = with out.config.system.build; [ netbootRamdisk kernel netbootIpxeScript ]; preferLocalBuild = true;
});
};
};
installerConfig = if pathExists ./installer.nix
then "installer.nix"
else (if pathExists ./installer then "installer" else null);
installers =
let mkInstallers = system: mapAttrs (mkInstaller system) (installerProfiles system);
mkInstaller = system: name: {profile, output}:
output (mkNixosConfiguration [profile { config = { nixpkgs.system = system; }; }]
./.
installerConfig
"installer"
);
in if !(isNull installerConfig)
then { installers = forAllSystems (system: mkInstallers system); }
else {};
rtpPath = ".";
addRtp = path: derivation:
derivation // { rtp = "${derivation}/${path}"; };
vimPlugin = pkgs: ref: vimPluginSubdir pkgs ref "";
vimPluginSubdir = pkgs: ref: d: addRtp "${rtpPath}/${ref}" (pkgs.stdenv.mkDerivation {
name = "vimplugin-${lib.strings.sanitizeDerivationName ref}";
unpackPhase = ":";
buildPhase = ":";
configurePhase = ":";
installPhase = ''
runHook preInstall
target="$out/${rtpPath}"
mkdir -p "$target"
cp -r "${inputs."${ref}".outPath}/${d}/"* "$target"
runHook postInstall
'';
});
in
{
nixosModules =
let modulesAttrs = recImport { dir = ./modules; };
systemProfiles = recImport rec { dir = ./system-profiles; _import = mkSystemProfile dir; };
users = recImport rec { dir = ./users; _import = mkUserModule dir; };
userProfiles = forAllUsers (userName: recImport rec { dir = ./user-profiles; _import = mkUserProfile userName dir; });
accounts = recursiveUpdate rootAccounts (recImport rec { dir = ./accounts; _import = mkAccountModule dir; });
rootAccounts = mapAttrs' (hostName: _: nameValuePair
"root@${hostName}"
({...}:
{ imports = [ self.nixosModules.users.root or
({...}: { imports = defaultUserProfiles "root"; })
];
}))
self.nixosConfigurations;
in modulesAttrs // { inherit systemProfiles users userProfiles accounts; };
nixosConfigurations =
recImport rec { dir = ./hosts; _import = mkNixosConfiguration [] dir; };
homeManagerModules = recImport rec { dir = ./home-modules; };
homeConfigurations = listToAttrs (concatLists (
mapAttrsToList
(hostname: nixosConfig:
mapAttrsToList (username: configuration: nameValuePair "${username}@${hostname}"
{ inherit (configuration.home)
activationPackage;
})
nixosConfig.config.home-manager.users)
self.nixosConfigurations));
overlay = import ./pkgs; # Dummy system
overlays = {
inherit utilOverlay;
} // overlays;
legacyPackages = pkgset;
packages = forAllSystems (system:
let
pkgs = pkgset."${system}";
pkgNames = concatMap (o: attrNames (o pkgs pkgs)) (attrValues overlays);
in filterAttrs (_: isDerivation) (getAttrs pkgNames pkgset."${system}"));
apps = activateNixosConfigurations;
devShell = forAllSystems' (system: import ./shell.nix ({
pkgs = self.legacyPackages.${system};
inherit (inputs.home-manager.packages.${system}) home-manager;
} // (if inputs.agenix.packages ? ${system} then {
inherit (inputs.agenix.packages.${system}) agenix;
} else {})));
defaultTemplate = {
path = ./.;
description = "A flakey nixos configuration";
};
checks = self.packages;
} // installers;
}