···11691169echo @foo@
11701170</programlisting>
1171117111721172- That is, no substitution is performed for undefined variables.</para></listitem>
11721172+ That is, no substitution is performed for undefined variables.</para>
11731173+11741174+ <para>Environment variables that start with an uppercase letter are filtered out,
11751175+ to prevent global variables (like <literal>HOME</literal>) from accidentally
11761176+ getting substituted.
11771177+ The variables also have to be valid bash “names”, as
11781178+ defined in the bash manpage (alphanumeric or <literal>_</literal>, must not
11791179+ start with a number).</para>
11801180+ </listitem>
11731181 </varlistentry>
1174118211751183
+1
pkgs/build-support/substitute/substitute-all.nix
···2233args:
4455+# see the substituteAll in the nixpkgs documentation for usage and constaints
56stdenv.mkDerivation ({
67 name = if args ? name then args.name else baseNameOf (toString args.src);
78 builder = ./substitute-all.sh;
+7-1
pkgs/stdenv/generic/setup.sh
···408408409409 if [ "$p" = --subst-var ]; then
410410 varName="${params[$((n + 1))]}"
411411+ # check if the used nix attribute name is a valid bash name
412412+ if ! [[ "$varName" =~ ^[a-zA-Z_]+[a-zA-Z0-9_]*$ ]]; then
413413+ echo "substitution variables must be valid bash names, \"$varName\" isn't."
414414+ exit 1;
415415+ fi
411416 pattern="@$varName@"
412417 replacement="${!varName}"
413418 n=$((n + 1))
···439444 local output="$2"
440445441446 # Select all environment variables that start with a lowercase character.
442442- for envVar in $(env | sed -e $'s/^\([a-z][^=]*\)=.*/\\1/; t \n d'); do
447447+ # Will not work with nix attribute names (and thus env variables) containing '\n'.
448448+ for envVar in $(set | sed -e $'s/^\([a-z][^=]*\)=.*/\\1/; t \n d'); do
443449 if [ "$NIX_DEBUG" = "1" ]; then
444450 echo "$envVar -> ${!envVar}"
445451 fi