Skip to content

Commit 5255a31

Browse files
committed
Make node deploy support --dry-run and --ephemeral
1 parent b627bc8 commit 5255a31

2 files changed

Lines changed: 40 additions & 18 deletions

File tree

pkgs/nixverse/nixverse.sh

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,19 +287,21 @@ Deploy one or more nodes.
287287
288288
Options:
289289
-p, --parallel <num> number of nodes to deploy in parallel (default: 10)
290+
-n, --dry-run use {nixos,darwin}-rebuild build
291+
--ephemeral use nixos-rebuild test
290292
--reboot deploy with nixos-rebuild boot, then reboot
291293
-h, --help show this help
292294
EOF
293295
}
294296
cmd_node_deploy() {
295297
local args
296-
args=$(getopt -n nixverse -o 'hp:' --long 'help,parallel:,no-activate,no-boot,reboot' -- "$@")
298+
args=$(getopt -n nixverse -o 'hnp:' --long 'help,dry-run,parallel:,ephemeral,reboot' -- "$@")
297299
eval set -- "$args"
298300
unset args
299301

300302
local parallel=$default_parallel
301-
local activate=true
302-
local boot=true
303+
local dryRun=false
304+
local ephemeral=false
303305
local reboot=false
304306
while true; do
305307
case $1 in
@@ -311,12 +313,12 @@ cmd_node_deploy() {
311313
fi
312314
shift 2
313315
;;
314-
--no-activate)
315-
activate=false
316+
-n | --dry-run)
317+
dryRun=true
316318
shift
317319
;;
318-
--no-boot)
319-
boot=false
320+
--ephemeral)
321+
ephemeral=true
320322
shift
321323
;;
322324
--reboot)
@@ -338,6 +340,21 @@ cmd_node_deploy() {
338340
esac
339341
done
340342

343+
local deployModes=0
344+
if [[ $dryRun = true ]]; then
345+
deployModes=$((deployModes + 1))
346+
fi
347+
if [[ $ephemeral = true ]]; then
348+
deployModes=$((deployModes + 1))
349+
fi
350+
if [[ $reboot = true ]]; then
351+
deployModes=$((deployModes + 1))
352+
fi
353+
if ((deployModes > 1)); then
354+
echo >&2 "--dry-run, --ephemeral, and --reboot are mutually exclusive"
355+
return 1
356+
fi
357+
341358
if [[ $# = 0 ]]; then
342359
cmd help node deploy >&2
343360
return 1
@@ -380,8 +397,8 @@ in
380397
inherit nodeNames;
381398
userFlakeSourcePath = "$flake";
382399
nixversePath = "@out@";
383-
activate = $activate;
384-
boot = $boot;
400+
dryRun = $dryRun;
401+
ephemeral = $ephemeral;
385402
reboot = $reboot;
386403
}
387404
);

pkgs/nixverse/output.nix

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@
222222
nodeNames,
223223
userFlakeSourcePath,
224224
nixversePath,
225-
activate,
226-
boot,
225+
dryRun,
226+
ephemeral,
227227
reboot,
228228
}:
229229
let
@@ -247,16 +247,18 @@
247247
sshOpts = map (opt: "-o ${lib.escapeShellArg opt}") node.deploy.sshOpts;
248248
common = "--flake '${userFlakePath}#${nodeName}' --show-trace";
249249
rebuildAction =
250-
if reboot then
250+
if dryRun then
251+
"build"
252+
else if ephemeral then
253+
"test"
254+
else if reboot then
251255
"boot"
252-
else if activate then
253-
if boot then "switch" else "test"
254256
else
255-
"build";
257+
"switch";
256258
rebuild =
257259
{
258260
nixos = "NIX_SSHOPTS=${lib.escapeShellArg sshOpts} nixos-rebuild ${rebuildAction} ${targetHost} ${buildHost} ${useSubstitutes} ${useRemoteSudo} ${common}";
259-
darwin = "sudo darwin-rebuild ${if activate then "switch" else "build"} ${common}";
261+
darwin = "sudo darwin-rebuild ${if dryRun then "build" else "switch"} ${common}";
260262
}
261263
.${node.os};
262264
rebootCommand =
@@ -266,8 +268,11 @@
266268
"reboot";
267269
in
268270
assert lib.assertMsg (
269-
!reboot || node.os == "nixos"
270-
) "--reboot is only supported for NixOS node ${nodeName}";
271+
reboot -> node.os == "nixos"
272+
) "--reboot is only supported for a NixOS node, which ${nodeName} is not";
273+
assert lib.assertMsg (
274+
ephemeral -> node.os == "nixos"
275+
) "--ephemeral is only supported for a NixOS node, which ${nodeName} is not";
271276
{
272277
name = nodeName;
273278
command = lib.concatLines (

0 commit comments

Comments
 (0)