Skip to content

Commit 853dede

Browse files
committed
Rename sshKeyDir to tempDir to better reflect its usage
The variable is now used for multiple purposes beyond just SSH keys: - SSH key storage - Temporary home directory for ssh-copy-id - Environment SSH key storage The new name tempDir more accurately describes its role as a general-purpose temporary working directory.
1 parent 0515f8d commit 853dede

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/nixos-anywhere.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ hasCurl=
5858
hasSetsid=
5959
hasNixOSFacter=
6060

61-
sshKeyDir=$(mktemp -d)
62-
trap 'rm -rf "$sshKeyDir"' EXIT
63-
mkdir -p "$sshKeyDir"
61+
tempDir=$(mktemp -d)
62+
trap 'rm -rf "$tempDir"' EXIT
63+
mkdir -p "$tempDir"
6464

6565
declare -A diskEncryptionKeys=()
6666
declare -A extraFilesOwnership=()
6767
declare -a nixCopyOptions=()
68-
declare -a sshArgs=("-o" "IdentitiesOnly=yes" "-i" "$sshKeyDir/nixos-anywhere" "-o" "UserKnownHostsFile=/dev/null" "-o" "StrictHostKeyChecking=no")
68+
declare -a sshArgs=("-o" "IdentitiesOnly=yes" "-i" "$tempDir/nixos-anywhere" "-o" "UserKnownHostsFile=/dev/null" "-o" "StrictHostKeyChecking=no")
6969

7070
showUsage() {
7171
cat <<USAGE
@@ -467,18 +467,18 @@ uploadSshKey() {
467467
# ssh-copy-id requires this directory
468468
local sshCopyHome="$HOME"
469469
if ! mkdir -p "$HOME/.ssh/" 2>/dev/null; then
470-
# Fallback: create a temporary home directory for ssh-copy-id in sshKeyDir
471-
sshCopyHome="$sshKeyDir/ssh-home"
470+
# Fallback: create a temporary home directory for ssh-copy-id in tempDir
471+
sshCopyHome="$tempDir/ssh-home"
472472
mkdir -p "$sshCopyHome/.ssh"
473473
echo "Warning: Could not create $HOME/.ssh, using temporary directory: $sshCopyHome"
474474
fi
475-
475+
476476
if [[ -n ${sshPrivateKeyFile} ]]; then
477-
cp "$sshPrivateKeyFile" "$sshKeyDir/nixos-anywhere"
478-
ssh-keygen -y -f "$sshKeyDir/nixos-anywhere" >"$sshKeyDir/nixos-anywhere.pub"
477+
cp "$sshPrivateKeyFile" "$tempDir/nixos-anywhere"
478+
ssh-keygen -y -f "$tempDir/nixos-anywhere" >"$tempDir/nixos-anywhere.pub"
479479
else
480480
# we generate a temporary ssh keypair that we can use during nixos-anywhere
481-
ssh-keygen -t ed25519 -f "$sshKeyDir"/nixos-anywhere -P "" -C "nixos-anywhere" >/dev/null
481+
ssh-keygen -t ed25519 -f "$tempDir"/nixos-anywhere -P "" -C "nixos-anywhere" >/dev/null
482482
fi
483483

484484
step Uploading install SSH keys
@@ -709,7 +709,7 @@ runDisko() {
709709
# If we don't use ssh-ng here, we get `error: operation 'getFSAccessor' is not supported by store`
710710
diskoScript=$(
711711
nixBuild "${flake}#${flakeAttr}.system.build.${diskoAttr}" \
712-
--eval-store auto --store "ssh-ng://$sshConnection?ssh-key=$sshKeyDir%2Fnixos-anywhere&$sshStoreSettings"
712+
--eval-store auto --store "ssh-ng://$sshConnection?ssh-key=$tempDir%2Fnixos-anywhere&$sshStoreSettings"
713713
)
714714
fi
715715
@@ -731,7 +731,7 @@ nixosInstall() {
731731
# If we don't use ssh-ng here, we get `error: operation 'getFSAccessor' is not supported by store`
732732
nixosSystem=$(
733733
nixBuild "${flake}#${flakeAttr}.system.build.toplevel" \
734-
--eval-store auto --store "ssh-ng://$sshConnection?ssh-key=$sshKeyDir%2Fnixos-anywhere&remote-store=local%3Froot=%2Fmnt&$sshStoreSettings"
734+
--eval-store auto --store "ssh-ng://$sshConnection?ssh-key=$tempDir%2Fnixos-anywhere&remote-store=local%3Froot=%2Fmnt&$sshStoreSettings"
735735
)
736736
fi
737737
@@ -830,8 +830,8 @@ main() {
830830
fi
831831
832832
if [[ -n ${SSH_PRIVATE_KEY} ]] && [[ -z ${sshPrivateKeyFile} ]]; then
833-
# $sshKeyDir is getting deleted on trap EXIT
834-
sshPrivateKeyFile="$sshKeyDir/from-env"
833+
# $tempDir is getting deleted on trap EXIT
834+
sshPrivateKeyFile="$tempDir/from-env"
835835
(
836836
umask 077
837837
printf '%s\n' "$SSH_PRIVATE_KEY" >"$sshPrivateKeyFile"

0 commit comments

Comments
 (0)