From 4fc8d2e15b5c4915b7b8cc0f141fe227a1a5fd4c Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Thu, 9 Dec 2021 15:39:33 -0500 Subject: [PATCH 1/2] nix-store --export/--import instead of nix-copy-closure --- deploy_nixos/nixos-deploy.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/deploy_nixos/nixos-deploy.sh b/deploy_nixos/nixos-deploy.sh index 319651b..f699610 100755 --- a/deploy_nixos/nixos-deploy.sh +++ b/deploy_nixos/nixos-deploy.sh @@ -62,6 +62,16 @@ copyToTarget() { NIX_SSHOPTS="${sshOpts[*]}" nix-copy-closure --to "$targetHost" "$@" } +exportToTarget() { + nix-store --export $(nix-store --query --requisites "$1") | + lzma --compress | + pv | + ssh "${sshOpts[@]}" "$targetHost" ' + lzma --decompress | + 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 +111,8 @@ if [[ "${buildOnTarget:-false}" == true ]]; then # Upload derivation log "uploading derivations" - copyToTarget "$drvPath" --gzip --use-substitutes + # copyToTarget "$drvPath" --gzip --use-substitutes + exportToTarget "$drvPath" # Build remotely log "building on target" From 992c8620b3c5d29bfa80abc769ba64405ff83012 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Fri, 10 Dec 2021 08:46:37 -0500 Subject: [PATCH 2/2] just use ssh compression for simplicity also add some comments --- deploy_nixos/nixos-deploy.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/deploy_nixos/nixos-deploy.sh b/deploy_nixos/nixos-deploy.sh index f699610..919d1f3 100755 --- a/deploy_nixos/nixos-deploy.sh +++ b/deploy_nixos/nixos-deploy.sh @@ -58,18 +58,19 @@ 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") | - lzma --compress | - pv | - ssh "${sshOpts[@]}" "$targetHost" ' - lzma --decompress | - nix-store --import - ' + ssh -o Compression=yes "${sshOpts[@]}" "$targetHost" 'nix-store --import' } # assumes that passwordless sudo is enabled on the server @@ -111,7 +112,8 @@ 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 @@ -127,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