-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
299 lines (270 loc) · 9.24 KB
/
Copy pathflake.nix
File metadata and controls
299 lines (270 loc) · 9.24 KB
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
{
description = "NixFleet - Agentless fleet management with Nix";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
nix-darwin = {
url = "github:LnL7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
nix2container = {
url = "github:nlewo/nix2container";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
nix-darwin,
nix2container,
}:
let
# Supported systems for the CLI/tooling
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
# Helper to generate outputs for each system
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Nixpkgs instantiated for each system
nixpkgsFor = forAllSystems (
system:
import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
}
);
# Create a NixFleet host configuration (for Ubuntu hosts)
mkNixFleetConfiguration =
{
system ? "x86_64-linux",
modules ? [ ],
specialArgs ? { },
}:
let
pkgs = nixpkgsFor.${system};
lib = nixpkgs.lib;
# Evaluate the modules
evaluated = lib.evalModules {
modules = [
# Core NixFleet module
./modules/nixfleet
# Manage /etc/nix/nix.custom.conf (trusted-users) on all Ubuntu
# hosts — deploy must be a trusted-user for apply to copy closures.
./modules/nix-config.nix
# Provide pkgs
{ _module.args = { inherit pkgs; }; }
]
++ modules;
specialArgs = {
inherit lib;
}
// specialArgs;
};
in
{
inherit (evaluated) config options;
# The main system derivation for deployment
system = evaluated.config.nixfleet.ubuntu.system;
# Convenience accessors
manifestHash = evaluated.config.nixfleet.ubuntu.manifestHash;
hostName = evaluated.config.nixfleet.host.name;
base = evaluated.config.nixfleet.host.base;
# Declarative Synology DSM state (Model B) — reconciled by the CLI over
# the DSM API. Lazy: only forced by `nix eval … .synology`, so ubuntu
# hosts never build it.
synology = evaluated.config.nixfleet.synology;
};
# Create a NixOS configuration with NixFleet modules
mkNixOSFleetConfiguration =
{
system ? "x86_64-linux",
modules ? [ ],
specialArgs ? { },
}:
nixpkgs.lib.nixosSystem {
inherit system specialArgs;
modules = [
# NixFleet options module (for nixfleet.* interface)
./modules/nixfleet/options.nix
# NixOS backend compiler (translates nixfleet.* to NixOS options)
./backends/nixos/compile.nix
]
++ modules;
};
# Create a nix-darwin configuration with NixFleet modules
mkDarwinFleetConfiguration =
{
system ? "aarch64-darwin",
modules ? [ ],
specialArgs ? { },
}:
nix-darwin.lib.darwinSystem {
inherit system specialArgs;
modules = [
# NixFleet options module (for nixfleet.* interface)
./modules/nixfleet/options.nix
# nix-darwin backend compiler (translates nixfleet.* to darwin options)
./backends/darwin/compile.nix
]
++ modules;
};
in
{
# Overlay for NixFleet packages
overlays.default = final: prev: {
nixfleet = final.callPackage ./pkgs/nixfleet {
gitCommit = self.rev or self.dirtyRev or "";
gitTag = if self ? rev then "v0.1.0" else "dev";
};
spire-agent = final.callPackage ./pkgs/spire-agent { };
};
# CLI package for each system + netboot images for x86_64-linux
packages = forAllSystems (
system:
let
pkgs = nixpkgsFor.${system};
# Helper to build a netboot image package from NixOS modules
mkNetboot =
name: modules:
let
sys = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
inherit modules;
};
in
pkgs.runCommand "netboot-${name}" { } ''
mkdir -p $out
ln -s ${sys.config.system.build.kernel}/bzImage $out/bzImage
ln -s ${sys.config.system.build.netbootRamdisk}/initrd $out/initrd
ln -s ${sys.config.system.build.squashfsStore} $out/nix-store.squashfs
echo "init=${sys.config.system.build.toplevel}/init loglevel=4" > $out/cmdline
'';
in
{
default = pkgs.nixfleet;
nixfleet = pkgs.nixfleet;
spire-agent = pkgs.spire-agent;
}
// (
if system == "x86_64-linux" then
let
n2c = nix2container.packages.${system}.nix2container;
in
{
netboot-gtr = mkNetboot "gtr" [ ./netboot/gtr.nix ];
netboot-gtr-diskless = mkNetboot "gtr-diskless" [ ./netboot/gtr-diskless.nix ];
# Agent OCI images (Linux only — container targets)
agent-pm = import ./agents/pm { inherit n2c pkgs; };
agent-personal = import ./agents/personal { inherit n2c pkgs; };
agent-coder = import ./agents/coder { inherit n2c pkgs; };
agent-sre = import ./agents/sre { inherit n2c pkgs; };
agent-sage = import ./agents/sage { inherit n2c pkgs; };
agent-orchestrator = import ./agents/orchestrator { inherit n2c pkgs; };
# Ubuntu installer artifacts (autoinstall configs + scripts)
installer = pkgs.runCommand "nixfleet-installer" { } ''
mkdir -p $out/common
${nixpkgs.lib.concatStringsSep "\n" (
nixpkgs.lib.mapAttrsToList (name: cfg: ''
mkdir -p $out/${name}
cp ${cfg}/user-data $out/${name}/
cp ${cfg}/meta-data $out/${name}/
'') self.installerConfigs
)}
cp ${./installer/zfs-partition.sh} $out/common/zfs-partition.sh
cp ${./installer/nixfleet-late-commands.sh} $out/common/nixfleet-late-commands.sh
'';
}
else
{ }
)
);
# Development shell
devShells = forAllSystems (
system:
let
pkgs = nixpkgsFor.${system};
in
{
default = pkgs.mkShell {
name = "nixfleet-dev";
packages = with pkgs; [
# Go toolchain (for CLI)
go
gopls
golangci-lint
delve
# Nix tooling
nix-prefetch-git
nix-tree
nixpkgs-fmt
# SPIRE agent (for local identity)
pkgs.spire-agent
# SSH/deployment testing
openssh
# General utilities
jq
yq-go
age
ssh-to-age
sops
];
shellHook = ''
echo "NixFleet development shell"
echo "Go version: $(go version)"
echo ""
echo "Netboot images (x86_64-linux only):"
echo " nix build .#netboot-gtr # GTR install/recovery image"
echo " nix build .#netboot-gtr-diskless # GTR diskless (NFS persistent)"
'';
};
}
);
# NixFleet library functions for host definitions
lib = (import ./lib { inherit (nixpkgs) lib; }) // {
inherit mkNixFleetConfiguration mkNixOSFleetConfiguration mkDarwinFleetConfiguration;
};
# NixFleet host configurations (Ubuntu hosts managed by NixFleet CLI)
nixfleetConfigurations = {
gti = mkNixFleetConfiguration {
modules = [ ./hosts/gti.nix ];
};
gtr = mkNixFleetConfiguration {
modules = [ ./hosts/gtr.nix ];
};
gtr-150 = mkNixFleetConfiguration {
modules = [ ./hosts/gtr-150.nix ];
};
gtr-151 = mkNixFleetConfiguration {
modules = [ ./hosts/gtr-151.nix ];
};
gtr-152 = mkNixFleetConfiguration {
modules = [ ./hosts/gtr-152.nix ];
};
gtr-153 = mkNixFleetConfiguration {
modules = [ ./hosts/gtr-153.nix ];
};
# Synology NAS — managed via the DSM API (Model B), not SSH.
znas = mkNixFleetConfiguration {
modules = [ ./hosts/znas.nix ];
};
};
# Per-host autoinstall configs for Ubuntu installer
installerConfigs =
let
pkgs = nixpkgsFor.x86_64-linux;
in
{
gtr = import ./installer/autoinstall.nix {
inherit (nixpkgs) lib;
inherit pkgs;
hostConfig = self.nixfleetConfigurations.gtr.config;
sshPubKey = ./secrets/deploy.pub;
};
};
};
}