Skip to content

Commit 454ad62

Browse files
committed
fix: make runSshNoTty fallible for system_features and escape bash variables
1 parent c5ba1f1 commit 454ad62

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/nixos-anywhere.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,9 @@ SSH
10501050
10511051
# Get system-features with a specific cpu architecture from the machine and add them to the installer
10521052
if [[ -n ${flake} ]]; then
1053-
system_features=$(runSshNoTty -o ConnectTimeout=10 nix --extra-experimental-features 'nix-command' config show system-features 2>/dev/null || true)
1054-
1053+
system_features=$(runSshNoTty -o ConnectTimeout=10 nix --extra-experimental-features 'nix-command' config show system-features)
1054+
# Escape the bash variable for safe interpolation into Nix
1055+
system_features="$(printf '%s' "$system_features" | sed 's/\\/\\\\/g; s/"/\\"/g')"
10551056
# First, try to evaluate all nix settings from the flake in one go
10561057
nixConfContent=$(nix --extra-experimental-features 'nix-command flakes' eval --raw --apply "
10571058
config:
@@ -1067,7 +1068,7 @@ SSH
10671068
remoteFeaturesStr = \"${system_features}\";
10681069
# Parse remote features string (space-separated) into list
10691070
remoteFeaturesList = if remoteFeaturesStr != \"\" then
1070-
builtins.filter (x: x != \"\") (builtins.split \" +\" remoteFeaturesStr)
1071+
builtins.filter (x: builtins.isString x && x != \"\") (builtins.split \" +\" remoteFeaturesStr)
10711072
else [];
10721073
in remoteFeaturesList;
10731074
@@ -1096,7 +1097,10 @@ SSH
10961097
if [[ -n ${nixConfContent} ]]; then
10971098
runSsh sh <<SSH
10981099
mkdir -p ~/.config/nix
1099-
echo "${nixConfContent}" >> ~/.config/nix/nix.conf
1100+
printf '%s\n' "\$(cat <<'CONTENT'
1101+
${nixConfContent}
1102+
CONTENT
1103+
)" >> ~/.config/nix/nix.conf
11001104
SSH
11011105
fi
11021106
fi

0 commit comments

Comments
 (0)