-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Commit
The set/env fix in #14907 wasn't very good, so let's use a null-delimited approach. Suggested by Aszlig. In particular, this should fix a mass-breakage on Darwin, though I was unable to test that.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,7 +409,7 @@ substitute() { | |
if [ "$p" = --subst-var ]; then | ||
varName="${params[$((n + 1))]}" | ||
# check if the used nix attribute name is a valid bash name | ||
if ! [[ "$varName" =~ ^[a-zA-Z_]+[a-zA-Z0-9_]*$ ]]; then | ||
if ! [[ "$varName" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then | ||
echo "substitution variables must be valid bash names, \"$varName\" isn't." | ||
exit 1; | ||
fi | ||
|
@@ -439,20 +439,23 @@ substituteInPlace() { | |
} | ||
|
||
|
||
# Substitute all environment variables that do not start with an upper-case | ||
# character or underscore. Note: other names that aren't bash-valid | ||
# will cause an error during `substitute --subst-var`. | ||
substituteAll() { | ||
local input="$1" | ||
local output="$2" | ||
local -a args=() | ||
|
||
# Select all environment variables that start with a lowercase character. | ||
# Will not work with nix attribute names (and thus env variables) containing '\n'. | ||
for envVar in $(set | sed -e $'s/^\([a-z][^=]*\)=.*/\\1/; t \n d'); do | ||
# We need to be careful due to vars with multi-line contents or weird names. | ||
while IFS= read -r -d '' varName; do | ||
if [ "$NIX_DEBUG" = "1" ]; then | ||
echo "$envVar -> ${!envVar}" | ||
echo "@varName@ -> '${varName}'" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
vcunat
Author
Member
|
||
fi | ||
args="$args --subst-var $envVar" | ||
done | ||
args+=("--subst-var" "$varName") | ||
done < <(env -0 | cut -z -d= -f1 | grep -z -v '^[_A-Z]') | ||
This comment has been minimized.
Sorry, something went wrong.
abbradar
Member
|
||
|
||
substitute "$input" "$output" $args | ||
substitute "$input" "$output" "${args[@]}" | ||
} | ||
|
||
|
||
|
If I understand correctly, this would yield fairly useless output: first
@varName@
is literally a string "varName`.