diff --git a/deploy_nixos/nixos-deploy.sh b/deploy_nixos/nixos-deploy.sh index 319651b..919d1f3 100755 --- a/deploy_nixos/nixos-deploy.sh +++ b/deploy_nixos/nixos-deploy.sh @@ -58,10 +58,21 @@ log() { echo "--- $*" >&2 } +# Use nix-copy-closure to copy some things to the target host. +# nix-copy-closure avoids copying store objects that are already on the target +# host. It performs well when copying large objects. copyToTarget() { NIX_SSHOPTS="${sshOpts[*]}" nix-copy-closure --to "$targetHost" "$@" } +# Use nix-store --export/--import via ssh to copy some things to the target +# host. This removes a lot of round-trips compared to copyToTarget which is +# beneficial when copying many small store objects - such as .drv files. +exportToTarget() { + nix-store --export $(nix-store --query --requisites "$1") | + ssh -o Compression=yes "${sshOpts[@]}" "$targetHost" 'nix-store --import' +} + # assumes that passwordless sudo is enabled on the server targetHostCmd() { # ${*@Q} escapes the arguments losslessly into space-separted quoted strings. @@ -101,7 +112,9 @@ if [[ "${buildOnTarget:-false}" == true ]]; then # Upload derivation log "uploading derivations" - copyToTarget "$drvPath" --gzip --use-substitutes + # Since derivations are small and there are likely many, use exportToTarget + # which should be faster than copyToTarget most of the time. + exportToTarget "$drvPath" # Build remotely log "building on target" @@ -116,6 +129,9 @@ else # Upload build results log "uploading build results" + # Since we are copying build outputs they are probably not all very small + # objects so use copyToTarget which might be able to avoid copying some of + # them. copyToTarget "$outPath" --gzip --use-substitutes fi