2023-01-29 17:44:23 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
2023-05-15 18:55:49 +02:00
|
|
|
# Copies a NixOS system to a target host, using the provided key,
|
|
|
|
# or whatever ambient key is configured if the key is not set.
|
2023-01-29 17:44:23 +01:00
|
|
|
set -ueo pipefail
|
|
|
|
|
|
|
|
export NIX_SSHOPTS="\
|
|
|
|
-o StrictHostKeyChecking=no\
|
|
|
|
-o UserKnownHostsFile=/dev/null\
|
2023-05-15 18:55:49 +02:00
|
|
|
-o GlobalKnownHostsFile=/dev/null"
|
|
|
|
|
|
|
|
# If DEPLOY_KEY was passed, write it to $scratch/id_deploy
|
|
|
|
if [ -n "${DEPLOY_KEY-}" ]; then
|
|
|
|
scratch="$(mktemp -d)"
|
|
|
|
trap 'rm -rf -- "${scratch}"' EXIT
|
|
|
|
|
|
|
|
echo -n "$DEPLOY_KEY" > $scratch/id_deploy
|
|
|
|
chmod 0600 $scratch/id_deploy
|
|
|
|
export NIX_SSHOPTS="$NIX_SSHOPTS -o IdentityFile=$scratch/id_deploy"
|
|
|
|
fi
|
2023-01-29 17:44:23 +01:00
|
|
|
|
|
|
|
nix-copy-closure \
|
2023-03-08 17:31:02 +01:00
|
|
|
--to ${TARGET_USER}@${TARGET_HOST} \
|
2023-01-29 17:44:23 +01:00
|
|
|
${SYSTEM_DRV} \
|
|
|
|
--gzip \
|
|
|
|
--include-outputs \
|
|
|
|
--use-substitutes
|