-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeployment.nix
142 lines (118 loc) · 3.04 KB
/
deployment.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
{ nixpkgs
, ipam
, dns
, nftables
, gather
, sops
, disko
, private
, ...
}@inputs:
let
deploymentPkgs = import nixpkgs {
localSystem.system = "x86_64-linux";
};
mkMachine = machine: { lib, ... }:
with lib;
let
# Generate tags for a machine path
genTags = path:
if path != [ ]
then (genTags (init path)) ++ [ (concatStringsSep "-" path) ]
else [ ];
in
{
imports = [
./modules
./shared
machine.path
disko.nixosModules.disko
sops.nixosModules.sops
dns.nixosModules.default
nftables.nixosModules.default
gather.nixosModules.default
];
_module.args = {
inherit machine;
inherit (machine) path id;
private = import private;
};
deployment = {
targetHost = machine.target.host;
targetUser = machine.target.user;
tags = machine.tags
++ (genTags (init machine.id));
} // (machine.deployment or { });
nix.distributedBuilds = true;
nixpkgs.overlays = [
# Make nixpkgs-unstable available as subtree
(_: _: {
unstable = import inputs.nixpkgs-unstable {
localSystem.system = machine.system;
config = {
allowUnfree = true;
};
};
chaotic = inputs.chaotic.legacyPackages."${machine.system}";
})
# Let builders fetch sources directly instead of uploading
(self: super: (super.prefer-remote-fetch self super))
];
sops = {
defaultSopsFile = lib.mkForce (machine.path + "/secrets.yaml");
defaultSopsFormat = "yaml";
age.sshKeyPaths = [ "/etc/ssh/ssh_host_ed25519_key" ];
};
gather = {
target = name: "${machine.relPath}/gathered/${name}";
root = ./.;
};
system.stateVersion = machine.stateVersion;
};
machines =
let
inherit (deploymentPkgs.callPackage ./machines.nix { }) machines;
in
builtins.listToAttrs (map
(machine: {
inherit (machine) name;
value = {
# Find the nixpkgs path for the machine with the given name
nixpkgs = import (inputs."nixpkgs-${machine.name}" or nixpkgs) {
localSystem.system = machine.system;
config = {
allowUnfree = true;
};
};
# Build the machines
system = mkMachine machine;
};
})
machines);
in
(builtins.mapAttrs
(_: machine: machine.system)
machines)
// {
meta = {
nixpkgs = deploymentPkgs;
nodeNixpkgs = builtins.mapAttrs
(_: machine: machine.nixpkgs)
machines;
nodeSpecialArgs = builtins.mapAttrs
(_: machine: {
# Inject the lib extensions
lib = machine.nixpkgs.lib.foldl
(lib: lib.extend)
machine.nixpkgs.lib
[
ipam.lib
dns.lib
nftables.lib
];
# All available inputs
inputs = removeAttrs inputs [ "self" ];
})
machines;
};
}