Skip to content

Commit 926b58a

Browse files
committed
fix: make runSshNoTty fallible for system_features and escape bash variables
1 parent e174e75 commit 926b58a

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
@@ -1037,8 +1037,9 @@ main() {
10371037
fi
10381038
10391039
if [[ -n ${flake} ]]; then
1040-
system_features=$(runSshNoTty -o ConnectTimeout=10 nix --extra-experimental-features 'nix-command' config show system-features 2>/dev/null || true)
1041-
1040+
system_features=$(runSshNoTty -o ConnectTimeout=10 nix --extra-experimental-features 'nix-command' config show system-features)
1041+
# Escape the bash variable for safe interpolation into Nix
1042+
system_features="$(printf '%s' "$system_features" | sed 's/\\/\\\\/g; s/"/\\"/g')"
10421043
# First, try to evaluate all nix settings from the flake in one go
10431044
nixConfContent=$(nix --extra-experimental-features 'nix-command flakes' eval --raw --apply "
10441045
config:
@@ -1054,7 +1055,7 @@ main() {
10541055
remoteFeaturesStr = \"${system_features}\";
10551056
# Parse remote features string (space-separated) into list
10561057
remoteFeaturesList = if remoteFeaturesStr != \"\" then
1057-
builtins.filter (x: x != \"\") (builtins.split \" +\" remoteFeaturesStr)
1058+
builtins.filter (x: builtins.isString x && x != \"\") (builtins.split \" +\" remoteFeaturesStr)
10581059
else [];
10591060
in remoteFeaturesList;
10601061
@@ -1083,7 +1084,10 @@ main() {
10831084
if [[ -n ${nixConfContent} ]]; then
10841085
runSsh sh <<SSH
10851086
mkdir -p ~/.config/nix
1086-
echo "${nixConfContent}" >> ~/.config/nix/nix.conf
1087+
printf '%s\n' "\$(cat <<'CONTENT'
1088+
${nixConfContent}
1089+
CONTENT
1090+
)" >> ~/.config/nix/nix.conf
10871091
SSH
10881092
fi
10891093
fi

0 commit comments

Comments
 (0)