Skip to content

Commit 7cff10e

Browse files
Mic92mergify[bot]
authored andcommitted
ssh keys provided via cli override env variables
this is more intuitive.
1 parent 7125e73 commit 7cff10e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/nixos-anywhere.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ nixOptions=(
7575
--extra-experimental-features 'nix-command flakes'
7676
"--no-write-lock-file"
7777
)
78+
SSH_PRIVATE_KEY=${SSH_PRIVATE_KEY-}
7879

7980
declare -A phases
8081
phases[kexec]=1
@@ -319,8 +320,7 @@ else
319320
abort "flake must be set"
320321
fi
321322

322-
# overrides -i if passed as an env var
323-
if [[ -n ${SSH_PRIVATE_KEY-} ]]; then
323+
if [[ -n ${SSH_PRIVATE_KEY} ]] && [[ -z ${sshPrivateKeyFile-} ]]; then
324324
# $ssh_key_dir is getting deleted on trap EXIT
325325
sshPrivateKeyFile="$ssh_key_dir/from-env"
326326
(
@@ -329,10 +329,9 @@ if [[ -n ${SSH_PRIVATE_KEY-} ]]; then
329329
)
330330
fi
331331

332-
if [[ -n ${sshPrivateKeyFile-} ]]; then
332+
if [[ -n ${sshPrivateKeyFile} ]]; then
333333
unset SSH_AUTH_SOCK # don't use system agent if key was supplied
334-
sshCopyIdArgs+=(-o "IdentityFile=${sshPrivateKeyFile}")
335-
sshCopyIdArgs+=(-f)
334+
sshCopyIdArgs+=(-o "IdentityFile=${sshPrivateKeyFile}" -f)
336335
fi
337336

338337
sshSettings=$(ssh "${sshArgs[@]}" -G "${sshConnection}")

0 commit comments

Comments
 (0)