/
flake.nix
119 lines (106 loc) · 4.94 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
{
description = "NixOS and Home Manager Configuration";
inputs.nix-inputs.url = "github:MatthewCash/nix-inputs";
outputs = originalInputs @ { nix-inputs, ... }:
let
inputs = nix-inputs.outputs.inputs // builtins.removeAttrs originalInputs [ "nix-inputs" ];
inherit (inputs) nixpkgsStable nixpkgsUnstable flake-utils;
stableLib = nixpkgsStable.lib;
stateVersion = "23.11";
# Systems
systemNames = builtins.attrNames
(stableLib.attrsets.filterAttrs (n: v: v == "directory")
(builtins.readDir ./systems));
systemConfigList = builtins.map (name: {
inherit name;
value = import ./systems/${name} {
inherit nixpkgsStable nixpkgsUnstable;
} // (if stableLib.inPureEvalMode then {} else { system = builtins.currentSystem; });
}) systemNames;
systemConfigs = builtins.listToAttrs systemConfigList;
buildArgs = builtins.mapAttrs (name: systemConfig:
import ./systems/buildArgs.nix {
inherit systemConfig inputs nixpkgsStable nixpkgsUnstable stateVersion;
}
) systemConfigs;
# NixOS Configurations
nixosSystems = builtins.zipAttrsWith (name: both:
let
systemConfig = builtins.elemAt both 0;
buildArgs = builtins.elemAt both 1;
in
import ./systems/buildNixos.nix (buildArgs // {
inherit systemConfig buildArgs inputs nixpkgsStable nixpkgsUnstable stateVersion;
})
) [ systemConfigs buildArgs ];
nixosConfigurations = builtins.mapAttrs (name: system:
system.specialArgs.systemNixpkgs.lib.nixosSystem system
) nixosSystems;
# Standalone Home Manager Configurations
homeConfigurations = builtins.zipAttrsWith (systemName: both:
let
systemConfig = builtins.elemAt both 0;
buildArgs = builtins.elemAt both 1;
in
(import ./systems/buildHomeConfigs.nix (buildArgs // {
inherit (systemConfig) systemNixpkgs system homeConfig;
inherit buildArgs;
})).standalone
) [ systemConfigs buildArgs];
# NixOS Generators
generatorFormats = builtins.attrNames inputs.nixos-generators.nixosModules;
generatorList = builtins.map (formatName: {
name = formatName;
value = builtins.mapAttrs (systemName: system: inputs.nixos-generators.nixosGenerate ({
format = formatName;
pkgs = system.specialArgs.systemNixpkgs.legacyPackages.${system.system};
} // system)) nixosSystems;
}) generatorFormats;
generators = builtins.listToAttrs generatorList;
packages = { pkgsStable, pkgsUnstable }: let
nix = stableLib.getExe pkgsUnstable.nix;
eval = path: /* bash */ ''
echo "- eval .#${path}:"
out=$(${nix} eval --impure --raw path:.#${path})
printf "\t$out\n"
'';
excludeSystems = [ "installer" ];
testSystems = builtins.filter (name: !(builtins.elem name excludeSystems)) systemNames;
in rec {
inherit generators;
apply = pkgsStable.writeShellScriptBin "apply" /* bash */ ''
exec ${stableLib.getExe pkgsUnstable.nixos-rebuild} switch --flake path:. --use-remote-sudo $@
'';
full-upgrade = pkgsStable.writeShellScriptBin "full-upgrade" /* bash */ ''
${nix} flake update path:.
exec ${stableLib.getExe apply}
'';
test = pkgsStable.writeShellScriptBin "test" /* bash */ ''
set -e -o pipefail; shopt -s inherit_errexit
echo "Evaluating system configurations"
${builtins.concatStringsSep "\n" (builtins.map (name:
eval "nixosConfigurations.${name}.config.system.build.toplevel"
) testSystems)}
echo "Evaluating home configurations"
${builtins.concatStringsSep "\n" (stableLib.flatten (
(stableLib.mapAttrsToList (systemName: value: stableLib.mapAttrsToList (homeName: value:
eval "homeConfigurations.${systemName}.${homeName}"
) value) homeConfigurations)
))}
echo "All evaluations completed successfully!"
'';
};
in
{
inherit nixosConfigurations homeConfigurations;
packages = stableLib.listToAttrs (
stableLib.forEach flake-utils.lib.defaultSystems (system:
let
pkgsStable = nixpkgsStable.legacyPackages.${system};
pkgsUnstable = nixpkgsUnstable.legacyPackages.${system};
in
{ name = system; value = packages { inherit pkgsStable pkgsUnstable; }; }
)
);
};
}