scripts/deploy: add --build flag

useful as e.g. deploy --pre --build, to only *build* all variants/hosts, but don't actually copy
This commit is contained in:
2025-03-16 07:01:15 +00:00
parent ca6c6f7b57
commit 2544bb4d68

View File

@@ -8,6 +8,7 @@ usage() {
echo "" echo ""
echo "usage: deploy [options] [host] [host2 ...]" echo "usage: deploy [options] [host] [host2 ...]"
echo "options:" echo "options:"
echo "- --build: only build; don't copy or deploy"
echo "- --copy: only build + copy files, nothing more" echo "- --copy: only build + copy files, nothing more"
echo "- --switch (default)" echo "- --switch (default)"
echo "- --test: switch to the new configuration, but do not make it bootable" echo "- --test: switch to the new configuration, but do not make it bootable"
@@ -68,7 +69,7 @@ parseArgs() {
local arg=$1 local arg=$1
shift shift
case "$arg" in case "$arg" in
(--copy|--switch|--test) (--build|--copy|--switch|--test)
action=${arg/--/} action=${arg/--/}
;; ;;
(--deriv) (--deriv)
@@ -221,30 +222,36 @@ deployOneHost() {
local netHost=$(resolveHost "$host") local netHost=$(resolveHost "$host")
if [ -n "$host" ] && [ "$host" != "$SELF" ]; then case "$action" in
if [ -e /run/secrets/nix_signing_key ]; then (copy|switch|test)
info "signing store paths ..." if [ -n "$host" ] && [ "$host" != "$SELF" ]; then
destructive sudo nix store sign -r -k /run/secrets/nix_signing_key "$myStorePath" if [ -e /run/secrets/nix_signing_key ]; then
else info "signing store paths ..."
info "not signing store paths: /run/secrets/nix_signing_key does not exist" destructive sudo nix store sign -r -k /run/secrets/nix_signing_key "$myStorePath"
fi else
# add more `-v` for more verbosity (up to 5). info "not signing store paths: /run/secrets/nix_signing_key does not exist"
# builders-use-substitutes false: optimizes so that the remote machine doesn't try to get paths from its substituters. fi
# we already have all paths here, and the remote substitution is slow to check and SERIOUSLY flaky on moby in particular. # add more `-v` for more verbosity (up to 5).
ECHO_CMD=1 destructive timeout "$timeout" nix copy -vv --option builders-use-substitutes false --to "ssh-ng://$netHost" "$myStorePath" || return 1 # builders-use-substitutes false: optimizes so that the remote machine doesn't try to get paths from its substituters.
fi # we already have all paths here, and the remote substitution is slow to check and SERIOUSLY flaky on moby in particular.
ECHO_CMD=1 destructive timeout "$timeout" nix copy -vv --option builders-use-substitutes false --to "ssh-ng://$netHost" "$myStorePath" || return 1
fi
;;
esac
if [ -n "$action" ] && [ "$action" != "copy" ]; then case "$action" in
info "activating profile... " (switch|test)
destructive runOnTarget "$netHost" sudo nix-env -p /nix/var/nix/profiles/system --set "$myStorePath" || return 1 info "activating profile... "
destructive runOnTarget "$netHost" sudo "$myStorePath/bin/switch-to-configuration" "$action" destructive runOnTarget "$netHost" sudo nix-env -p /nix/var/nix/profiles/system --set "$myStorePath" || return 1
local rc=$? destructive runOnTarget "$netHost" sudo "$myStorePath/bin/switch-to-configuration" "$action"
if [[ -n "$doReboot" && ("$rc" -eq 0 || -n "$doRebootForce") ]]; then local rc=$?
info "rebooting $host" if [[ -n "$doReboot" && ("$rc" -eq 0 || -n "$doRebootForce") ]]; then
destructive runOnTarget "$netHost" sane-reboot "$host" || return 1 info "rebooting $host"
fi destructive runOnTarget "$netHost" sane-reboot "$host" || return 1
return $rc fi
fi return $rc
;;
esac
} }
failedDeploys=() failedDeploys=()