scripts/deploy: allow --deriv to be either a .drv or a store path

This commit is contained in:
2025-03-20 03:39:44 +00:00
parent 5133664603
commit 29415aa88a

View File

@@ -19,7 +19,7 @@ usage() {
echo "- --variant light|min|''|all (default: '')"
echo "- --wireguard always|never|opportunistic: deploy over wireguard"
echo "- --ip <address>: deploy to the specific IP address"
echo "- --deriv /nix/store/...: prebuilt store path to deploy instead of (re-)building the default target"
echo "- --deriv /nix/store/...: prebuilt store path (or .drv to realize) to deploy instead of (re-)building the default target"
echo ""
echo "common idioms:"
echo "- deploy all: deploy all hosts, sequentially"
@@ -197,14 +197,19 @@ deployOneHost() {
local timeout=$(timeoutFor "$variant")
# storePath is allowed to be either a realized derivation,
# or the path to a .drv file itself
local myStorePath="$storePath"
if [ -z "$myStorePath" ]; then
# `nix-build -A foo` evals and then realizes foo, but it never unloads the memory used to eval foo.
# my exprs are heavyweight, we need that memory for building, so do the evals separately from the realizations:
info "evaluating $host$variant..."
local drvPath=$(nix eval --raw -f . "hosts.$host$variant.toplevel.drvPath")
myStorePath=$(nix eval --raw -f . "hosts.$host$variant.toplevel.drvPath")
fi
if [[ "$myStorePath" == *.drv ]]; then
info "building $host$variant ($drvPath)"
myStorePath=$(destructive nix-store --realize "$drvPath" "${nixArgs[@]}")
myStorePath=$(destructive nix-store --realize "$myStorePath" "${nixArgs[@]}")
if [ -z "$myStorePath" ]; then
return 1
fi