scripts/deploy: add the equivalent of my "pre-deploy" functionality
This commit is contained in:
@@ -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,33 +66,53 @@ runOnTarget() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# deployOneHost $host $variant
|
||||||
|
deployOneHost() {
|
||||||
|
local host="$1"
|
||||||
|
local variant="$2"
|
||||||
|
|
||||||
|
nix-build -A "hosts.$host$variant" --out-link "./build/result-$host$variant" "${nixArgs[@]}"
|
||||||
|
storePath="$(readlink ./build/result-$host$variant)"
|
||||||
|
|
||||||
|
# mimic `nixos-rebuild --target-host`, in effect:
|
||||||
|
# - nix-copy-closure ...
|
||||||
|
# - nix-env --set ...
|
||||||
|
# - switch-to-configuration <boot|dry-activate|switch|test|>
|
||||||
|
# avoid the actual `nixos-rebuild` for a few reasons:
|
||||||
|
# - fewer nix evals
|
||||||
|
# - more introspectability and debuggability
|
||||||
|
# - sandbox friendliness (especially: `git` doesn't have to be run as root)
|
||||||
|
|
||||||
|
if [ -n "$host" ]; then
|
||||||
|
if [ -e /run/secrets/nix_signing_key ]; then
|
||||||
|
sudo nix store sign -r -k /run/secrets/nix_signing_key "$storePath"
|
||||||
|
else
|
||||||
|
echo "not signing store paths: /run/secrets/nix_signing_key does not exist"
|
||||||
|
fi
|
||||||
|
# add more `-v` for more verbosity (up to 5).
|
||||||
|
# builders-use-substitutes false: optimizes so that the remote machine doesn't try to get paths from its substituters.
|
||||||
|
# we already have all paths here, and the remote substitution is slow to check and SERIOUSLY flaky on moby in particular.
|
||||||
|
nix copy -vv --option builders-use-substitutes false --to "ssh-ng://$host" "$storePath"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$action" ] && [ "$action" != "copy" ]; then
|
||||||
|
runOnTarget sudo nix-env -p /nix/var/nix/profiles/system --set "$storePath"
|
||||||
|
runOnTarget sudo "$storePath/bin/switch-to-configuration" "$action"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
parseArgs "$@"
|
parseArgs "$@"
|
||||||
|
|
||||||
nix-build -A "hosts.$host$variant" --out-link "./build/result-$host$variant" "${nixArgs[@]}"
|
if [ "$host" = "all" ]; then
|
||||||
storePath="$(readlink ./build/result-$host$variant)"
|
for host in moby lappy crappy servo desko; do
|
||||||
|
if [ "$variant" = "all" ]; then
|
||||||
# mimic `nixos-rebuild --target-host`, in effect:
|
for variant in -min -light ""; do
|
||||||
# - nix-copy-closure ...
|
deployOneHost "$host" "$variant"
|
||||||
# - nix-env --set ...
|
done
|
||||||
# - switch-to-configuration <boot|dry-activate|switch|test|>
|
else
|
||||||
# avoid the actual `nixos-rebuild` for a few reasons:
|
deployOneHost "$host" "$variant"
|
||||||
# - fewer nix evals
|
fi
|
||||||
# - more introspectability and debuggability
|
done
|
||||||
# - sandbox friendliness (especially: `git` doesn't have to be run as root)
|
else
|
||||||
|
deployOneHost "$host" "variant"
|
||||||
if [ -n "$host" ]; then
|
|
||||||
if [ -e /run/secrets/nix_signing_key ]; then
|
|
||||||
sudo nix store sign -r -k /run/secrets/nix_signing_key "$storePath"
|
|
||||||
else
|
|
||||||
echo "not signing store paths: /run/secrets/nix_signing_key does not exist"
|
|
||||||
fi
|
|
||||||
# add more `-v` for more verbosity (up to 5).
|
|
||||||
# builders-use-substitutes false: optimizes so that the remote machine doesn't try to get paths from its substituters.
|
|
||||||
# we already have all paths here, and the remote substitution is slow to check and SERIOUSLY flaky on moby in particular.
|
|
||||||
nix copy -vv --option builders-use-substitutes false --to "ssh-ng://$host" "$storePath"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$action" ]; then
|
|
||||||
runOnTarget sudo nix-env -p /nix/var/nix/profiles/system --set "$storePath"
|
|
||||||
runOnTarget sudo "$storePath/bin/switch-to-configuration" "$action"
|
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user