Skip to content

Instantly share code, notes, and snippets.

@grahamc
Created December 26, 2017 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahamc/aed128bbb5450c29fc6a29b793eb0886 to your computer and use it in GitHub Desktop.
Save grahamc/aed128bbb5450c29fc6a29b793eb0886 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -eu
set -o pipefail
buildHost=root@yourremotebuilder
tmpDir=$(mktemp -t -d nixos-rebuild.XXXXXX)
SSHOPTS="${NIX_SSHOPTS:-} -o ControlMaster=auto -o ControlPath=$tmpDir/ssh-%n -o ControlPersist=60"
cleanup() {
for ctrl in "$tmpDir"/ssh-*; do
ssh -o ControlPath="$ctrl" -O exit dummyhost 2>/dev/null || true
done
rm -rf "$tmpDir"
}
trap cleanup EXIT
set -eux
drv=$(nix-instantiate ./your-thing-to-build.nix -A foobar)
NIX_SSHOPTS=$SSHOPTS nix-copy-closure --to "$buildHost" "$drv"
out=$(ssh $SSHOPTS "$buildHost" "NIX_REMOTE=daemon nix-store -r '$drv' -j 5")
nix-copy-closure --from "$buildHost" "$out"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment