@@ -7,8 +7,10 @@ Usage: nixos-anywhere [options] ssh-host
77
88Options:
99
10- * -f, --flake flake
11- set the flake to install the system from
10+ * -f, --flake <flake_uri>
11+ set the flake to install the system from.
12+ * -i <identity_file>
13+ selects which SSH private key file to use.
1214* -L, --print-build-logs
1315 print full build logs
1416* -s, --store-paths
@@ -56,6 +58,7 @@ nix_options=(
5658 " --no-write-lock-file"
5759)
5860substitute_on_destination=y
61+ ssh_private_key_file=
5962
6063declare -A disk_encryption_keys
6164declare -a nix_copy_options
@@ -67,6 +70,10 @@ while [[ $# -gt 0 ]]; do
6770 flake=$2
6871 shift
6972 ;;
73+ -i)
74+ ssh_private_key_file=$2
75+ shift
76+ ;;
7077 -L | --print-build-logs)
7178 print_build_logs=y
7279 ;;
@@ -198,15 +205,19 @@ else
198205 abort " flake must be set"
199206fi
200207
208+ # overrides -i if passed as an env var
201209if [[ -n ${SSH_PRIVATE_KEY-} ]]; then
202- sshPrivateKeyFile= $( mktemp )
203- trap ' rm "$sshPrivateKeyFile" ' EXIT
210+ # $ssh_key_dir is getting deleted on trap EXIT
211+ ssh_private_key_file= " $ssh_key_dir /from-env "
204212 (
205213 umask 077
206- printf ' %s\n' " $SSH_PRIVATE_KEY " > " $sshPrivateKeyFile "
214+ printf ' %s\n' " $SSH_PRIVATE_KEY " > " $ssh_private_key_file "
207215 )
216+ fi
217+
218+ if [[ -n ${ssh_private_key_file-} ]]; then
208219 unset SSH_AUTH_SOCK # don't use system agent if key was supplied
209- ssh_copy_id_args+=(-o " IdentityFile=${sshPrivateKeyFile } " )
220+ ssh_copy_id_args+=(-o " IdentityFile=${ssh_private_key_file } " )
210221 ssh_copy_id_args+=(-f)
211222fi
212223
0 commit comments