confctl 2.2.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/.git-hooks/pre_commit/nixfmt.rb +13 -0
  3. data/.github/workflows/rspec.yml +64 -0
  4. data/.github/workflows/rubocop.yml +27 -0
  5. data/.github/workflows/tests.yml +139 -0
  6. data/.gitignore +12 -7
  7. data/.overcommit.yml +2 -0
  8. data/.rspec +1 -0
  9. data/.rubocop.yml +8 -1
  10. data/AGENTS.md +42 -0
  11. data/CHANGELOG.md +57 -0
  12. data/Gemfile +3 -2
  13. data/Gemfile.lock +198 -0
  14. data/README.md +166 -58
  15. data/Rakefile +5 -0
  16. data/confctl.gemspec +20 -2
  17. data/docs/carrier.md +3 -3
  18. data/docs/flake-inputs.md +159 -0
  19. data/docs/swpins-to-flakes.md +325 -0
  20. data/example/cluster/module-list.nix +2 -1
  21. data/example/cluster/nixos-machine/config.nix +12 -2
  22. data/example/cluster/nixos-machine/hardware.nix +6 -1
  23. data/example/cluster/vpsadminos-container/config.nix +6 -1
  24. data/example/cluster/vpsadminos-container/module.nix +4 -1
  25. data/example/cluster/vpsadminos-machine/config.nix +6 -1
  26. data/example/cluster/vpsadminos-machine/hardware.nix +6 -1
  27. data/example/cluster/vpsadminos-machine/module.nix +5 -2
  28. data/example/cluster/vpsfreecz-vps/config.nix +6 -1
  29. data/example/cluster/vpsfreecz-vps/module.nix +4 -1
  30. data/example/configs/swpins.nix +8 -3
  31. data/example/environments/base.nix +6 -1
  32. data/example/swpins/core.json +35 -0
  33. data/example-flake/.gitignore +2 -0
  34. data/example-flake/README.md +38 -0
  35. data/example-flake/cluster/cluster.nix +5 -0
  36. data/example-flake/cluster/module-list.nix +4 -0
  37. data/example-flake/cluster/nested/nixos-machine/config.nix +25 -0
  38. data/example-flake/cluster/nested/nixos-machine/hardware.nix +9 -0
  39. data/example-flake/cluster/nested/nixos-machine/module.nix +8 -0
  40. data/example-flake/cluster/nixos-machine/config.nix +25 -0
  41. data/example-flake/cluster/nixos-machine/hardware.nix +9 -0
  42. data/example-flake/cluster/nixos-machine/module.nix +8 -0
  43. data/example-flake/cluster/vpsadminos-container/config.nix +28 -0
  44. data/example-flake/cluster/vpsadminos-container/module.nix +8 -0
  45. data/example-flake/cluster/vpsadminos-machine/config.nix +27 -0
  46. data/example-flake/cluster/vpsadminos-machine/hardware.nix +9 -0
  47. data/example-flake/cluster/vpsadminos-machine/module.nix +8 -0
  48. data/example-flake/cluster/vpsfreecz-vps/config.nix +31 -0
  49. data/example-flake/cluster/vpsfreecz-vps/module.nix +8 -0
  50. data/example-flake/configs/confctl.nix +10 -0
  51. data/example-flake/data/default.nix +5 -0
  52. data/example-flake/data/ssh-keys.nix +7 -0
  53. data/example-flake/environments/base.nix +18 -0
  54. data/example-flake/flake.lock +75 -0
  55. data/example-flake/flake.nix +36 -0
  56. data/example-flake/modules/module-list.nix +13 -0
  57. data/example-flake/shell.nix +11 -0
  58. data/flake.lock +159 -0
  59. data/flake.nix +189 -0
  60. data/gemset.nix +1022 -0
  61. data/lib/confctl/cli/app.rb +145 -0
  62. data/lib/confctl/cli/attr_filters.rb +1 -1
  63. data/lib/confctl/cli/cluster.rb +681 -108
  64. data/lib/confctl/cli/command.rb +24 -2
  65. data/lib/confctl/cli/configuration.rb +171 -106
  66. data/lib/confctl/cli/generation.rb +65 -1
  67. data/lib/confctl/cli/inputs/channels.rb +190 -0
  68. data/lib/confctl/cli/inputs/machines.rb +83 -0
  69. data/lib/confctl/cli/inputs/root.rb +101 -0
  70. data/lib/confctl/cli/inputs.rb +5 -0
  71. data/lib/confctl/cli/log_view.rb +21 -10
  72. data/lib/confctl/cli/migrate/swpins_to_flakes.rb +866 -0
  73. data/lib/confctl/cli/migrate.rb +5 -0
  74. data/lib/confctl/cli/output_formatter.rb +5 -7
  75. data/lib/confctl/cli/swpins/base.rb +9 -0
  76. data/lib/confctl/cli/swpins/channel.rb +2 -5
  77. data/lib/confctl/cli/swpins/cluster.rb +2 -5
  78. data/lib/confctl/cli/swpins/core.rb +2 -5
  79. data/lib/confctl/config_type.rb +7 -0
  80. data/lib/confctl/flake_lock.rb +78 -0
  81. data/lib/confctl/flake_lock_diff.rb +36 -0
  82. data/lib/confctl/generation/build.rb +131 -24
  83. data/lib/confctl/generation/build_list.rb +4 -3
  84. data/lib/confctl/generation/unified.rb +14 -1
  85. data/lib/confctl/git_repo_mirror.rb +2 -2
  86. data/lib/confctl/health_checks/run_command.rb +3 -2
  87. data/lib/confctl/health_checks/systemd/properties.rb +1 -1
  88. data/lib/confctl/health_checks/systemd/property_list.rb +2 -2
  89. data/lib/confctl/inputs/commit_message.rb +125 -0
  90. data/lib/confctl/inputs/git_commit.rb +17 -0
  91. data/lib/confctl/inputs/nix_output_guard.rb +37 -0
  92. data/lib/confctl/inputs/setter.rb +179 -0
  93. data/lib/confctl/inputs/updater.rb +76 -0
  94. data/lib/confctl/inputs.rb +5 -0
  95. data/lib/confctl/inputs_info.rb +50 -0
  96. data/lib/confctl/line_buffer.rb +1 -1
  97. data/lib/confctl/machine.rb +18 -3
  98. data/lib/confctl/machine_control.rb +8 -2
  99. data/lib/confctl/machine_list.rb +2 -2
  100. data/lib/confctl/machine_status.rb +63 -20
  101. data/lib/confctl/nix/args.rb +48 -0
  102. data/lib/confctl/nix.rb +30 -437
  103. data/lib/confctl/nix_build_flake.rb +95 -0
  104. data/lib/confctl/nix_copy.rb +14 -2
  105. data/lib/confctl/nix_flake.rb +449 -0
  106. data/lib/confctl/nix_format.rb +3 -3
  107. data/lib/confctl/nix_legacy.rb +467 -0
  108. data/lib/confctl/swpins/change_set.rb +29 -3
  109. data/lib/confctl/swpins/specs/base.rb +2 -2
  110. data/lib/confctl/ui.rb +19 -0
  111. data/lib/confctl/version.rb +1 -1
  112. data/man/index.html +11 -0
  113. data/man/man8/confctl-options.nix.8.html +113 -0
  114. data/man/man8/confctl.8 +152 -21
  115. data/man/man8/confctl.8.html +355 -0
  116. data/man/man8/confctl.8.md +148 -17
  117. data/man/style.css +301 -0
  118. data/nix/evaluator.nix +94 -69
  119. data/nix/flake/mk-confctl-devshell.nix +85 -0
  120. data/nix/flake/mk-confctl-outputs.nix +522 -0
  121. data/nix/flake/mk-config-devshell.nix +168 -0
  122. data/nix/lib/default.nix +118 -65
  123. data/nix/lib/machine/default.nix +65 -45
  124. data/nix/lib/machine/info.nix +16 -5
  125. data/nix/lib/swpins/eval.nix +42 -29
  126. data/nix/lib/swpins/options.nix +6 -2
  127. data/nix/machines.nix +23 -15
  128. data/nix/modules/cluster/default.nix +104 -41
  129. data/nix/modules/confctl/carrier/base.nix +11 -4
  130. data/nix/modules/confctl/carrier/carrier-env.rb +2 -2
  131. data/nix/modules/confctl/carrier/netboot/build-netboot-server.rb +50 -16
  132. data/nix/modules/confctl/carrier/netboot/nixos.nix +56 -24
  133. data/nix/modules/confctl/configuration-info.nix +17 -0
  134. data/nix/modules/confctl/generations.nix +2 -2
  135. data/nix/modules/confctl/host.nix +13 -0
  136. data/nix/modules/confctl/inputs-info.nix +21 -0
  137. data/nix/modules/confctl/kexec-netboot/default.nix +13 -6
  138. data/nix/modules/confctl/kexec-netboot/kexec-netboot.8.adoc +3 -0
  139. data/nix/modules/confctl/kexec-netboot/kexec-netboot.rb +25 -16
  140. data/nix/modules/confctl/nix.nix +31 -1
  141. data/nix/modules/confctl/swpins.nix +13 -6
  142. data/nix/modules/module-list.nix +4 -2
  143. data/nix/modules/system-list.nix +4 -1
  144. data/nix/package.nix +37 -0
  145. data/shell.nix +39 -8
  146. data/skills/confctl-configuration-update/SKILL.md +228 -0
  147. data/skills/confctl-configuration-update/agents/openai.yaml +4 -0
  148. data/skills/confctl-release/SKILL.md +102 -0
  149. data/skills/confctl-release/agents/openai.yaml +4 -0
  150. data/spec/confctl/cli/cluster_health_check_spec.rb +43 -0
  151. data/spec/confctl/cli/cluster_skip_current_deploy_spec.rb +157 -0
  152. data/spec/confctl/cli/cluster_status_flake_spec.rb +83 -0
  153. data/spec/confctl/cli/inputs_set_output_spec.rb +70 -0
  154. data/spec/confctl/configuration_spec.rb +45 -0
  155. data/spec/confctl/inputs_spec.rb +104 -0
  156. data/spec/confctl/machine_control_spec.rb +112 -0
  157. data/spec/confctl/machine_list_spec.rb +47 -0
  158. data/spec/confctl/nix_flake_spec.rb +41 -0
  159. data/spec/confctl/swpins_spec.rb +106 -0
  160. data/spec/generation/build_modes_spec.rb +132 -0
  161. data/spec/inputs/commit_message_spec.rb +205 -0
  162. data/spec/inputs/nix_cached_fallback_spec.rb +50 -0
  163. data/spec/inputs/nix_output_guard_spec.rb +45 -0
  164. data/spec/spec_helper.rb +12 -0
  165. data/spec/support/cli_helper.rb +57 -0
  166. data/test-runner.sh +7 -0
  167. data/tests/all-tests.nix +30 -0
  168. data/tests/make-test.nix +15 -0
  169. data/tests/runner/extensions/confctl_helpers.rb +238 -0
  170. data/tests/runner/extensions/hostfwd_ports.rb +41 -0
  171. data/tests/suite/auto_rollback.nix +344 -0
  172. data/tests/suite/carrier/deploy.nix +751 -0
  173. data/tests/suite/carrier/netboot.nix +849 -0
  174. data/tests/suite/deploy/base.nix +806 -0
  175. data/tests/suite/deploy/flakes.nix +1 -0
  176. data/tests/suite/deploy/swpins.nix +1 -0
  177. metadata +104 -4
  178. data/nix/modules/confctl/overlays.nix +0 -15
@@ -0,0 +1,751 @@
1
+ import ../../make-test.nix (
2
+ {
3
+ pkgs,
4
+ confctlPackage,
5
+ confctlSrc,
6
+ ...
7
+ }:
8
+ let
9
+ confctlBin =
10
+ if confctlPackage == null then
11
+ throw "suiteArgs.confctlPackage is required"
12
+ else
13
+ "${confctlPackage}/bin/confctl";
14
+
15
+ confctlSource = if confctlSrc == null then throw "suiteArgs.confctlSrc is required" else confctlSrc;
16
+ in
17
+ {
18
+ name = "carrier-deploy";
19
+
20
+ description = ''
21
+ Verify standalone deploys and carried profile deploys on a NixOS carrier for NixOS and vpsAdminOS machines.
22
+ '';
23
+
24
+ tags = [
25
+ "ci"
26
+ ];
27
+
28
+ machines = {
29
+ carrier = {
30
+ spin = "nixos";
31
+ diskSize = 20480;
32
+ networks = [
33
+ {
34
+ type = "user";
35
+ opts = {
36
+ hostForward = "tcp::net1-:22";
37
+ network = "10.0.2.0/24";
38
+ host = "10.0.2.2";
39
+ dns = "10.0.2.3";
40
+ };
41
+ }
42
+ ];
43
+ config = {
44
+ services.openssh = {
45
+ enable = true;
46
+ settings = {
47
+ PermitRootLogin = "yes";
48
+ PasswordAuthentication = false;
49
+ };
50
+ };
51
+ networking.firewall.enable = false;
52
+ environment.systemPackages = with pkgs; [
53
+ git
54
+ ];
55
+ };
56
+ };
57
+
58
+ nixos = {
59
+ spin = "nixos";
60
+ diskSize = 20480;
61
+ networks = [
62
+ {
63
+ type = "user";
64
+ opts = {
65
+ hostForward = "tcp::net2-:22";
66
+ network = "10.0.2.0/24";
67
+ host = "10.0.2.2";
68
+ dns = "10.0.2.3";
69
+ };
70
+ }
71
+ ];
72
+ config = {
73
+ services.openssh = {
74
+ enable = true;
75
+ settings = {
76
+ PermitRootLogin = "yes";
77
+ PasswordAuthentication = false;
78
+ };
79
+ };
80
+ networking.firewall.enable = false;
81
+ environment.systemPackages = with pkgs; [
82
+ git
83
+ ];
84
+ };
85
+ };
86
+
87
+ vpsadminos = {
88
+ spin = "vpsadminos";
89
+ networks = [
90
+ {
91
+ type = "user";
92
+ opts = {
93
+ hostForward = "tcp::net3-:22";
94
+ network = "10.0.2.0/24";
95
+ host = "10.0.2.2";
96
+ dns = "10.0.2.3";
97
+ };
98
+ }
99
+ ];
100
+ config = {
101
+ services.openssh = {
102
+ enable = true;
103
+ settings = {
104
+ PermitRootLogin = "yes";
105
+ PasswordAuthentication = false;
106
+ };
107
+ };
108
+ boot.qemu = {
109
+ memory = 2048;
110
+ cpus = 4;
111
+ };
112
+ networking.firewall.enable = false;
113
+ environment.systemPackages = with pkgs; [
114
+ git
115
+ ];
116
+ };
117
+ };
118
+ };
119
+
120
+ testScript = ''
121
+ require 'fileutils'
122
+ require 'json'
123
+
124
+ CARRIER_MACHINE = 'carrier'
125
+ NIXOS_MACHINE = 'nixos-machine'
126
+ VPSADMINOS_MACHINE = 'vpsadminos-machine'
127
+
128
+ CARRIED_NIXOS_MACHINE = 'carrier#nixos-machine'
129
+ CARRIED_VPSADMINOS_MACHINE = 'carrier#vpsadminos-machine'
130
+
131
+ NIXOS_CARRIED_ENTRIES = %w[machine.json build-mode kernel init]
132
+ VPSADMINOS_CARRIED_ENTRIES = %w[machine.json build-mode bzImage initrd root.squashfs kernel-params]
133
+
134
+ def write_flake_root!(conf_dir)
135
+ File.write(File.join(conf_dir, 'flake.nix'), <<~NIX)
136
+ {
137
+ description = "confctl carrier deploy test fixture";
138
+
139
+ inputs = {
140
+ confctl.url = "path:#{confctl_src}";
141
+ nixpkgs.follows = "confctl/nixpkgs";
142
+ vpsadminos.follows = "confctl/vpsadminos";
143
+ };
144
+
145
+ outputs = inputs@{ self, confctl, ... }:
146
+ let
147
+ channels = {
148
+ carrier = {
149
+ nixpkgs = "nixpkgs";
150
+ vpsadminos = "vpsadminos";
151
+ };
152
+ };
153
+
154
+ confctlOutputs = confctl.lib.mkConfctlOutputs {
155
+ confDir = ./.;
156
+ inherit inputs channels;
157
+ };
158
+ in
159
+ {
160
+ confctl = confctlOutputs;
161
+
162
+ devShells.x86_64-linux.default = confctl.lib.mkConfigDevShell {
163
+ system = "x86_64-linux";
164
+ mode = "minimal";
165
+ };
166
+ };
167
+ }
168
+ NIX
169
+ end
170
+
171
+ def write_hardware_config!(conf_dir, machine_name)
172
+ dir = File.join(conf_dir, 'cluster', machine_name)
173
+ FileUtils.mkdir_p(dir)
174
+
175
+ File.write(File.join(dir, 'hardware.nix'), <<~NIX)
176
+ {
177
+ config,
178
+ pkgs,
179
+ lib,
180
+ ...
181
+ }:
182
+ {
183
+ # Test fixture hardware configuration.
184
+ }
185
+ NIX
186
+ end
187
+
188
+ def write_nixos_config!(conf_dir, machine_name, marker:, carrier_enabled:, build_dist:)
189
+ write_hardware_config!(conf_dir, machine_name)
190
+
191
+ carrier_config =
192
+ if carrier_enabled
193
+ <<~NIX
194
+ confctl.carrier.onChangeCommands = '''
195
+ {
196
+ echo "on-change"
197
+ for profile in /nix/var/nix/profiles/confctl-*; do
198
+ [ -e "$profile" ] || continue
199
+ echo "$profile -> $(readlink "$profile")"
200
+ done
201
+ } >> /var/log/confctl-carrier-events.log
202
+ ''';
203
+ NIX
204
+ else
205
+ ""
206
+ end
207
+
208
+ dist_config =
209
+ if build_dist
210
+ <<~NIX
211
+ system.build.dist = pkgs.symlinkJoin {
212
+ name = "#{machine_name}-carried";
213
+ paths = [
214
+ config.system.build.toplevel
215
+ ];
216
+ postBuild = '''
217
+ ln -s ''${machineJson} $out/machine.json
218
+ ln -s ''${buildMode} $out/build-mode
219
+ ''';
220
+ };
221
+ NIX
222
+ else
223
+ ""
224
+ end
225
+
226
+ File.write(File.join(conf_dir, "cluster/#{machine_name}/config.nix"), <<~NIX)
227
+ {
228
+ config,
229
+ pkgs,
230
+ lib,
231
+ inputsInfo,
232
+ inputs,
233
+ ...
234
+ }:
235
+ let
236
+ machineJson = pkgs.writeText "machine-#{machine_name}.json" (builtins.toJSON {
237
+ machine = "#{machine_name}";
238
+ marker = "#{marker}";
239
+ spin = "nixos";
240
+ label = "#{machine_name}";
241
+ toplevel = builtins.unsafeDiscardStringContext config.system.build.toplevel;
242
+ inputsInfo = inputsInfo;
243
+ });
244
+
245
+ buildMode = pkgs.writeText "build-mode-#{machine_name}" "carried\n";
246
+ in
247
+ {
248
+ imports = [
249
+ ../../environments/base.nix
250
+ ./hardware.nix
251
+ (
252
+ { lib, ... }:
253
+ {
254
+ options.virtualisation.cores = lib.mkOption {
255
+ type = lib.types.int;
256
+ default = 2;
257
+ };
258
+ options.virtualisation.memorySize = lib.mkOption {
259
+ type = lib.types.int;
260
+ default = 2048;
261
+ };
262
+ options.virtualisation.mountHostNixStore = lib.mkOption {
263
+ type = lib.types.bool;
264
+ default = false;
265
+ };
266
+ options.virtualisation.sharedDirectories = lib.mkOption {
267
+ type = lib.types.attrsOf lib.types.anything;
268
+ default = { };
269
+ };
270
+ }
271
+ )
272
+ (inputs.vpsadminos + "/tests/configs/nixos/base.nix")
273
+ ];
274
+
275
+ networking.hostName = "#{machine_name}";
276
+ time.timeZone = lib.mkForce "UTC";
277
+ boot.loader.grub.enable = false;
278
+
279
+ fileSystems."/" = {
280
+ device = "/dev/disk/by-label/nixos";
281
+ fsType = "ext4";
282
+ };
283
+
284
+ environment.etc."confctl-marker".text = "#{marker}\n";
285
+
286
+ #{dist_config}
287
+ #{carrier_config}
288
+ }
289
+ NIX
290
+ end
291
+
292
+ def write_vpsadminos_config!(conf_dir, marker:)
293
+ write_hardware_config!(conf_dir, VPSADMINOS_MACHINE)
294
+
295
+ File.write(File.join(conf_dir, "cluster/#{VPSADMINOS_MACHINE}/config.nix"), <<~NIX)
296
+ {
297
+ config,
298
+ pkgs,
299
+ lib,
300
+ inputsInfo,
301
+ inputs,
302
+ ...
303
+ }:
304
+ let
305
+ machineJson = pkgs.writeText "machine-#{VPSADMINOS_MACHINE}.json" (builtins.toJSON {
306
+ machine = "#{VPSADMINOS_MACHINE}";
307
+ marker = "#{marker}";
308
+ spin = "vpsadminos";
309
+ label = "#{VPSADMINOS_MACHINE}";
310
+ toplevel = builtins.unsafeDiscardStringContext config.system.build.toplevel;
311
+ inputsInfo = inputsInfo;
312
+ });
313
+
314
+ buildMode = pkgs.writeText "build-mode-#{VPSADMINOS_MACHINE}" "carried\n";
315
+ in
316
+ {
317
+ imports = [
318
+ ../../environments/base.nix
319
+ ./hardware.nix
320
+ (inputs.vpsadminos + "/tests/configs/vpsadminos/base.nix")
321
+ ];
322
+
323
+ networking.hostName = "#{VPSADMINOS_MACHINE}";
324
+
325
+ boot.loader.grub.enable = false;
326
+ boot.supportedFilesystems = [ "zfs" ];
327
+ boot.kernelParams = [ "nolive" ];
328
+ boot.zfs.pools = { };
329
+
330
+ environment.etc."confctl-marker".text = "#{marker}\n";
331
+
332
+ system.distBuilderCommands = '''
333
+ ln -s ''${machineJson} $out/machine.json
334
+ ln -s ''${buildMode} $out/build-mode
335
+ ''';
336
+
337
+ system.stateVersion = "20.09";
338
+ }
339
+ NIX
340
+ end
341
+
342
+ def write_machine_modules!(conf_dir, carrier_port:, nixos_port:, vpsadminos_port:)
343
+ FileUtils.mkdir_p(File.join(conf_dir, 'cluster', 'carrier'))
344
+ FileUtils.mkdir_p(File.join(conf_dir, 'cluster', NIXOS_MACHINE))
345
+ FileUtils.mkdir_p(File.join(conf_dir, 'cluster', VPSADMINOS_MACHINE))
346
+
347
+ File.write(File.join(conf_dir, 'cluster/carrier/module.nix'), <<~NIX)
348
+ { config, ... }:
349
+ {
350
+ cluster."carrier" = {
351
+ spin = "nixos";
352
+ inputs.channels = [ "carrier" ];
353
+ host.target = "127.0.0.1";
354
+ host.port = #{carrier_port};
355
+ healthChecks.machineCommands = [
356
+ {
357
+ description = "true";
358
+ command = [ "true" ];
359
+ }
360
+ ];
361
+
362
+ carrier = {
363
+ enable = true;
364
+ machines = [
365
+ {
366
+ machine = "#{NIXOS_MACHINE}";
367
+ alias = "#{NIXOS_MACHINE}";
368
+ buildAttribute = [ "system" "build" "dist" ];
369
+ }
370
+ {
371
+ machine = "#{VPSADMINOS_MACHINE}";
372
+ alias = "#{VPSADMINOS_MACHINE}";
373
+ buildAttribute = [ "system" "build" "dist" ];
374
+ }
375
+ ];
376
+ };
377
+ };
378
+ }
379
+ NIX
380
+
381
+ File.write(File.join(conf_dir, "cluster/#{NIXOS_MACHINE}/module.nix"), <<~NIX)
382
+ { config, ... }:
383
+ {
384
+ cluster."#{NIXOS_MACHINE}" = {
385
+ spin = "nixos";
386
+ inputs.channels = [ "carrier" ];
387
+ host.target = "127.0.0.1";
388
+ host.port = #{nixos_port};
389
+ healthChecks.machineCommands = [
390
+ {
391
+ description = "true";
392
+ command = [ "true" ];
393
+ }
394
+ ];
395
+ };
396
+ }
397
+ NIX
398
+
399
+ File.write(File.join(conf_dir, "cluster/#{VPSADMINOS_MACHINE}/module.nix"), <<~NIX)
400
+ { config, ... }:
401
+ {
402
+ cluster."#{VPSADMINOS_MACHINE}" = {
403
+ spin = "vpsadminos";
404
+ inputs.channels = [ "carrier" ];
405
+ host.target = "127.0.0.1";
406
+ host.port = #{vpsadminos_port};
407
+ healthChecks.machineCommands = [
408
+ {
409
+ description = "true";
410
+ command = [ "true" ];
411
+ }
412
+ ];
413
+ };
414
+ }
415
+ NIX
416
+ end
417
+
418
+ def prepare_fixture!(conf_dir:, carrier_port:, nixos_port:, vpsadminos_port:, pubkey:)
419
+ prepare_fixture_dir!(conf_dir)
420
+ write_flake_root!(conf_dir)
421
+ write_machine_modules!(
422
+ conf_dir,
423
+ carrier_port:,
424
+ nixos_port:,
425
+ vpsadminos_port:
426
+ )
427
+ write_nixos_config!(conf_dir, CARRIER_MACHINE, marker: 'A', carrier_enabled: true, build_dist: false)
428
+ write_nixos_config!(conf_dir, NIXOS_MACHINE, marker: 'A', carrier_enabled: false, build_dist: true)
429
+ write_vpsadminos_config!(conf_dir, marker: 'A')
430
+ write_admin_ssh_keys!(conf_dir, pubkey)
431
+ write_cluster_modules!(
432
+ conf_dir,
433
+ [
434
+ 'carrier/module.nix',
435
+ "#{NIXOS_MACHINE}/module.nix",
436
+ "#{VPSADMINOS_MACHINE}/module.nix"
437
+ ]
438
+ )
439
+ init_fixture_repo!(conf_dir)
440
+ end
441
+
442
+ def machine_state(machine_name)
443
+ confctl_machine_state(machine_name)
444
+ end
445
+
446
+ def assert_machine_state(machine_name, profile:, current:)
447
+ expect(confctl_remote_realpath(machine_name, '/nix/var/nix/profiles/system')).to eq(profile)
448
+ expect(confctl_remote_realpath(machine_name, '/run/current-system')).to eq(current)
449
+ end
450
+
451
+ def carrier_profile_path(alias_name)
452
+ "/nix/var/nix/profiles/confctl-#{alias_name}"
453
+ end
454
+
455
+ def assert_carried_generation_matches!(carried_generation, standalone_generation, machine_name:, marker:, spin:, expected_entries:)
456
+ expect(carried_generation['toplevel']).not_to eq(standalone_generation['toplevel'])
457
+ expect(File.read(File.join(carried_generation['toplevel'], 'build-mode'))).to eq("carried\n")
458
+
459
+ machine_json = JSON.parse(File.read(File.join(carried_generation['toplevel'], 'machine.json')))
460
+ expect(machine_json['machine']).to eq(machine_name)
461
+ expect(machine_json['marker']).to eq(marker)
462
+ expect(machine_json['spin']).to eq(spin)
463
+ expect(machine_json['toplevel']).to eq(standalone_generation['toplevel'])
464
+
465
+ expected_entries.each do |entry|
466
+ expect(File.exist?(File.join(carried_generation['toplevel'], entry))).to be(true)
467
+ end
468
+ end
469
+
470
+ def assert_carried_profile!(alias_name, generation:, number:, expected_entries:)
471
+ profile = carrier_profile_path(alias_name)
472
+ generation_link = "#{profile}-#{number}-link"
473
+
474
+ expect(confctl_remote_realpath(CARRIER_MACHINE, profile)).to eq(generation['toplevel'])
475
+ expect(confctl_remote_realpath(CARRIER_MACHINE, generation_link)).to eq(generation['toplevel'])
476
+
477
+ expected_entries.each do |entry|
478
+ confctl_store_path_exists!(CARRIER_MACHINE, File.join(generation['toplevel'], entry))
479
+ end
480
+
481
+ confctl_ssh!(CARRIER_MACHINE, 'test', '-e', generation_link)
482
+ end
483
+
484
+ def assert_previous_carried_generation!(alias_name, generation:, number:)
485
+ generation_link = "#{carrier_profile_path(alias_name)}-#{number}-link"
486
+ expect(confctl_remote_realpath(CARRIER_MACHINE, generation_link)).to eq(generation['toplevel'])
487
+ end
488
+
489
+ def build_generation!(host)
490
+ confctl!('build', '--yes', host)
491
+ confctl_generation_info(host)
492
+ end
493
+
494
+ before(:suite) do
495
+ @carrier_port = ConfctlHostfwdPorts.reserve('net1')
496
+ @nixos_port = ConfctlHostfwdPorts.reserve('net2')
497
+ @vpsadminos_port = ConfctlHostfwdPorts.reserve('net3')
498
+
499
+ carrier.start
500
+ nixos.start
501
+ vpsadminos.start
502
+
503
+ @state_dir = @opts[:state_dir]
504
+ @conf_dir = File.join(@state_dir, 'conf')
505
+ @home_dir = File.join(@state_dir, 'home')
506
+ confctl_setup!(
507
+ bin: "${confctlBin}",
508
+ src: "${confctlSource}",
509
+ conf_dir: @conf_dir,
510
+ home_dir: @home_dir
511
+ )
512
+
513
+ @pubkey = setup_ssh_home!(@home_dir)
514
+
515
+ install_pubkey!(carrier, @pubkey)
516
+ install_pubkey!(nixos, @pubkey)
517
+ install_pubkey!(vpsadminos, @pubkey)
518
+
519
+ prepare_fixture!(
520
+ conf_dir: @conf_dir,
521
+ carrier_port: @carrier_port,
522
+ nixos_port: @nixos_port,
523
+ vpsadminos_port: @vpsadminos_port,
524
+ pubkey: @pubkey
525
+ )
526
+ end
527
+
528
+ describe 'confctl carrier deploy behavior', order: :defined do
529
+ before(:context) do
530
+ out = wait_for_confctl_connectivity!(expected_successes: 3, timeout: 180)
531
+ expect(out).to include('3 successful')
532
+ end
533
+
534
+ it 'builds and deploys standalone generations for carrier, NixOS and vpsAdminOS machines' do
535
+ @carrier_gen_a = build_generation!(CARRIER_MACHINE)
536
+ @nixos_gen_a = build_generation!(NIXOS_MACHINE)
537
+ @vpsadminos_gen_a = build_generation!(VPSADMINOS_MACHINE)
538
+
539
+ expect(File.executable?(File.join(@carrier_gen_a['toplevel'], 'bin', 'switch-to-configuration'))).to be(true)
540
+ expect(File.executable?(File.join(@nixos_gen_a['toplevel'], 'bin', 'switch-to-configuration'))).to be(true)
541
+
542
+ confctl!('deploy', '--yes', CARRIER_MACHINE)
543
+ confctl!('deploy', '--yes', NIXOS_MACHINE)
544
+ confctl!('deploy', '--yes', VPSADMINOS_MACHINE)
545
+
546
+ assert_machine_state(
547
+ CARRIER_MACHINE,
548
+ profile: @carrier_gen_a['toplevel'],
549
+ current: @carrier_gen_a['toplevel']
550
+ )
551
+ assert_machine_state(
552
+ NIXOS_MACHINE,
553
+ profile: @nixos_gen_a['toplevel'],
554
+ current: @nixos_gen_a['toplevel']
555
+ )
556
+ assert_machine_state(
557
+ VPSADMINOS_MACHINE,
558
+ profile: @vpsadminos_gen_a['toplevel'],
559
+ current: @vpsadminos_gen_a['toplevel']
560
+ )
561
+ end
562
+
563
+ it 'builds carried NixOS and vpsAdminOS generations from the same source machines' do
564
+ @carried_nixos_gen_a = build_generation!(CARRIED_NIXOS_MACHINE)
565
+ @carried_vpsadminos_gen_a = build_generation!(CARRIED_VPSADMINOS_MACHINE)
566
+
567
+ assert_carried_generation_matches!(
568
+ @carried_nixos_gen_a,
569
+ @nixos_gen_a,
570
+ machine_name: NIXOS_MACHINE,
571
+ marker: 'A',
572
+ spin: 'nixos',
573
+ expected_entries: NIXOS_CARRIED_ENTRIES
574
+ )
575
+ assert_carried_generation_matches!(
576
+ @carried_vpsadminos_gen_a,
577
+ @vpsadminos_gen_a,
578
+ machine_name: VPSADMINOS_MACHINE,
579
+ marker: 'A',
580
+ spin: 'vpsadminos',
581
+ expected_entries: VPSADMINOS_CARRIED_ENTRIES
582
+ )
583
+ end
584
+
585
+ it 'deploys carried generations to carrier-managed profiles' do
586
+ confctl!('deploy', '--yes', CARRIED_NIXOS_MACHINE)
587
+ confctl!('deploy', '--yes', CARRIED_VPSADMINOS_MACHINE)
588
+
589
+ assert_carried_profile!(
590
+ NIXOS_MACHINE,
591
+ generation: @carried_nixos_gen_a,
592
+ number: 1,
593
+ expected_entries: NIXOS_CARRIED_ENTRIES
594
+ )
595
+ assert_carried_profile!(
596
+ VPSADMINOS_MACHINE,
597
+ generation: @carried_vpsadminos_gen_a,
598
+ number: 1,
599
+ expected_entries: VPSADMINOS_CARRIED_ENTRIES
600
+ )
601
+
602
+ assert_machine_state(
603
+ CARRIER_MACHINE,
604
+ profile: @carrier_gen_a['toplevel'],
605
+ current: @carrier_gen_a['toplevel']
606
+ )
607
+ assert_machine_state(
608
+ NIXOS_MACHINE,
609
+ profile: @nixos_gen_a['toplevel'],
610
+ current: @nixos_gen_a['toplevel']
611
+ )
612
+ assert_machine_state(
613
+ VPSADMINOS_MACHINE,
614
+ profile: @vpsadminos_gen_a['toplevel'],
615
+ current: @vpsadminos_gen_a['toplevel']
616
+ )
617
+
618
+ log_out, = confctl_ssh!(CARRIER_MACHINE, 'cat', '/var/log/confctl-carrier-events.log')
619
+ expect(log_out).to include("/nix/var/nix/profiles/confctl-#{NIXOS_MACHINE}")
620
+ expect(log_out).to include("/nix/var/nix/profiles/confctl-#{VPSADMINOS_MACHINE}")
621
+ end
622
+
623
+ it 'skips repeated carried deploy when the carrier-managed profile is already current' do
624
+ log_before, = confctl_ssh!(CARRIER_MACHINE, 'cat', '/var/log/confctl-carrier-events.log')
625
+
626
+ out, = confctl!('deploy', '--yes', '--generation', @carried_nixos_gen_a['name'], CARRIED_NIXOS_MACHINE)
627
+ expect(out).to include("Skipping #{CARRIED_NIXOS_MACHINE}: already using target generation")
628
+
629
+ log_after, = confctl_ssh!(CARRIER_MACHINE, 'cat', '/var/log/confctl-carrier-events.log')
630
+ expect(log_after).to eq(log_before)
631
+
632
+ assert_carried_profile!(
633
+ NIXOS_MACHINE,
634
+ generation: @carried_nixos_gen_a,
635
+ number: 1,
636
+ expected_entries: NIXOS_CARRIED_ENTRIES
637
+ )
638
+ end
639
+
640
+ it 'builds updated standalone and carried generations for all machines' do
641
+ write_nixos_config!(@conf_dir, CARRIER_MACHINE, marker: 'B', carrier_enabled: true, build_dist: false)
642
+ write_nixos_config!(@conf_dir, NIXOS_MACHINE, marker: 'B', carrier_enabled: false, build_dist: true)
643
+ write_vpsadminos_config!(@conf_dir, marker: 'B')
644
+
645
+ @carrier_gen_b = build_generation!(CARRIER_MACHINE)
646
+ @nixos_gen_b = build_generation!(NIXOS_MACHINE)
647
+ @vpsadminos_gen_b = build_generation!(VPSADMINOS_MACHINE)
648
+ @carried_nixos_gen_b = build_generation!(CARRIED_NIXOS_MACHINE)
649
+ @carried_vpsadminos_gen_b = build_generation!(CARRIED_VPSADMINOS_MACHINE)
650
+
651
+ expect(@carrier_gen_b['toplevel']).not_to eq(@carrier_gen_a['toplevel'])
652
+ expect(@nixos_gen_b['toplevel']).not_to eq(@nixos_gen_a['toplevel'])
653
+ expect(@vpsadminos_gen_b['toplevel']).not_to eq(@vpsadminos_gen_a['toplevel'])
654
+
655
+ assert_carried_generation_matches!(
656
+ @carried_nixos_gen_b,
657
+ @nixos_gen_b,
658
+ machine_name: NIXOS_MACHINE,
659
+ marker: 'B',
660
+ spin: 'nixos',
661
+ expected_entries: NIXOS_CARRIED_ENTRIES
662
+ )
663
+ assert_carried_generation_matches!(
664
+ @carried_vpsadminos_gen_b,
665
+ @vpsadminos_gen_b,
666
+ machine_name: VPSADMINOS_MACHINE,
667
+ marker: 'B',
668
+ spin: 'vpsadminos',
669
+ expected_entries: VPSADMINOS_CARRIED_ENTRIES
670
+ )
671
+ end
672
+
673
+ it 'deploys standalone updates without disturbing carried profiles' do
674
+ confctl!('deploy', '--yes', '--generation', @carrier_gen_b['name'], CARRIER_MACHINE, 'switch')
675
+ confctl!('deploy', '--yes', '--generation', @nixos_gen_b['name'], NIXOS_MACHINE, 'switch')
676
+ confctl!('deploy', '--yes', '--generation', @vpsadminos_gen_b['name'], VPSADMINOS_MACHINE, 'switch')
677
+
678
+ assert_machine_state(
679
+ CARRIER_MACHINE,
680
+ profile: @carrier_gen_b['toplevel'],
681
+ current: @carrier_gen_b['toplevel']
682
+ )
683
+ assert_machine_state(
684
+ NIXOS_MACHINE,
685
+ profile: @nixos_gen_b['toplevel'],
686
+ current: @nixos_gen_b['toplevel']
687
+ )
688
+ assert_machine_state(
689
+ VPSADMINOS_MACHINE,
690
+ profile: @vpsadminos_gen_b['toplevel'],
691
+ current: @vpsadminos_gen_b['toplevel']
692
+ )
693
+
694
+ assert_carried_profile!(
695
+ NIXOS_MACHINE,
696
+ generation: @carried_nixos_gen_a,
697
+ number: 1,
698
+ expected_entries: NIXOS_CARRIED_ENTRIES
699
+ )
700
+ assert_carried_profile!(
701
+ VPSADMINOS_MACHINE,
702
+ generation: @carried_vpsadminos_gen_a,
703
+ number: 1,
704
+ expected_entries: VPSADMINOS_CARRIED_ENTRIES
705
+ )
706
+ end
707
+
708
+ it 'deploys updated carried generations and keeps both carrier profile generations' do
709
+ confctl!('deploy', '--yes', '--generation', @carried_nixos_gen_b['name'], CARRIED_NIXOS_MACHINE)
710
+ confctl!('deploy', '--yes', '--generation', @carried_vpsadminos_gen_b['name'], CARRIED_VPSADMINOS_MACHINE)
711
+
712
+ assert_carried_profile!(
713
+ NIXOS_MACHINE,
714
+ generation: @carried_nixos_gen_b,
715
+ number: 2,
716
+ expected_entries: NIXOS_CARRIED_ENTRIES
717
+ )
718
+ assert_carried_profile!(
719
+ VPSADMINOS_MACHINE,
720
+ generation: @carried_vpsadminos_gen_b,
721
+ number: 2,
722
+ expected_entries: VPSADMINOS_CARRIED_ENTRIES
723
+ )
724
+ assert_previous_carried_generation!(NIXOS_MACHINE, generation: @carried_nixos_gen_a, number: 1)
725
+ assert_previous_carried_generation!(VPSADMINOS_MACHINE, generation: @carried_vpsadminos_gen_a, number: 1)
726
+
727
+ assert_machine_state(
728
+ CARRIER_MACHINE,
729
+ profile: @carrier_gen_b['toplevel'],
730
+ current: @carrier_gen_b['toplevel']
731
+ )
732
+ assert_machine_state(
733
+ NIXOS_MACHINE,
734
+ profile: @nixos_gen_b['toplevel'],
735
+ current: @nixos_gen_b['toplevel']
736
+ )
737
+ assert_machine_state(
738
+ VPSADMINOS_MACHINE,
739
+ profile: @vpsadminos_gen_b['toplevel'],
740
+ current: @vpsadminos_gen_b['toplevel']
741
+ )
742
+ end
743
+
744
+ it 'keeps all standalone machines reachable at the end' do
745
+ out = wait_for_confctl_connectivity!(expected_successes: 3, timeout: 180)
746
+ expect(out).to include('3 successful')
747
+ end
748
+ end
749
+ '';
750
+ }
751
+ )