scripts/deploy: add the equivalent of my "pre-deploy" functionality

This commit is contained in:
2024-06-12 09:04:17 +00:00
parent 86482e922c
commit b5b39d1500

View File

@@ -8,8 +8,12 @@ usage() {
echo "" echo ""
echo "usage: deploy [options] [host]" echo "usage: deploy [options] [host]"
echo "options:" echo "options:"
echo "- --action switch|test" echo "- --action copy|switch|test (default: 'switch')"
echo "- --variant light|min" echo "- --variant light|min|''|all (default: '')"
echo "- --pre: alias for --action copy --variant all all"
echo ""
echo "common idioms:"
echo "deploy all: deploy all hosts, sequentially"
exit 1 exit 1
} }
@@ -40,6 +44,11 @@ parseArgs() {
(crappy|desko|lappy|moby|servo) (crappy|desko|lappy|moby|servo)
host="$arg" host="$arg"
;; ;;
(--pre)
action=copy
host=all
variant=all
;;
(*) (*)
nixArgs+=("$arg") nixArgs+=("$arg")
;; ;;
@@ -57,7 +66,10 @@ runOnTarget() {
fi fi
} }
parseArgs "$@" # deployOneHost $host $variant
deployOneHost() {
local host="$1"
local variant="$2"
nix-build -A "hosts.$host$variant" --out-link "./build/result-$host$variant" "${nixArgs[@]}" nix-build -A "hosts.$host$variant" --out-link "./build/result-$host$variant" "${nixArgs[@]}"
storePath="$(readlink ./build/result-$host$variant)" storePath="$(readlink ./build/result-$host$variant)"
@@ -83,7 +95,24 @@ if [ -n "$host" ]; then
nix copy -vv --option builders-use-substitutes false --to "ssh-ng://$host" "$storePath" nix copy -vv --option builders-use-substitutes false --to "ssh-ng://$host" "$storePath"
fi fi
if [ -n "$action" ]; then if [ -n "$action" ] && [ "$action" != "copy" ]; then
runOnTarget sudo nix-env -p /nix/var/nix/profiles/system --set "$storePath" runOnTarget sudo nix-env -p /nix/var/nix/profiles/system --set "$storePath"
runOnTarget sudo "$storePath/bin/switch-to-configuration" "$action" runOnTarget sudo "$storePath/bin/switch-to-configuration" "$action"
fi fi
}
parseArgs "$@"
if [ "$host" = "all" ]; then
for host in moby lappy crappy servo desko; do
if [ "$variant" = "all" ]; then
for variant in -min -light ""; do
deployOneHost "$host" "$variant"
done
else
deployOneHost "$host" "$variant"
fi
done
else
deployOneHost "$host" "variant"
fi