From f6f40e3fe5fbb9721624a218faea1b520f9ec200 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 25 Jul 2017 18:48:47 -0400 Subject: [PATCH 1/3] stdenv-setup and misc pkgs: Revert to space-deliminated propagated-* files We cannot switch to line-delimited yet, because certain Nix commands do not read in the entire file, but just the first line. --- pkgs/build-support/cc-wrapper/default.nix | 6 +++--- pkgs/build-support/gcc-wrapper-old/builder.sh | 2 +- pkgs/build-support/trivial-builders.nix | 2 +- .../desktops/kde-4.14/kde-package/default.nix | 2 +- .../compilers/openjdk-darwin/8.nix | 2 +- .../compilers/openjdk-darwin/default.nix | 2 +- pkgs/development/compilers/openjdk/7.nix | 2 +- pkgs/development/compilers/openjdk/8.nix | 2 +- .../compilers/oraclejdk/jdk-linux-base.nix | 2 +- pkgs/development/compilers/zulu/default.nix | 2 +- .../haskell-modules/generic-builder.nix | 2 +- pkgs/misc/misc.nix | 2 +- pkgs/stdenv/generic/builder.sh | 2 +- pkgs/stdenv/generic/setup.sh | 19 +++++++++++-------- 14 files changed, 26 insertions(+), 23 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 1b52a0b8b123..09d1d4cd681a 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/gcc-wrapper-old/builder.sh b/pkgs/build-support/gcc-wrapper-old/builder.sh index 4f141f6b8f21..22e32814927e 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 1ee1fe8298fd..16bd4e8e4054 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 3637d9f89cb2..94f878097ded 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 691829c7788a..6234b63208cd 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 8ce0835fcb69..1e8f88beea66 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 9ef7d26b2efe..72f0ba293ba9 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 7c50872ebe59..0f0b42640c5d 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 08fd724f7733..fec038199adc 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 03be4ee8a0b9..f7638757ff7a 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 a8da63493a43..c7c54c959b5a 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -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 6e8c6f4486f1..a3c293beab33 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/stdenv/generic/builder.sh b/pkgs/stdenv/generic/builder.sh index f8c0fd44ac78..686cb778ca77 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 e0a33ca1c384..56ab82232964 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -210,6 +210,11 @@ printLines() { printf '%s\n' "$@" } +printWords() { + [[ "$#" -gt 0 ]] || return 0 + printf '%s ' "$@" +} + ###################################################################### # Initialisation. @@ -291,12 +296,10 @@ 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 } @@ -814,19 +817,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 +843,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 From ea7d13cf1acc60999a442b46b279460928165140 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 25 Jul 2017 17:48:50 -0400 Subject: [PATCH 2/3] stdenv-setup and misc hooks: Work with bash-3.4 for MacOS nix-shell This is a temporary measure until this impurity is removed from Nix. --- pkgs/build-support/cc-wrapper/setup-hook.sh | 2 +- .../haskell-modules/generic-builder.nix | 2 +- pkgs/servers/x11/xorg/builder.sh | 4 +- pkgs/stdenv/generic/setup.sh | 38 ++++++++++++------- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index 3e8494cf9c18..104b82425f29 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/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index c7c54c959b5a..2ec77b0563ae 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 diff --git a/pkgs/servers/x11/xorg/builder.sh b/pkgs/servers/x11/xorg/builder.sh index 3a8cf6fa6c8e..fae8bf5a8ce5 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/setup.sh b/pkgs/stdenv/generic/setup.sh index 56ab82232964..1e8b5f57585a 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 @@ -271,12 +273,22 @@ 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 + + # For some reason, bash gives us some (hopefully limited) eval + # "for free"! Everything is single-quoted except for `"$var"` + # so `var` is expanded first. + declare -g "$var"'=("${'"$var"'[@]}" "$pkg")' if ! [ -e "$pkg" ]; then echo "build input $pkg does not exist" >&2 @@ -306,19 +318,19 @@ findInputs() { if [ -z "$crossConfig" ]; then # Not cross-compiling - both buildInputs (and variants like propagatedBuildInputs) # are handled identically to nativeBuildInputs - declare -gA nativePkgs + declare -ga nativePkgs for i in $nativeBuildInputs $buildInputs \ $defaultNativeBuildInputs $defaultBuildInputs \ $propagatedNativeBuildInputs $propagatedBuildInputs; do findInputs "$i" nativePkgs propagated-native-build-inputs done else - declare -gA crossPkgs + declare -ga crossPkgs for i in $buildInputs $defaultBuildInputs $propagatedBuildInputs; do findInputs "$i" crossPkgs propagated-build-inputs done - declare -gA nativePkgs + declare -ga nativePkgs for i in $nativeBuildInputs $defaultNativeBuildInputs $propagatedNativeBuildInputs; do findInputs "$i" nativePkgs propagated-native-build-inputs done @@ -334,7 +346,7 @@ _addToNativeEnv() { runHook envHook "$pkg" } -for i in "${!nativePkgs[@]}"; do +for i in "${nativePkgs[@]}"; do _addToNativeEnv "$i" done @@ -345,7 +357,7 @@ _addToCrossEnv() { runHook crossEnvHook "$pkg" } -for i in "${!crossPkgs[@]}"; do +for i in "${crossPkgs[@]}"; do _addToCrossEnv "$i" done From 820e4021d3474d6d11d8847be8b2ae9b24da72d8 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 25 Jul 2017 20:58:47 -0400 Subject: [PATCH 3/3] stdenv-setup: Remove any `declare -g` This is invalid before bash-4.2, affecting bash used impurely in nix-shell on MacOS. --- pkgs/stdenv/generic/setup.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 1e8b5f57585a..dc3369f6611c 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -285,10 +285,7 @@ findInputs() { *" $pkg "*) return 0 ;; esac - # For some reason, bash gives us some (hopefully limited) eval - # "for free"! Everything is single-quoted except for `"$var"` - # so `var` is expanded first. - declare -g "$var"'=("${'"$var"'[@]}" "$pkg")' + eval "$var"'+=("$pkg")' if ! [ -e "$pkg" ]; then echo "build input $pkg does not exist" >&2 @@ -318,19 +315,19 @@ findInputs() { 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