diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 1b52a0b8b12..09d1d4cd681 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -190,7 +190,7 @@ stdenv.mkDerivation { # The dynamic linker is passed in `ldflagsBefore' to allow # explicit overrides of the dynamic linker by callers to gcc/ld # (the *last* value counts, so ours should come first). - printLines "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before + printWords "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before '') + optionalString (libc != null) '' @@ -258,9 +258,9 @@ stdenv.mkDerivation { # Propagate the wrapped cc so that if you install the wrapper, # you get tools like gcov, the manpages, etc. as well (including # for binutils and Glibc). - printLines ${cc} ${cc.man or ""} ${binutils_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages + printWords ${cc} ${cc.man or ""} ${binutils_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages - printLines ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs + printWords ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs '' + optionalString (targetPlatform.isSunOS && nativePrefix != "") '' diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index 3e8494cf9c1..104b82425f2 100644 --- a/pkgs/build-support/cc-wrapper/setup-hook.sh +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -54,7 +54,7 @@ do if PATH=$_PATH type -p "@binPrefix@$CMD" > /dev/null then - export "${ENV_PREFIX}${CMD^^}=@binPrefix@${CMD}"; + export "${ENV_PREFIX}$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=@binPrefix@${CMD}"; fi done diff --git a/pkgs/build-support/gcc-wrapper-old/builder.sh b/pkgs/build-support/gcc-wrapper-old/builder.sh index 4f141f6b8f2..22e32814927 100644 --- a/pkgs/build-support/gcc-wrapper-old/builder.sh +++ b/pkgs/build-support/gcc-wrapper-old/builder.sh @@ -211,5 +211,5 @@ cp -p $utils $out/nix-support/utils.sh # tools like gcov, the manpages, etc. as well (including for binutils # and Glibc). if test -z "$nativeTools"; then - printLines $gcc $binutils $libc $libc_bin > $out/nix-support/propagated-user-env-packages + printWords $gcc $binutils $libc $libc_bin > $out/nix-support/propagated-user-env-packages fi diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix index 1ee1fe8298f..16bd4e8e405 100644 --- a/pkgs/build-support/trivial-builders.nix +++ b/pkgs/build-support/trivial-builders.nix @@ -84,7 +84,7 @@ rec { mkdir -p $out/nix-support cp ${script} $out/nix-support/setup-hook '' + lib.optionalString (deps != []) '' - printLines ${toString deps} > $out/nix-support/propagated-native-build-inputs + printWords ${toString deps} > $out/nix-support/propagated-native-build-inputs '' + lib.optionalString (substitutions != {}) '' substituteAll ${script} $out/nix-support/setup-hook ''); diff --git a/pkgs/desktops/kde-4.14/kde-package/default.nix b/pkgs/desktops/kde-4.14/kde-package/default.nix index 3637d9f89cb..94f878097de 100644 --- a/pkgs/desktops/kde-4.14/kde-package/default.nix +++ b/pkgs/desktops/kde-4.14/kde-package/default.nix @@ -86,7 +86,7 @@ rec { };}) '' mkdir -pv $out/nix-support - printLines ${toString list} | tee $out/nix-support/propagated-user-env-packages + printWords ${toString list} | tee $out/nix-support/propagated-user-env-packages ''; # Given manifest module data, return the module diff --git a/pkgs/development/compilers/openjdk-darwin/8.nix b/pkgs/development/compilers/openjdk-darwin/8.nix index 691829c7788..6234b63208c 100644 --- a/pkgs/development/compilers/openjdk-darwin/8.nix +++ b/pkgs/development/compilers/openjdk-darwin/8.nix @@ -33,7 +33,7 @@ let # any package that depends on the JRE has $CLASSPATH set up # properly. mkdir -p $out/nix-support - printLines ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs + printWords ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs install_name_tool -change /usr/X11/lib/libfreetype.6.dylib ${freetype}/lib/libfreetype.6.dylib $out/jre/lib/libfontmanager.dylib diff --git a/pkgs/development/compilers/openjdk-darwin/default.nix b/pkgs/development/compilers/openjdk-darwin/default.nix index 8ce0835fcb6..1e8f88beea6 100644 --- a/pkgs/development/compilers/openjdk-darwin/default.nix +++ b/pkgs/development/compilers/openjdk-darwin/default.nix @@ -23,7 +23,7 @@ let # any package that depends on the JRE has $CLASSPATH set up # properly. mkdir -p $out/nix-support - printLines ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs + printWords ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs install_name_tool -change /usr/X11/lib/libfreetype.6.dylib ${freetype}/lib/libfreetype.6.dylib $out/jre/lib/libfontmanager.dylib diff --git a/pkgs/development/compilers/openjdk/7.nix b/pkgs/development/compilers/openjdk/7.nix index 9ef7d26b2ef..72f0ba293ba 100644 --- a/pkgs/development/compilers/openjdk/7.nix +++ b/pkgs/development/compilers/openjdk/7.nix @@ -190,7 +190,7 @@ let # any package that depends on the JRE has $CLASSPATH set up # properly. mkdir -p $jre/nix-support - printLines ${setJavaClassPath} > $jre/nix-support/propagated-native-build-inputs + printWords ${setJavaClassPath} > $jre/nix-support/propagated-native-build-inputs # Set JAVA_HOME automatically. mkdir -p $out/nix-support diff --git a/pkgs/development/compilers/openjdk/8.nix b/pkgs/development/compilers/openjdk/8.nix index 7c50872ebe5..0f0b42640c5 100644 --- a/pkgs/development/compilers/openjdk/8.nix +++ b/pkgs/development/compilers/openjdk/8.nix @@ -202,7 +202,7 @@ let # any package that depends on the JRE has $CLASSPATH set up # properly. mkdir -p $jre/nix-support - printLines ${setJavaClassPath} > $jre/nix-support/propagated-native-build-inputs + printWords ${setJavaClassPath} > $jre/nix-support/propagated-native-build-inputs # Set JAVA_HOME automatically. mkdir -p $out/nix-support diff --git a/pkgs/development/compilers/oraclejdk/jdk-linux-base.nix b/pkgs/development/compilers/oraclejdk/jdk-linux-base.nix index 08fd724f773..fec038199ad 100644 --- a/pkgs/development/compilers/oraclejdk/jdk-linux-base.nix +++ b/pkgs/development/compilers/oraclejdk/jdk-linux-base.nix @@ -165,7 +165,7 @@ let result = stdenv.mkDerivation rec { ln -s $jrePath/lib/${architecture}/libnpjp2.so $jrePath/lib/${architecture}/plugins mkdir -p $out/nix-support - printLines ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs + printWords ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs # Set JAVA_HOME automatically. cat <> $out/nix-support/setup-hook diff --git a/pkgs/development/compilers/zulu/default.nix b/pkgs/development/compilers/zulu/default.nix index 03be4ee8a0b..f7638757ff7 100644 --- a/pkgs/development/compilers/zulu/default.nix +++ b/pkgs/development/compilers/zulu/default.nix @@ -54,7 +54,7 @@ in stdenv.mkDerivation rec { find $out -name "*.so" -exec patchelf --set-rpath "$rpath" {} \; mkdir -p $out/nix-support - printLines ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs + printWords ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs # Set JAVA_HOME automatically. cat <> $out/nix-support/setup-hook diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index a8da63493a4..2ec77b0563a 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -211,7 +211,7 @@ stdenv.mkDerivation ({ configureFlags="${concatStringsSep " " defaultConfigureFlags} $configureFlags" # nativePkgs defined in stdenv/setup.hs - for p in "''${!nativePkgs[@]}"; do + for p in "''${nativePkgs[@]}"; do if [ -d "$p/lib/${ghc.name}/package.conf.d" ]; then cp -f "$p/lib/${ghc.name}/package.conf.d/"*.conf $packageConfDir/ continue @@ -311,7 +311,7 @@ stdenv.mkDerivation ({ ${optionalString isGhcjs '' for exeDir in "$out/bin/"*.jsexe; do exe="''${exeDir%.jsexe}" - printLines '#!${nodejs}/bin/node' > "$exe" + printWords '#!${nodejs}/bin/node' > "$exe" cat "$exeDir/all.js" >> "$exe" chmod +x "$exe" done diff --git a/pkgs/misc/misc.nix b/pkgs/misc/misc.nix index 6e8c6f4486f..a3c293beab3 100644 --- a/pkgs/misc/misc.nix +++ b/pkgs/misc/misc.nix @@ -23,7 +23,7 @@ in */ collection = {list, name} : runCommand "collection-${name}" {} '' mkdir -p $out/nix-support - printLines ${builtins.toString list} > $out/nix-support/propagated-user-env-packages + printWords ${builtins.toString list} > $out/nix-support/propagated-user-env-packages ''; /* creates a derivation symlinking references C/C++ libs into one include and lib directory called $out/cdt-envs/${name} diff --git a/pkgs/servers/x11/xorg/builder.sh b/pkgs/servers/x11/xorg/builder.sh index 3a8cf6fa6c8..fae8bf5a8ce 100644 --- a/pkgs/servers/x11/xorg/builder.sh +++ b/pkgs/servers/x11/xorg/builder.sh @@ -18,14 +18,14 @@ postInstall() { for r in $requires; do if test -n "$crossConfig"; then - for p in "${!crossPkgs[@]}"; do + for p in "${crossPkgs[@]}"; do if test -e $p/lib/pkgconfig/$r.pc; then echo " found requisite $r in $p" propagatedBuildInputs="$propagatedBuildInputs $p" fi done else - for p in "${!nativePkgs[@]}"; do + for p in "${nativePkgs[@]}"; do if test -e $p/lib/pkgconfig/$r.pc; then echo " found requisite $r in $p" propagatedNativeBuildInputs="$propagatedNativeBuildInputs $p" diff --git a/pkgs/stdenv/generic/builder.sh b/pkgs/stdenv/generic/builder.sh index f8c0fd44ac7..686cb778ca7 100644 --- a/pkgs/stdenv/generic/builder.sh +++ b/pkgs/stdenv/generic/builder.sh @@ -15,5 +15,5 @@ cat "$setup" >> $out/setup # in stdenv. mkdir $out/nix-support if [ "$propagatedUserEnvPkgs" ]; then - printf '%s\n' $propagatedUserEnvPkgs > $out/nix-support/propagated-user-env-packages + printf '%s ' $propagatedUserEnvPkgs > $out/nix-support/propagated-user-env-packages fi diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index e0a33ca1c38..dc3369f6611 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -17,9 +17,10 @@ runHook() { shift local var="$hookName" if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi - local -n var + + local varRef="$var[@]" local hook - for hook in "_callImplicitHook 0 $hookName" "${var[@]}"; do + for hook in "_callImplicitHook 0 $hookName" "${!varRef}"; do _eval "$hook" "$@" done return 0 @@ -33,9 +34,10 @@ runOneHook() { shift local var="$hookName" if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi - local -n var + + local varRef="$var[@]" local hook - for hook in "_callImplicitHook 1 $hookName" "${var[@]}"; do + for hook in "_callImplicitHook 1 $hookName" "${!varRef}"; do if _eval "$hook" "$@"; then return 0 fi @@ -210,6 +212,11 @@ printLines() { printf '%s\n' "$@" } +printWords() { + [[ "$#" -gt 0 ]] || return 0 + printf '%s ' "$@" +} + ###################################################################### # Initialisation. @@ -266,12 +273,19 @@ runHook addInputsHook findInputs() { local pkg="$1" local var="$2" - local -n varDeref="$var" local propagatedBuildInputsFile="$3" - # Stop if we've already added this one - [[ -z "${varDeref["$pkg"]}" ]] || return 0 - varDeref["$pkg"]=1 + # TODO(@Ericson2314): Restore using associative array once Darwin + # nix-shell doesn't use impure bash. This should replace the O(n) + # case with an O(1) hash map lookup, assuming bash is implemented + # well :D. + local varRef="$var[*]" + + case "${!varRef}" in + *" $pkg "*) return 0 ;; + esac + + eval "$var"'+=("$pkg")' if ! [ -e "$pkg" ]; then echo "build input $pkg does not exist" >&2 @@ -291,31 +305,29 @@ findInputs() { fi if [ -f "$pkg/nix-support/$propagatedBuildInputsFile" ]; then - local fd pkgNext - exec {fd}<"$pkg/nix-support/$propagatedBuildInputsFile" - while IFS= read -r -u $fd pkgNext; do + local pkgNext + for pkgNext in $(< "$pkg/nix-support/$propagatedBuildInputsFile"); do findInputs "$pkgNext" "$var" "$propagatedBuildInputsFile" done - exec {fd}<&- fi } if [ -z "$crossConfig" ]; then # Not cross-compiling - both buildInputs (and variants like propagatedBuildInputs) # are handled identically to nativeBuildInputs - declare -gA nativePkgs + declare -a nativePkgs for i in $nativeBuildInputs $buildInputs \ $defaultNativeBuildInputs $defaultBuildInputs \ $propagatedNativeBuildInputs $propagatedBuildInputs; do findInputs "$i" nativePkgs propagated-native-build-inputs done else - declare -gA crossPkgs + declare -a crossPkgs for i in $buildInputs $defaultBuildInputs $propagatedBuildInputs; do findInputs "$i" crossPkgs propagated-build-inputs done - declare -gA nativePkgs + declare -a nativePkgs for i in $nativeBuildInputs $defaultNativeBuildInputs $propagatedNativeBuildInputs; do findInputs "$i" nativePkgs propagated-native-build-inputs done @@ -331,7 +343,7 @@ _addToNativeEnv() { runHook envHook "$pkg" } -for i in "${!nativePkgs[@]}"; do +for i in "${nativePkgs[@]}"; do _addToNativeEnv "$i" done @@ -342,7 +354,7 @@ _addToCrossEnv() { runHook crossEnvHook "$pkg" } -for i in "${!crossPkgs[@]}"; do +for i in "${crossPkgs[@]}"; do _addToCrossEnv "$i" done @@ -814,19 +826,19 @@ fixupPhase() { if [ -n "$propagated" ]; then mkdir -p "${!outputDev}/nix-support" # shellcheck disable=SC2086 - printLines $propagated > "${!outputDev}/nix-support/propagated-native-build-inputs" + printWords $propagated > "${!outputDev}/nix-support/propagated-native-build-inputs" fi else if [ -n "$propagatedBuildInputs" ]; then mkdir -p "${!outputDev}/nix-support" # shellcheck disable=SC2086 - printLines $propagatedBuildInputs > "${!outputDev}/nix-support/propagated-build-inputs" + printWords $propagatedBuildInputs > "${!outputDev}/nix-support/propagated-build-inputs" fi if [ -n "$propagatedNativeBuildInputs" ]; then mkdir -p "${!outputDev}/nix-support" # shellcheck disable=SC2086 - printLines $propagatedNativeBuildInputs > "${!outputDev}/nix-support/propagated-native-build-inputs" + printWords $propagatedNativeBuildInputs > "${!outputDev}/nix-support/propagated-native-build-inputs" fi fi @@ -840,7 +852,7 @@ fixupPhase() { if [ -n "$propagatedUserEnvPkgs" ]; then mkdir -p "${!outputBin}/nix-support" # shellcheck disable=SC2086 - printLines $propagatedUserEnvPkgs > "${!outputBin}/nix-support/propagated-user-env-packages" + printWords $propagatedUserEnvPkgs > "${!outputBin}/nix-support/propagated-user-env-packages" fi runHook postFixup