stdenv substituteAll: use more robust code
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.
This commit is contained in:
parent
717670720f
commit
9e0d0423fe
@ -409,7 +409,7 @@ substitute() {
|
|||||||
if [ "$p" = --subst-var ]; then
|
if [ "$p" = --subst-var ]; then
|
||||||
varName="${params[$((n + 1))]}"
|
varName="${params[$((n + 1))]}"
|
||||||
# check if the used nix attribute name is a valid bash name
|
# 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."
|
echo "substitution variables must be valid bash names, \"$varName\" isn't."
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
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() {
|
substituteAll() {
|
||||||
local input="$1"
|
local input="$1"
|
||||||
local output="$2"
|
local output="$2"
|
||||||
|
local -a args=()
|
||||||
|
|
||||||
# Select all environment variables that start with a lowercase character.
|
# We need to be careful due to vars with multi-line contents or weird names.
|
||||||
# Will not work with nix attribute names (and thus env variables) containing '\n'.
|
while IFS= read -r -d '' varName; do
|
||||||
for envVar in $(set | sed -e $'s/^\([a-z][^=]*\)=.*/\\1/; t \n d'); do
|
|
||||||
if [ "$NIX_DEBUG" = "1" ]; then
|
if [ "$NIX_DEBUG" = "1" ]; then
|
||||||
echo "$envVar -> ${!envVar}"
|
echo "@varName@ -> '${varName}'"
|
||||||
fi
|
fi
|
||||||
args="$args --subst-var $envVar"
|
args+=("--subst-var" "$varName")
|
||||||
done
|
done < <(env -0 | cut -z -d= -f1 | grep -z -v '^[_A-Z]')
|
||||||
|
|
||||||
substitute "$input" "$output" $args
|
substitute "$input" "$output" "${args[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user