Skip to content

Commit 9eab3c1

Browse files
committed
nixos-anywhere: refactor default SSH arguments to sshArgs variable
1 parent 1e2882c commit 9eab3c1

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/nixos-anywhere.sh

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ mkdir -p "$sshKeyDir"
6565
declare -A diskEncryptionKeys=()
6666
declare -A extraFilesOwnership=()
6767
declare -a nixCopyOptions=()
68-
declare -a sshArgs=()
68+
declare -a sshArgs=("-i" "$sshKeyDir/nixos-anywhere" "-o" "UserKnownHostsFile=/dev/null" "-o" "StrictHostKeyChecking=no")
6969

7070
showUsage() {
7171
cat <<USAGE
@@ -407,23 +407,27 @@ parseArgs() {
407407

408408
# ssh wrapper
409409
runSshNoTty() {
410-
ssh -i "$sshKeyDir"/nixos-anywhere -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${sshArgs[@]}" "$sshConnection" "$@"
410+
# shellcheck disable=SC2029
411+
# We want to expand "$@" to get the command to run over SSH
412+
ssh "${sshArgs[@]}" "$sshConnection" "$@"
411413
}
412414
runSshTimeout() {
413-
timeout 10 ssh -i "$sshKeyDir"/nixos-anywhere -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${sshArgs[@]}" "$sshConnection" "$@"
415+
timeout 10 ssh "${sshArgs[@]}" "$sshConnection" "$@"
414416
}
415417
runSsh() {
416-
ssh "$sshTtyParam" -i "$sshKeyDir"/nixos-anywhere -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${sshArgs[@]}" "$sshConnection" "$@"
418+
# shellcheck disable=SC2029
419+
# We want to expand "$@" to get the command to run over SSH
420+
ssh "$sshTtyParam" "${sshArgs[@]}" "$sshConnection" "$@"
417421
}
418422

419423
nixCopy() {
420-
NIX_SSHOPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $sshKeyDir/nixos-anywhere ${sshArgs[*]}" nix copy \
424+
NIX_SSHOPTS="${sshArgs[*]}" nix copy \
421425
"${nixOptions[@]}" \
422426
"${nixCopyOptions[@]}" \
423427
"$@"
424428
}
425429
nixBuild() {
426-
NIX_SSHOPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $sshKeyDir/nixos-anywhere ${sshArgs[*]}" nix build \
430+
NIX_SSHOPTS="${sshArgs[*]}" nix build \
427431
--print-out-paths \
428432
--no-link \
429433
"${nixBuildFlags[@]}" \
@@ -481,20 +485,14 @@ uploadSshKey() {
481485
if [[ ${envPassword} == y ]]; then
482486
sshpass -e \
483487
ssh-copy-id \
484-
-i "$sshKeyDir"/nixos-anywhere.pub \
485488
-o ConnectTimeout=10 \
486-
-o UserKnownHostsFile=/dev/null \
487489
-o IdentitiesOnly=yes \
488-
-o StrictHostKeyChecking=no \
489490
"${sshCopyIdArgs[@]}" \
490491
"${sshArgs[@]}" \
491492
"$sshConnection"
492493
else
493494
ssh-copy-id \
494-
-i "$sshKeyDir"/nixos-anywhere.pub \
495495
-o ConnectTimeout=10 \
496-
-o UserKnownHostsFile=/dev/null \
497-
-o StrictHostKeyChecking=no \
498496
"${sshCopyIdArgs[@]}" \
499497
"${sshArgs[@]}" \
500498
"$sshConnection"

0 commit comments

Comments
 (0)