From b0f2d3419c3340978026272496c306287a8cdbd9 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 25 Jun 2014 15:38:37 +0200 Subject: [PATCH 01/23] Allow multiple hooks with the same name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit You can now register multiple values per named hook, e.g. addHook preConfigure "echo foo" addHook preConfigure "echo bar" will cause ‘runHook preConfigure’ to run both ‘echo foo’ and ‘echo bar’ (in that order). It will also call the shell function preConfigure() or eval the shell variable $preConfigure, if defined. Thus, if you don't call addHook, it works like the old hook mechanism. Allowing multiple hooks makes stdenv more modular and extensible. For instance, multiple setup hooks can define a preFixup hook, and all of these will be executed. --- pkgs/stdenv/generic/setup.sh | 53 ++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index c3b9033b49a..de762490715 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -1,8 +1,38 @@ -# Run the named hook, either by calling the function with that name or -# by evaluating the variable with that name. This allows convenient -# setting of hooks both from Nix expressions (as attributes / -# environment variables) and from shell scripts (as functions). +###################################################################### +# Hook handling. + + +# Add the specified shell code to the named hook, e.g. ‘addHook +# preConfigure "rm ./foo; touch ./bar"’. +addHook() { + local hookName="$1" + local hookCode="$2" + eval "_${hookName}_hooks+=(\"\$hookCode\")" +} + + +# Run all hooks with the specified name in the order in which they +# were added, stopping if any fails (returns a non-zero exit +# code). Hooks are added using ‘addHooks ’, or +# implicitly by defining a shell function or variable . Note +# that the latter takes precedence over hooks added via ‘addHooks’. runHook() { + local hookName="$1" + local var="_${hookName}_hooks" + eval "local -a dummy=(\"\${_${hookName}_hooks[@]}\")" + for hook in "runSingleHook $hookName" "${dummy[@]}"; do + if ! _eval "$hook"; then return 1; fi + done + return 0 +} + + +# Run the named hook, either by calling the function with that name or +# by evaluating the variable with that name. This allows convenient +# setting of hooks both from Nix expressions (as attributes / +# environment variables) and from shell scripts (as functions). If you +# want to allow multiple hooks, use runHook instead. +runSingleHook() { local hookName="$1" case "$(type -t $hookName)" in (function|alias|builtin) $hookName;; @@ -13,6 +43,17 @@ runHook() { } +# A function wrapper around ‘eval’ that ensures that ‘return’ inside +# hooks exits the hook, not the caller. +_eval() { + local code="$1" + eval "$code" +} + + +###################################################################### +# Error handling. + exitHandler() { exitCode=$? set +e @@ -467,7 +508,7 @@ unpackFile() { echo "source archive $curSrc has unknown type" exit 1 fi - runHook unpackCmd + runSingleHook unpackCmd fi ;; esac @@ -505,7 +546,7 @@ unpackPhase() { # Find the source directory. if [ -n "$setSourceRoot" ]; then - runHook setSourceRoot + runSingleHook setSourceRoot elif [ -z "$sourceRoot" ]; then sourceRoot= for i in *; do From 37889e2b5ea444fce8a48fe3bf9250c9ddafa7d0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 25 Jun 2014 16:47:58 +0200 Subject: [PATCH 02/23] Provide a hook for per-output fixup --- pkgs/stdenv/generic/setup.sh | 75 +++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index de762490715..14c64e8020d 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -1,3 +1,6 @@ +: ${outputs:=out} + + ###################################################################### # Hook handling. @@ -784,14 +787,16 @@ installPhase() { } -# The fixup phase performs generic, package-independent, Nix-related -# stuff, like running patchelf and setting the -# propagated-build-inputs. It should rarely be overriden. +# The fixup phase performs generic, package-independent stuff, like +# stripping binaries, running patchelf and setting +# propagated-build-inputs. fixupPhase() { - runHook preFixup - # Make sure everything is writable so "strip" et al. work. - if [ -e "$prefix" ]; then chmod -R u+w "$prefix"; fi + for output in $outputs; do + if [ -e "$output" ]; then chmod -R u+w "$output"; fi + done + + runHook preFixup # Put man/doc/info under $out/share. forceShare=${forceShare:=man doc info} @@ -812,10 +817,42 @@ fixupPhase() { done; fi + # Apply fixup to each output. + local output + for output in $outputs; do + prefix=${!output} runHook fixupOutput + done + + if [ -n "$propagatedBuildInputs" ]; then + mkdir -p "$out/nix-support" + echo "$propagatedBuildInputs" > "$out/nix-support/propagated-build-inputs" + fi + + if [ -n "$propagatedNativeBuildInputs" ]; then + mkdir -p "$out/nix-support" + echo "$propagatedNativeBuildInputs" > "$out/nix-support/propagated-native-build-inputs" + fi + + if [ -n "$propagatedUserEnvPkgs" ]; then + mkdir -p "$out/nix-support" + echo "$propagatedUserEnvPkgs" > "$out/nix-support/propagated-user-env-packages" + fi + + if [ -n "$setupHook" ]; then + mkdir -p "$out/nix-support" + substituteAll "$setupHook" "$out/nix-support/setup-hook" + fi + + runHook postFixup +} + + +addHook fixupOutput _defaultFixupOutput +_defaultFixupOutput() { if [ -z "$dontGzipMan" ]; then echo "gzipping man pages" GLOBIGNORE=.:..:*.gz:*.bz2 - for f in "$out"/share/man/*/* "$out"/share/man/*/*/*; do + for f in "$prefix"/share/man/*/* "$prefix"/share/man/*/*/*; do if [ -f "$f" -a ! -L "$f" ]; then if gzip -c -n "$f" > "$f".gz; then rm "$f" @@ -824,7 +861,7 @@ fixupPhase() { fi fi done - for f in "$out"/share/man/*/* "$out"/share/man/*/*/*; do + for f in "$prefix"/share/man/*/* "$prefix"/share/man/*/*/*; do if [ -L "$f" -a -f `readlink -f "$f"`.gz ]; then ln -sf `readlink "$f"`.gz "$f".gz && rm "$f" fi @@ -852,28 +889,6 @@ fixupPhase() { if [ -z "$dontPatchShebangs" ]; then patchShebangs "$prefix" fi - - if [ -n "$propagatedBuildInputs" ]; then - mkdir -p "$out/nix-support" - echo "$propagatedBuildInputs" > "$out/nix-support/propagated-build-inputs" - fi - - if [ -n "$propagatedNativeBuildInputs" ]; then - mkdir -p "$out/nix-support" - echo "$propagatedNativeBuildInputs" > "$out/nix-support/propagated-native-build-inputs" - fi - - if [ -n "$propagatedUserEnvPkgs" ]; then - mkdir -p "$out/nix-support" - echo "$propagatedUserEnvPkgs" > "$out/nix-support/propagated-user-env-packages" - fi - - if [ -n "$setupHook" ]; then - mkdir -p "$out/nix-support" - substituteAll "$setupHook" "$out/nix-support/setup-hook" - fi - - runHook postFixup } From 0a8605ded168751dbe8bcd0d00d1e38b9d1feded Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 25 Jun 2014 16:51:18 +0200 Subject: [PATCH 03/23] Formatting --- pkgs/stdenv/generic/default.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 0d8355e89cc..039ac76e406 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -23,7 +23,7 @@ let # {pkgs, ...}: # { # allowUnfree = false; - # allowUnfreePredicate = (x: pkgs.lib.hasPrefix "flashplayero-" x.name); + # allowUnfreePredicate = (x: pkgs.lib.hasPrefix "flashplayer-" x.name); # } allowUnfreePredicate = config.allowUnfreePredicate or (x: false); @@ -74,7 +74,9 @@ let unsafeGetAttrPos "name" attrs; pos' = if pos != null then "‘" + pos.file + ":" + toString pos.line + "’" else "«unknown-file»"; in - if !allowUnfree && (let l = lib.lists.toList attrs.meta.license or []; in lib.lists.elem "unfree" l || lib.lists.elem "unfree-redistributable" l) && !(allowUnfreePredicate attrs) then + if !allowUnfree + && (let l = lib.lists.toList attrs.meta.license or []; in lib.lists.elem "unfree" l || lib.lists.elem "unfree-redistributable" l) + && !allowUnfreePredicate attrs then throw '' Package ‘${attrs.name}’ in ${pos'} has an unfree license, refusing to evaluate. You can set { nixpkgs.config.allowUnfree = true; } From b23dbb1a5dffbfa3abb47fcd0f1579ac2e6f29fc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 25 Jun 2014 17:01:29 +0200 Subject: [PATCH 04/23] Allow buildInputs to be regular files If a build input is a regular file, use it as a setup hook. This makes setup hooks more efficient to create: you don't need a derivation that copies them to $out/nix-support/setup-hook, instead you can use the file as is. --- pkgs/stdenv/generic/setup.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 14c64e8020d..d3d2d250e50 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -198,6 +198,10 @@ findInputs() { eval $var="'${!var} $pkg '" + if [ -f $pkg ]; then + source $pkg + fi + if [ -f $pkg/nix-support/setup-hook ]; then source $pkg/nix-support/setup-hook fi From 83a41771abbfcfc027270671be55eb3ed1606a46 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 27 Jun 2014 11:15:28 +0200 Subject: [PATCH 05/23] Move RPATH shrinking from stdenv to a setup hook provided by patchelf --- .../tools/misc/patchelf/default.nix | 2 ++ .../tools/misc/patchelf/setup-hook.sh | 18 +++++++++++++++ pkgs/stdenv/generic/setup.sh | 17 -------------- pkgs/stdenv/linux/default.nix | 23 ++++++++++--------- 4 files changed, 32 insertions(+), 28 deletions(-) create mode 100644 pkgs/development/tools/misc/patchelf/setup-hook.sh diff --git a/pkgs/development/tools/misc/patchelf/default.nix b/pkgs/development/tools/misc/patchelf/default.nix index 06b5c2ef516..5aa81e46bed 100644 --- a/pkgs/development/tools/misc/patchelf/default.nix +++ b/pkgs/development/tools/misc/patchelf/default.nix @@ -8,6 +8,8 @@ stdenv.mkDerivation rec { sha256 = "c99f84d124347340c36707089ec8f70530abd56e7827c54d506eb4cc097a17e7"; }; + setupHook = [ ./setup-hook.sh ]; + meta = { homepage = http://nixos.org/patchelf.html; license = "GPL"; diff --git a/pkgs/development/tools/misc/patchelf/setup-hook.sh b/pkgs/development/tools/misc/patchelf/setup-hook.sh new file mode 100644 index 00000000000..e27d1ed5b00 --- /dev/null +++ b/pkgs/development/tools/misc/patchelf/setup-hook.sh @@ -0,0 +1,18 @@ +# This setup hook calls patchelf to automatically remove unneeded +# directories from the RPATH of every library or executable in every +# output. + +if [ -z "$dontPatchELF" ]; then + addHook fixupOutput 'patchELF "$prefix"' +fi + +patchELF() { + header "patching ELF executables and libraries in $prefix" + if [ -e "$prefix" ]; then + find "$prefix" \( \ + \( -type f -a -name "*.so*" \) -o \ + \( -type f -a -perm +0100 \) \ + \) -print -exec patchelf --shrink-rpath '{}' \; + fi + stopNest +} diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index d3d2d250e50..a953176127c 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -702,19 +702,6 @@ checkPhase() { } -patchELF() { - # Patch all ELF executables and shared libraries. - header "patching ELF executables and libraries" - if [ -e "$prefix" ]; then - find "$prefix" \( \ - \( -type f -a -name "*.so*" \) -o \ - \( -type f -a -perm +0100 \) \ - \) -print -exec patchelf --shrink-rpath '{}' \; - fi - stopNest -} - - patchShebangs() { # Rewrite all script interpreter file names (`#! /path') under the # specified directory tree to paths found in $PATH. E.g., @@ -886,10 +873,6 @@ _defaultFixupOutput() { fi fi - if [ "$havePatchELF" = 1 -a -z "$dontPatchELF" ]; then - patchELF "$prefix" - fi - if [ -z "$dontPatchShebangs" ]; then patchShebangs "$prefix" fi diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 23cccf223f4..7169ce9f94e 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -26,7 +26,6 @@ rec { commonPreHook = '' export NIX_ENFORCE_PURITY=1 - havePatchELF=1 ${if system == "x86_64-linux" then "NIX_LIB64_IN_SELF_RPATH=1" else ""} ${if system == "mips64el-linux" then "NIX_LIB32_IN_SELF_RPATH=1" else ""} ''; @@ -46,7 +45,7 @@ rec { builder = bootstrapFiles.sh; args = - if system == "armv5tel-linux" || system == "armv6l-linux" + if system == "armv5tel-linux" || system == "armv6l-linux" || system == "armv7l-linux" then [ ./scripts/unpack-bootstrap-tools-arm.sh ] else [ ./scripts/unpack-bootstrap-tools.sh ]; @@ -69,10 +68,10 @@ rec { # This function builds the various standard environments used during # the bootstrap. stdenvBootFun = - {gcc, extraAttrs ? {}, overrides ? (pkgs: {}), extraPath ? [], fetchurl}: + { gcc, extraAttrs ? {}, overrides ? (pkgs: {}), extraBuildInputs ? [], fetchurl }: import ../generic { - inherit system config; + inherit system config extraBuildInputs; name = "stdenv-linux-boot"; preHook = '' @@ -82,7 +81,7 @@ rec { ${commonPreHook} ''; shell = "${bootstrapTools}/bin/sh"; - initialPath = [bootstrapTools] ++ extraPath; + initialPath = [ bootstrapTools ]; fetchurlBoot = fetchurl; inherit gcc; # Having the proper 'platform' in all the stdenvs allows getting proper @@ -208,9 +207,9 @@ rec { ppl = pkgs.ppl.override { stdenv = pkgs.makeStaticLibraries pkgs.stdenv; }; }; extraAttrs = { - glibc = stdenvLinuxGlibc; # Required by gcc47 build + glibc = stdenvLinuxGlibc; # Required by gcc47 build }; - extraPath = [ stdenvLinuxBoot1Pkgs.paxctl ]; + extraBuildInputs = [ stdenvLinuxBoot2Pkgs.patchelf stdenvLinuxBoot1Pkgs.paxctl ]; inherit fetchurl; }; @@ -233,7 +232,7 @@ rec { gcc = stdenvLinuxBoot3Pkgs.gcc.gcc; name = ""; }; - extraPath = [ stdenvLinuxBoot3Pkgs.xz ]; + extraBuildInputs = [ stdenvLinuxBoot2Pkgs.patchelf stdenvLinuxBoot3Pkgs.xz ]; overrides = pkgs: { inherit (stdenvLinuxBoot1Pkgs) perl; inherit (stdenvLinuxBoot3Pkgs) gettext gnum4 gmp; @@ -268,8 +267,10 @@ rec { ''; initialPath = - ((import ../common-path.nix) {pkgs = stdenvLinuxBoot4Pkgs;}) - ++ [stdenvLinuxBoot4Pkgs.patchelf stdenvLinuxBoot4Pkgs.paxctl ]; + ((import ../common-path.nix) {pkgs = stdenvLinuxBoot4Pkgs;}); + + extraBuildInputs = + [ stdenvLinuxBoot4Pkgs.patchelf stdenvLinuxBoot4Pkgs.paxctl ]; gcc = wrapGCC rec { inherit (stdenvLinuxBoot4Pkgs) binutils coreutils; @@ -284,7 +285,7 @@ rec { fetchurlBoot = fetchurl; extraAttrs = { - inherit (stdenvLinuxBoot3Pkgs) glibc; + glibc = stdenvLinuxGlibc; inherit platform bootstrapTools; shellPackage = stdenvLinuxBoot4Pkgs.bash; }; From d7a4fa26b064aa294b1f52c61b02770feed6903b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 27 Jun 2014 11:29:51 +0200 Subject: [PATCH 06/23] Fix dontPatchELF being set after the setup script has been sourced --- pkgs/development/tools/misc/patchelf/setup-hook.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/development/tools/misc/patchelf/setup-hook.sh b/pkgs/development/tools/misc/patchelf/setup-hook.sh index e27d1ed5b00..6bc918a4610 100644 --- a/pkgs/development/tools/misc/patchelf/setup-hook.sh +++ b/pkgs/development/tools/misc/patchelf/setup-hook.sh @@ -2,9 +2,7 @@ # directories from the RPATH of every library or executable in every # output. -if [ -z "$dontPatchELF" ]; then - addHook fixupOutput 'patchELF "$prefix"' -fi +addHook fixupOutput 'if [ -z "$dontPatchELF" ]; then patchELF "$prefix"; fi' patchELF() { header "patching ELF executables and libraries in $prefix" From daa66b8b1cb2ea5359f9914418350f63f0a53d7e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 27 Jun 2014 13:33:05 +0200 Subject: [PATCH 07/23] Factor out fixup phase stuff into separate setup hooks --- .../setup-hooks/compress-man-pages.sh | 27 ++++ .../setup-hooks/patch-shebangs.sh | 62 +++++++++ pkgs/build-support/setup-hooks/strip.sh | 36 ++++++ pkgs/stdenv/generic/default.nix | 10 +- pkgs/stdenv/generic/setup.sh | 122 +----------------- 5 files changed, 134 insertions(+), 123 deletions(-) create mode 100644 pkgs/build-support/setup-hooks/compress-man-pages.sh create mode 100644 pkgs/build-support/setup-hooks/patch-shebangs.sh create mode 100644 pkgs/build-support/setup-hooks/strip.sh diff --git a/pkgs/build-support/setup-hooks/compress-man-pages.sh b/pkgs/build-support/setup-hooks/compress-man-pages.sh new file mode 100644 index 00000000000..74c565ebffc --- /dev/null +++ b/pkgs/build-support/setup-hooks/compress-man-pages.sh @@ -0,0 +1,27 @@ +addHook fixupOutput 'if [ -z "$dontGzipMan" ]; then compressManPages "$prefix"; fi' + +compressManPages() { + local dir="$1" + + echo "gzipping man pages in $dir" + + GLOBIGNORE=.:..:*.gz:*.bz2 + + for f in "$dir"/share/man/*/* "$dir"/share/man/*/*/*; do + if [ -f "$f" -a ! -L "$f" ]; then + if gzip -c -n "$f" > "$f".gz; then + rm "$f" + else + rm "$f".gz + fi + fi + done + + for f in "$dir"/share/man/*/* "$dir"/share/man/*/*/*; do + if [ -L "$f" -a -f `readlink -f "$f"`.gz ]; then + ln -sf `readlink "$f"`.gz "$f".gz && rm "$f" + fi + done + + unset GLOBIGNORE +} diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh new file mode 100644 index 00000000000..6b42291358d --- /dev/null +++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh @@ -0,0 +1,62 @@ +# This setup hook causes the fixup phase to rewrite all script +# interpreter file names (`#! /path') to paths found in $PATH. E.g., +# /bin/sh will be rewritten to /nix/store/-some-bash/bin/sh. +# /usr/bin/env gets special treatment so that ".../bin/env python" is +# rewritten to /nix/store//bin/python. Interpreters that are +# already in the store are left untouched. + +addHook fixupOutput 'if [ -z "$dontPatchShebangs" ]; then patchShebangs "$prefix"; fi' + +patchShebangs() { + local dir="$1" + header "patching script interpreter paths in $dir" + local f + local oldPath + local newPath + local arg0 + local args + local oldInterpreterLine + local newInterpreterLine + + find "$dir" -type f -perm +0100 | while read f; do + if [ "$(head -1 "$f" | head -c +2)" != '#!' ]; then + # missing shebang => not a script + continue + fi + + oldInterpreterLine=$(head -1 "$f" | tail -c +3) + read -r oldPath arg0 args <<< "$oldInterpreterLine" + + if $(echo "$oldPath" | grep -q "/bin/env$"); then + # Check for unsupported 'env' functionality: + # - options: something starting with a '-' + # - environment variables: foo=bar + if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then + echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" + exit 1 + fi + newPath="$(command -v "$arg0" || true)" + else + if [ "$oldPath" = "" ]; then + # If no interpreter is specified linux will use /bin/sh. Set + # oldpath="/bin/sh" so that we get /nix/store/.../sh. + oldPath="/bin/sh" + fi + newPath="$(command -v "$(basename "$oldPath")" || true)" + args="$arg0 $args" + fi + + newInterpreterLine="$newPath $args" + + if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then + if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then + echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\"" + # escape the escape chars so that sed doesn't interpret them + escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g') + sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f" + fi + fi + done + + stopNest +} diff --git a/pkgs/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh new file mode 100644 index 00000000000..a84f7beaa5a --- /dev/null +++ b/pkgs/build-support/setup-hooks/strip.sh @@ -0,0 +1,36 @@ +# This setup hook strips libraries and executables in the fixup phase. + +addHook fixupOutput _doStrip + +_doStrip() { + if [ -z "$dontStrip" ]; then + stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin} + if [ -n "$stripDebugList" ]; then + stripDirs "$stripDebugList" "${stripDebugFlags:--S}" + fi + + stripAllList=${stripAllList:-} + if [ -n "$stripAllList" ]; then + stripDirs "$stripAllList" "${stripAllFlags:--s}" + fi + fi +} + +stripDirs() { + local dirs="$1" + local stripFlags="$2" + local dirsNew= + + for d in ${dirs}; do + if [ -d "$prefix/$d" ]; then + dirsNew="${dirsNew} $prefix/$d " + fi + done + dirs=${dirsNew} + + if [ -n "${dirs}" ]; then + header "stripping (with flags $stripFlags) in $dirs" + find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} strip $commonStripFlags $stripFlags || true + stopNest + fi +} diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 039ac76e406..f370aec88cf 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -31,6 +31,12 @@ let unsafeGetAttrPos = builtins.unsafeGetAttrPos or (n: as: null); + extraBuildInputs' = extraBuildInputs ++ + [ ../../build-support/setup-hooks/compress-man-pages.sh + ../../build-support/setup-hooks/strip.sh + ../../build-support/setup-hooks/patch-shebangs.sh + ]; + # The stdenv that we are producing. result = @@ -106,10 +112,10 @@ let __ignoreNulls = true; # Inputs built by the cross compiler. - buildInputs = lib.optionals (crossConfig != null) (buildInputs ++ extraBuildInputs); + buildInputs = lib.optionals (crossConfig != null) (buildInputs ++ extraBuildInputs'); propagatedBuildInputs = lib.optionals (crossConfig != null) propagatedBuildInputs; # Inputs built by the usual native compiler. - nativeBuildInputs = nativeBuildInputs ++ lib.optionals (crossConfig == null) (buildInputs ++ extraBuildInputs); + nativeBuildInputs = nativeBuildInputs ++ lib.optionals (crossConfig == null) (buildInputs ++ extraBuildInputs'); propagatedNativeBuildInputs = propagatedNativeBuildInputs ++ lib.optionals (crossConfig == null) propagatedBuildInputs; }))) ( diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index a953176127c..286e9e019b1 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -325,25 +325,6 @@ export NIX_BUILD_CORES # Misc. helper functions. -stripDirs() { - local dirs="$1" - local stripFlags="$2" - local dirsNew= - - for d in ${dirs}; do - if [ -d "$prefix/$d" ]; then - dirsNew="${dirsNew} $prefix/$d " - fi - done - dirs=${dirsNew} - - if [ -n "${dirs}" ]; then - header "stripping (with flags $stripFlags) in $dirs" - find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} strip $commonStripFlags $stripFlags || true - stopNest - fi -} - # PaX-mark binaries paxmark() { local flags="$1" @@ -357,6 +338,7 @@ paxmark() { paxctl -zex -${flags} "$@" } + ###################################################################### # Textual substitution functions. @@ -702,67 +684,6 @@ checkPhase() { } -patchShebangs() { - # Rewrite all script interpreter file names (`#! /path') under the - # specified directory tree to paths found in $PATH. E.g., - # /bin/sh will be rewritten to /nix/store/-some-bash/bin/sh. - # /usr/bin/env gets special treatment so that ".../bin/env python" is - # rewritten to /nix/store//bin/python. - # Interpreters that are already in the store are left untouched. - header "patching script interpreter paths" - local dir="$1" - local f - local oldPath - local newPath - local arg0 - local args - local oldInterpreterLine - local newInterpreterLine - - find "$dir" -type f -perm +0100 | while read f; do - if [ "$(head -1 "$f" | head -c +2)" != '#!' ]; then - # missing shebang => not a script - continue - fi - - oldInterpreterLine=$(head -1 "$f" | tail -c +3) - read -r oldPath arg0 args <<< "$oldInterpreterLine" - - if $(echo "$oldPath" | grep -q "/bin/env$"); then - # Check for unsupported 'env' functionality: - # - options: something starting with a '-' - # - environment variables: foo=bar - if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then - echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" - exit 1 - fi - newPath="$(command -v "$arg0" || true)" - else - if [ "$oldPath" = "" ]; then - # If no interpreter is specified linux will use /bin/sh. Set - # oldpath="/bin/sh" so that we get /nix/store/.../sh. - oldPath="/bin/sh" - fi - newPath="$(command -v "$(basename "$oldPath")" || true)" - args="$arg0 $args" - fi - - newInterpreterLine="$newPath $args" - - if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then - if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then - echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\"" - # escape the escape chars so that sed doesn't interpret them - escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g') - sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f" - fi - fi - done - - stopNest -} - - installPhase() { runHook preInstall @@ -838,47 +759,6 @@ fixupPhase() { } -addHook fixupOutput _defaultFixupOutput -_defaultFixupOutput() { - if [ -z "$dontGzipMan" ]; then - echo "gzipping man pages" - GLOBIGNORE=.:..:*.gz:*.bz2 - for f in "$prefix"/share/man/*/* "$prefix"/share/man/*/*/*; do - if [ -f "$f" -a ! -L "$f" ]; then - if gzip -c -n "$f" > "$f".gz; then - rm "$f" - else - rm "$f".gz - fi - fi - done - for f in "$prefix"/share/man/*/* "$prefix"/share/man/*/*/*; do - if [ -L "$f" -a -f `readlink -f "$f"`.gz ]; then - ln -sf `readlink "$f"`.gz "$f".gz && rm "$f" - fi - done - unset GLOBIGNORE - fi - - # TODO: strip _only_ ELF executables, and return || fail here... - if [ -z "$dontStrip" ]; then - stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin} - if [ -n "$stripDebugList" ]; then - stripDirs "$stripDebugList" "${stripDebugFlags:--S}" - fi - - stripAllList=${stripAllList:-} - if [ -n "$stripAllList" ]; then - stripDirs "$stripAllList" "${stripAllFlags:--s}" - fi - fi - - if [ -z "$dontPatchShebangs" ]; then - patchShebangs "$prefix" - fi -} - - installCheckPhase() { runHook preInstallCheck From 5e82aab5d4c6916fb4f35370b6f162d88bc6bf69 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 27 Jun 2014 13:40:12 +0200 Subject: [PATCH 08/23] Drop redundant space --- pkgs/build-support/setup-hooks/strip.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh index a84f7beaa5a..1815297cb6d 100644 --- a/pkgs/build-support/setup-hooks/strip.sh +++ b/pkgs/build-support/setup-hooks/strip.sh @@ -29,7 +29,7 @@ stripDirs() { dirs=${dirsNew} if [ -n "${dirs}" ]; then - header "stripping (with flags $stripFlags) in $dirs" + header "stripping (with flags $stripFlags) in$dirs" find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} strip $commonStripFlags $stripFlags || true stopNest fi From 1a44dbbbb900acb993fc68995fc3cfb50e5122ba Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 30 Jun 2014 13:21:30 +0200 Subject: [PATCH 09/23] unpackFile: Always copy directories If $src refers to a directory, then always copy it. Previously, we checked the extension first, so if the directory had an extension like .tar, unpackPhase would fail. --- pkgs/build-support/fetchzip/default.nix | 4 +-- pkgs/stdenv/generic/setup.sh | 46 ++++++++++++++----------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/pkgs/build-support/fetchzip/default.nix b/pkgs/build-support/fetchzip/default.nix index 7c6e16a0589..12fb69ba8ef 100644 --- a/pkgs/build-support/fetchzip/default.nix +++ b/pkgs/build-support/fetchzip/default.nix @@ -13,9 +13,7 @@ , ... } @ args: fetchurl ({ - # Remove the extension, because otherwise unpackPhase will get - # confused. FIXME: fix unpackPhase. - name = args.name or lib.removeSuffix ".zip" (lib.removeSuffix ".tar.gz" (baseNameOf url)); + name = args.name or (baseNameOf url); recursiveHash = true; diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 286e9e019b1..c3ebc3e9b5f 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -475,32 +475,36 @@ unpackFile() { header "unpacking source archive $curSrc" 3 - case "$curSrc" in - *.tar.xz | *.tar.lzma) - # Don't rely on tar knowing about .xz. - xz -d < $curSrc | tar xf - - ;; - *.tar | *.tar.* | *.tgz | *.tbz2) - # GNU tar can automatically select the decompression method - # (info "(tar) gzip"). - tar xf $curSrc - ;; - *.zip) - unzip -qq $curSrc - ;; - *) - if [ -d "$curSrc" ]; then - stripHash $curSrc - cp -prd --no-preserve=timestamps $curSrc $strippedName - else + if [ -d "$curSrc" ]; then + + stripHash $curSrc + cp -prd --no-preserve=timestamps $curSrc $strippedName + + else + + case "$curSrc" in + *.tar.xz | *.tar.lzma) + # Don't rely on tar knowing about .xz. + xz -d < $curSrc | tar xf - + ;; + *.tar | *.tar.* | *.tgz | *.tbz2) + # GNU tar can automatically select the decompression method + # (info "(tar) gzip"). + tar xf $curSrc + ;; + *.zip) + unzip -qq $curSrc + ;; + *) if [ -z "$unpackCmd" ]; then echo "source archive $curSrc has unknown type" exit 1 fi runSingleHook unpackCmd - fi - ;; - esac + ;; + esac + + fi stopNest } From 3e33c975fb850e903feaac4925b8e267493a6205 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 30 Jun 2014 13:48:29 +0200 Subject: [PATCH 10/23] stdenv: Make unpackFile extensible via the hook mechanism unpackCmd is now a regular hook, so there can be multiple functions hooking into it. --- pkgs/stdenv/generic/setup.sh | 49 ++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index c3ebc3e9b5f..9a756fd4723 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -23,25 +23,41 @@ runHook() { local hookName="$1" local var="_${hookName}_hooks" eval "local -a dummy=(\"\${_${hookName}_hooks[@]}\")" - for hook in "runSingleHook $hookName" "${dummy[@]}"; do + for hook in "_callImplicitHook 0 $hookName" "${dummy[@]}"; do if ! _eval "$hook"; then return 1; fi done return 0 } +# Run all hooks with the specified name, until one succeeds (returns a +# zero exit code). If none succeed, return a non-zero exit code. +runOneHook() { + local hookName="$1" + local var="_${hookName}_hooks" + eval "local -a dummy=(\"\${_${hookName}_hooks[@]}\")" + for hook in "_callImplicitHook 1 $hookName" "${dummy[@]}"; do + if _eval "$hook"; then + return 0 + fi + done + return 1 +} + + # Run the named hook, either by calling the function with that name or # by evaluating the variable with that name. This allows convenient # setting of hooks both from Nix expressions (as attributes / # environment variables) and from shell scripts (as functions). If you # want to allow multiple hooks, use runHook instead. -runSingleHook() { - local hookName="$1" +_callImplicitHook() { + local def="$1" + local hookName="$2" case "$(type -t $hookName)" in (function|alias|builtin) $hookName;; (file) source $hookName;; (keyword) :;; - (*) eval "${!hookName}";; + (*) if [ -z "${!hookName}" ]; then return "$def"; else eval "${!hookName}"; fi;; esac } @@ -469,12 +485,8 @@ stripHash() { } -unpackFile() { - curSrc="$1" - local cmd - - header "unpacking source archive $curSrc" 3 - +addHook unpackCmd _defaultUnpack +_defaultUnpack() { if [ -d "$curSrc" ]; then stripHash $curSrc @@ -496,16 +508,21 @@ unpackFile() { unzip -qq $curSrc ;; *) - if [ -z "$unpackCmd" ]; then - echo "source archive $curSrc has unknown type" - exit 1 - fi - runSingleHook unpackCmd + return 1 ;; esac fi +} + +unpackFile() { + curSrc="$1" + header "unpacking source archive $curSrc" 3 + if ! runOneHook unpackCmd; then + echo "do not know how to unpack source archive $curSrc" + exit 1 + fi stopNest } @@ -539,7 +556,7 @@ unpackPhase() { # Find the source directory. if [ -n "$setSourceRoot" ]; then - runSingleHook setSourceRoot + runOneHook setSourceRoot elif [ -z "$sourceRoot" ]; then sourceRoot= for i in *; do From f97ee61255478e9ca683d1fb7c9fd777247293cb Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 30 Jun 2014 13:57:20 +0200 Subject: [PATCH 11/23] unzip: Clean up expression --- pkgs/tools/archivers/unzip/default.nix | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/pkgs/tools/archivers/unzip/default.nix b/pkgs/tools/archivers/unzip/default.nix index f939c968c44..0f8ddb17059 100644 --- a/pkgs/tools/archivers/unzip/default.nix +++ b/pkgs/tools/archivers/unzip/default.nix @@ -1,14 +1,21 @@ { stdenv, fetchurl, bzip2 , enableNLS ? false, libnatspec }: -stdenv.mkDerivation ({ +stdenv.mkDerivation { name = "unzip-6.0"; - + src = fetchurl { url = mirror://sourceforge/infozip/unzip60.tar.gz; sha256 = "0dxx11knh3nk95p2gg2ak777dd11pr7jx5das2g49l262scrcv83"; }; + patches = stdenv.lib.optional enableNLS + (fetchurl { + url = "http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-arch/unzip/files/unzip-6.0-natspec.patch?revision=1.1"; + name = "unzip-6.0-natspec.patch"; + sha256 = "67ab260ae6adf8e7c5eda2d1d7846929b43562943ec4aff629bd7018954058b1"; + }); + nativeBuildInputs = [ bzip2 ]; buildInputs = [ bzip2 ] ++ stdenv.lib.optional enableNLS libnatspec; @@ -30,13 +37,4 @@ stdenv.mkDerivation ({ license = "free"; # http://www.info-zip.org/license.html platforms = stdenv.lib.platforms.all; }; -} // (if enableNLS then { - patches = - [ ( fetchurl { - url = - "http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-arch/unzip/files/unzip-6.0-natspec.patch?revision=1.1"; - name = "unzip-6.0-natspec.patch"; - sha256 = "67ab260ae6adf8e7c5eda2d1d7846929b43562943ec4aff629bd7018954058b1"; - }) - ]; -} else {})) +} From d7b356f73b41640f5ee741f004c4fb41e0471d30 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 30 Jun 2014 14:12:35 +0200 Subject: [PATCH 12/23] stdenv: Move unzip support to unzip's setup hook --- pkgs/stdenv/generic/setup.sh | 11 ++++------- pkgs/tools/archivers/unzip/default.nix | 2 ++ pkgs/tools/archivers/unzip/setup-hook.sh | 5 +++++ 3 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 pkgs/tools/archivers/unzip/setup-hook.sh diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 9a756fd4723..e5fdbdf2d53 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -489,23 +489,20 @@ addHook unpackCmd _defaultUnpack _defaultUnpack() { if [ -d "$curSrc" ]; then - stripHash $curSrc - cp -prd --no-preserve=timestamps $curSrc $strippedName + stripHash "$curSrc" + cp -prd --no-preserve=timestamps "$curSrc" $strippedName else case "$curSrc" in *.tar.xz | *.tar.lzma) # Don't rely on tar knowing about .xz. - xz -d < $curSrc | tar xf - + xz -d < "$curSrc" | tar xf - ;; *.tar | *.tar.* | *.tgz | *.tbz2) # GNU tar can automatically select the decompression method # (info "(tar) gzip"). - tar xf $curSrc - ;; - *.zip) - unzip -qq $curSrc + tar xf "$curSrc" ;; *) return 1 diff --git a/pkgs/tools/archivers/unzip/default.nix b/pkgs/tools/archivers/unzip/default.nix index 0f8ddb17059..7f2c81e2797 100644 --- a/pkgs/tools/archivers/unzip/default.nix +++ b/pkgs/tools/archivers/unzip/default.nix @@ -31,6 +31,8 @@ stdenv.mkDerivation { installFlags = "prefix=$(out)"; + setupHook = ./setup-hook.sh; + meta = { homepage = http://www.info-zip.org; description = "An extraction utility for archives compressed in .zip format"; diff --git a/pkgs/tools/archivers/unzip/setup-hook.sh b/pkgs/tools/archivers/unzip/setup-hook.sh new file mode 100644 index 00000000000..47894ded023 --- /dev/null +++ b/pkgs/tools/archivers/unzip/setup-hook.sh @@ -0,0 +1,5 @@ +addHook unpackCmd _tryUnzip +_tryUnzip() { + if ! [[ "foo.zip" =~ \.zip$ ]]; then return 1; fi + unzip -qq "$curSrc" +} From 9f822e5477bc32b77af39b5bf8cf50b56b97c196 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 30 Jun 2014 14:26:23 +0200 Subject: [PATCH 13/23] stdenv: Move paxmark function to paxctl's setup hook --- pkgs/os-specific/linux/paxctl/default.nix | 2 ++ pkgs/os-specific/linux/paxctl/setup-hook.sh | 8 ++++++++ pkgs/stdenv/generic/builder.sh | 1 - pkgs/stdenv/generic/default.nix | 8 +++----- pkgs/stdenv/generic/setup.sh | 19 +++---------------- 5 files changed, 16 insertions(+), 22 deletions(-) create mode 100644 pkgs/os-specific/linux/paxctl/setup-hook.sh diff --git a/pkgs/os-specific/linux/paxctl/default.nix b/pkgs/os-specific/linux/paxctl/default.nix index 8e70ddd8434..795ffa38ac4 100644 --- a/pkgs/os-specific/linux/paxctl/default.nix +++ b/pkgs/os-specific/linux/paxctl/default.nix @@ -18,6 +18,8 @@ stdenv.mkDerivation rec { "MANDIR=share/man/man1" ]; + setupHook = ./setup-hook.sh; + meta = with stdenv.lib; { description = "A tool for controlling PaX flags on a per binary basis"; homepage = "https://pax.grsecurity.net"; diff --git a/pkgs/os-specific/linux/paxctl/setup-hook.sh b/pkgs/os-specific/linux/paxctl/setup-hook.sh new file mode 100644 index 00000000000..11a6bb9910f --- /dev/null +++ b/pkgs/os-specific/linux/paxctl/setup-hook.sh @@ -0,0 +1,8 @@ +# PaX-mark binaries. +paxmark() { + local flags="$1" + shift + + paxctl -c "$@" + paxctl -zex -${flags} "$@" +} diff --git a/pkgs/stdenv/generic/builder.sh b/pkgs/stdenv/generic/builder.sh index 60360e7b825..fd4c17ca251 100644 --- a/pkgs/stdenv/generic/builder.sh +++ b/pkgs/stdenv/generic/builder.sh @@ -12,7 +12,6 @@ cat "$setup" >> $out/setup sed -e "s^@initialPath@^$initialPath^g" \ -e "s^@gcc@^$gcc^g" \ -e "s^@shell@^$shell^g" \ - -e "s^@needsPax@^$needsPax^g" \ < $out/setup > $out/setup.tmp mv $out/setup.tmp $out/setup diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index f370aec88cf..28a3c1e9f3b 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -10,8 +10,6 @@ let lib = import ../../../lib; in lib.makeOverridable ( , setupScript ? ./setup.sh , extraBuildInputs ? [] - -, skipPaxMarking ? false }: let @@ -56,9 +54,6 @@ let inherit preHook initialPath gcc shell; - # Whether we should run paxctl to pax-mark binaries - needsPax = result.isLinux && !skipPaxMarking; - propagatedUserEnvPkgs = [gcc] ++ lib.filter lib.isDerivation initialPath; } @@ -181,6 +176,9 @@ let || system == "armv6l-linux" || system == "armv7l-linux"; + # Whether we should run paxctl to pax-mark binaries. + needsPax = isLinux; + # For convenience, bring in the library functions in lib/ so # packages don't have to do that themselves. inherit lib; diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index e5fdbdf2d53..72db7dc6004 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -337,22 +337,9 @@ fi export NIX_BUILD_CORES -###################################################################### -# Misc. helper functions. - - -# PaX-mark binaries -paxmark() { - local flags="$1" - shift - - if [ -z "@needsPax@" ]; then - return - fi - - paxctl -c "$@" - paxctl -zex -${flags} "$@" -} +# Dummy implementation of the paxmark function. On Linux, this is +# overwritten by paxctl's setup hook. +paxmark() { true; } ###################################################################### From 15103e5e5fb01556e9c5758ef99d7e7f5d0f7699 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 1 Jul 2014 16:17:23 +0200 Subject: [PATCH 14/23] stdenv: Remove the special handling of gcc Now gcc is just another build input, making it possible in the future to have a stdenv that doesn't depend on a C compiler. This is very useful on NixOS, since it would allow trivial builders like writeTextFile to work without pulling in the C compiler. --- .../build-support/clang-wrapper/setup-hook.sh | 2 + pkgs/build-support/gcc-wrapper/setup-hook.sh | 2 + pkgs/stdenv/generic/builder.sh | 1 - pkgs/stdenv/generic/default.nix | 5 +- pkgs/stdenv/generic/setup.sh | 53 +++++++++---------- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/pkgs/build-support/clang-wrapper/setup-hook.sh b/pkgs/build-support/clang-wrapper/setup-hook.sh index f7687651eaf..538e6263e72 100644 --- a/pkgs/build-support/clang-wrapper/setup-hook.sh +++ b/pkgs/build-support/clang-wrapper/setup-hook.sh @@ -1,3 +1,5 @@ +export NIX_GCC=@out@ + addCVars () { if test -d $1/include; then export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include" diff --git a/pkgs/build-support/gcc-wrapper/setup-hook.sh b/pkgs/build-support/gcc-wrapper/setup-hook.sh index 298ade21d1f..ea762e9b405 100644 --- a/pkgs/build-support/gcc-wrapper/setup-hook.sh +++ b/pkgs/build-support/gcc-wrapper/setup-hook.sh @@ -1,3 +1,5 @@ +export NIX_GCC=@out@ + addCVars () { if test -d $1/include; then export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include" diff --git a/pkgs/stdenv/generic/builder.sh b/pkgs/stdenv/generic/builder.sh index fd4c17ca251..fc41976b7d1 100644 --- a/pkgs/stdenv/generic/builder.sh +++ b/pkgs/stdenv/generic/builder.sh @@ -10,7 +10,6 @@ echo "$preHook" > $out/setup cat "$setup" >> $out/setup sed -e "s^@initialPath@^$initialPath^g" \ - -e "s^@gcc@^$gcc^g" \ -e "s^@shell@^$shell^g" \ < $out/setup > $out/setup.tmp mv $out/setup.tmp $out/setup diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 28a3c1e9f3b..3d9cec05a35 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -33,6 +33,7 @@ let [ ../../build-support/setup-hooks/compress-man-pages.sh ../../build-support/setup-hooks/strip.sh ../../build-support/setup-hooks/patch-shebangs.sh + gcc ]; # The stdenv that we are producing. @@ -52,7 +53,7 @@ let setup = setupScript; - inherit preHook initialPath gcc shell; + inherit preHook initialPath shell; propagatedUserEnvPkgs = [gcc] ++ lib.filter lib.isDerivation initialPath; @@ -186,6 +187,8 @@ let inherit fetchurlBoot; inherit overrides; + + inherit gcc; } # Propagate any extra attributes. For instance, we use this to diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 72db7dc6004..675d8ce797d 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -1,3 +1,5 @@ +set -e + : ${outputs:=out} @@ -115,7 +117,7 @@ trap "exitHandler" EXIT ###################################################################### -# Helper functions that might be useful in setup hooks. +# Helper functions. addToSearchPathWithCustomDelimiter() { @@ -134,13 +136,24 @@ addToSearchPath() { } +ensureDir() { + echo "warning: ‘ensureDir’ is deprecated; use ‘mkdir’ instead" >&2 + local dir + for dir in "$@"; do + if ! [ -x "$dir" ]; then mkdir -p "$dir"; fi + done +} + + +installBin() { + mkdir -p $out/bin + cp "$@" $out/bin +} + + ###################################################################### # Initialisation. -set -e - -[ -z $NIX_GCC ] && NIX_GCC=@gcc@ - # Wildcard expansions that don't match should expand to an empty list. # This ensures that, for instance, "for i in *; do ...; done" does the @@ -150,7 +163,7 @@ shopt -s nullglob # Set up the initial path. PATH= -for i in $NIX_GCC @initialPath@; do +for i in @initialPath@; do if [ "$i" = / ]; then i=; fi addToSearchPath PATH $i/bin addToSearchPath PATH $i/sbin @@ -171,27 +184,9 @@ runHook preHook # Check that the pre-hook initialised SHELL. if [ -z "$SHELL" ]; then echo "SHELL not set"; exit 1; fi -# Hack: run gcc's setup hook. + envHooks=() crossEnvHooks=() -if [ -f $NIX_GCC/nix-support/setup-hook ]; then - source $NIX_GCC/nix-support/setup-hook -fi - - -# Ensure that the given directories exists. -ensureDir() { - echo "warning: ‘ensureDir’ is deprecated; use ‘mkdir’ instead" >&2 - local dir - for dir in "$@"; do - if ! [ -x "$dir" ]; then mkdir -p "$dir"; fi - done -} - -installBin() { - mkdir -p $out/bin - cp "$@" $out/bin -} # Allow the caller to augment buildInputs (it's not always possible to @@ -242,7 +237,7 @@ done # Set the relevant environment variables to point to the build inputs # found above. -addToNativeEnv() { +_addToNativeEnv() { local pkg=$1 if [ -d $1/bin ]; then @@ -256,10 +251,10 @@ addToNativeEnv() { } for i in $nativePkgs; do - addToNativeEnv $i + _addToNativeEnv $i done -addToCrossEnv() { +_addToCrossEnv() { local pkg=$1 # Some programs put important build scripts (freetype-config and similar) @@ -276,7 +271,7 @@ addToCrossEnv() { } for i in $crossPkgs; do - addToCrossEnv $i + _addToCrossEnv $i done From cd948c093faef02b964f15a973313129fb029613 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 1 Jul 2014 16:43:52 +0200 Subject: [PATCH 15/23] stdenv: Reindent --- pkgs/stdenv/generic/default.nix | 140 ++++++++++++++++---------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 3d9cec05a35..2c9ede898de 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -36,6 +36,73 @@ let gcc ]; + # Add a utility function to produce derivations that use this + # stdenv and its shell. + mkDerivation = attrs: + let + pos = + if attrs.meta.description or null != null then + unsafeGetAttrPos "description" attrs.meta + else + unsafeGetAttrPos "name" attrs; + pos' = if pos != null then "‘" + pos.file + ":" + toString pos.line + "’" else "«unknown-file»"; + in + if !allowUnfree + && (let l = lib.lists.toList attrs.meta.license or []; in lib.lists.elem "unfree" l || lib.lists.elem "unfree-redistributable" l) + && !allowUnfreePredicate attrs then + throw '' + Package ‘${attrs.name}’ in ${pos'} has an unfree license, refusing to evaluate. You can set + { nixpkgs.config.allowUnfree = true; } + in configuration.nix to override this. If you use Nix standalone, you can add + { allowUnfree = true; } + to ~/.nixpkgs/config.nix.'' + else if !allowBroken && attrs.meta.broken or false then + throw "you can't use package ‘${attrs.name}’ in ${pos'} because it has been marked as broken" + else if !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem result.system attrs.meta.platforms then + throw "the package ‘${attrs.name}’ in ${pos'} is not supported on ‘${result.system}’" + else + lib.addPassthru (derivation ( + (removeAttrs attrs ["meta" "passthru" "crossAttrs"]) + // (let + buildInputs = attrs.buildInputs or []; + nativeBuildInputs = attrs.nativeBuildInputs or []; + propagatedBuildInputs = attrs.propagatedBuildInputs or []; + propagatedNativeBuildInputs = attrs.propagatedNativeBuildInputs or []; + crossConfig = attrs.crossConfig or null; + in + { + builder = attrs.realBuilder or shell; + args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; + stdenv = result; + system = result.system; + userHook = config.stdenv.userHook or null; + __ignoreNulls = true; + + # Inputs built by the cross compiler. + buildInputs = lib.optionals (crossConfig != null) (buildInputs ++ extraBuildInputs'); + propagatedBuildInputs = lib.optionals (crossConfig != null) propagatedBuildInputs; + # Inputs built by the usual native compiler. + nativeBuildInputs = nativeBuildInputs ++ lib.optionals (crossConfig == null) (buildInputs ++ extraBuildInputs'); + propagatedNativeBuildInputs = propagatedNativeBuildInputs ++ + lib.optionals (crossConfig == null) propagatedBuildInputs; + }))) ( + { + # The meta attribute is passed in the resulting attribute set, + # but it's not part of the actual derivation, i.e., it's not + # passed to the builder and is not a dependency. But since we + # include it in the result, it *is* available to nix-env for + # queries. We also a meta.position attribute here to + # identify the source location of the package. + meta = attrs.meta or {} // (if pos != null then { + position = pos.file + ":" + (toString pos.line); + } else {}); + passthru = attrs.passthru or {}; + } // + # Pass through extra attributes that are not inputs, but + # should be made available to Nix expressions using the + # derivation (e.g., in assertions). + (attrs.passthru or {})); + # The stdenv that we are producing. result = @@ -61,76 +128,7 @@ let // rec { - meta = { - description = "The default build environment for Unix packages in Nixpkgs"; - }; - - # Add a utility function to produce derivations that use this - # stdenv and its shell. - mkDerivation = attrs: - let - pos = - if attrs.meta.description or null != null then - unsafeGetAttrPos "description" attrs.meta - else - unsafeGetAttrPos "name" attrs; - pos' = if pos != null then "‘" + pos.file + ":" + toString pos.line + "’" else "«unknown-file»"; - in - if !allowUnfree - && (let l = lib.lists.toList attrs.meta.license or []; in lib.lists.elem "unfree" l || lib.lists.elem "unfree-redistributable" l) - && !allowUnfreePredicate attrs then - throw '' - Package ‘${attrs.name}’ in ${pos'} has an unfree license, refusing to evaluate. You can set - { nixpkgs.config.allowUnfree = true; } - in configuration.nix to override this. If you use Nix standalone, you can add - { allowUnfree = true; } - to ~/.nixpkgs/config.nix.'' - else if !allowBroken && attrs.meta.broken or false then - throw "you can't use package ‘${attrs.name}’ in ${pos'} because it has been marked as broken" - else if !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem result.system attrs.meta.platforms then - throw "the package ‘${attrs.name}’ in ${pos'} is not supported on ‘${result.system}’" - else - lib.addPassthru (derivation ( - (removeAttrs attrs ["meta" "passthru" "crossAttrs"]) - // (let - buildInputs = attrs.buildInputs or []; - nativeBuildInputs = attrs.nativeBuildInputs or []; - propagatedBuildInputs = attrs.propagatedBuildInputs or []; - propagatedNativeBuildInputs = attrs.propagatedNativeBuildInputs or []; - crossConfig = attrs.crossConfig or null; - in - { - builder = attrs.realBuilder or shell; - args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; - stdenv = result; - system = result.system; - userHook = config.stdenv.userHook or null; - __ignoreNulls = true; - - # Inputs built by the cross compiler. - buildInputs = lib.optionals (crossConfig != null) (buildInputs ++ extraBuildInputs'); - propagatedBuildInputs = lib.optionals (crossConfig != null) propagatedBuildInputs; - # Inputs built by the usual native compiler. - nativeBuildInputs = nativeBuildInputs ++ lib.optionals (crossConfig == null) (buildInputs ++ extraBuildInputs'); - propagatedNativeBuildInputs = propagatedNativeBuildInputs ++ - lib.optionals (crossConfig == null) propagatedBuildInputs; - }))) ( - { - # The meta attribute is passed in the resulting attribute set, - # but it's not part of the actual derivation, i.e., it's not - # passed to the builder and is not a dependency. But since we - # include it in the result, it *is* available to nix-env for - # queries. We also a meta.position attribute here to - # identify the source location of the package. - meta = attrs.meta or {} // (if pos != null then { - position = pos.file + ":" + (toString pos.line); - } else {}); - passthru = attrs.passthru or {}; - } // - # Pass through extra attributes that are not inputs, but - # should be made available to Nix expressions using the - # derivation (e.g., in assertions). - (attrs.passthru or {})); + meta.description = "The default build environment for Unix packages in Nixpkgs"; # Utility flags to test the type of platform. isDarwin = system == "x86_64-darwin"; @@ -180,6 +178,8 @@ let # Whether we should run paxctl to pax-mark binaries. needsPax = isLinux; + inherit mkDerivation; + # For convenience, bring in the library functions in lib/ so # packages don't have to do that themselves. inherit lib; From be3fc3ae2f3a782226d2b8b8ec36c37f18fa12a3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 1 Jul 2014 17:21:32 +0200 Subject: [PATCH 16/23] Prevent an unnecessary evaluation of lib --- pkgs/stdenv/default.nix | 6 +++--- pkgs/stdenv/linux/default.nix | 4 +--- pkgs/stdenv/nix/default.nix | 6 +++--- pkgs/top-level/all-packages.nix | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix index 47d1fb6d9f7..e056505f1b7 100644 --- a/pkgs/stdenv/default.nix +++ b/pkgs/stdenv/default.nix @@ -5,7 +5,7 @@ # Posix utilities, the GNU C compiler, and so on. On other systems, # we use the native C library. -{ system, allPackages ? import ../.., platform, config }: +{ system, allPackages ? import ../.., platform, config, lib }: rec { @@ -28,14 +28,14 @@ rec { # The Nix build environment. stdenvNix = import ./nix { - inherit config; + inherit config lib; stdenv = stdenvNative; pkgs = stdenvNativePkgs; }; # Linux standard environment. - stdenvLinux = (import ./linux { inherit system allPackages platform config;}).stdenvLinux; + stdenvLinux = (import ./linux { inherit system allPackages platform config lib; }).stdenvLinux; # Select the appropriate stdenv for the platform `system'. diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 7169ce9f94e..d96a9483285 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -7,12 +7,10 @@ # The function defaults are for easy testing. { system ? builtins.currentSystem , allPackages ? import ../../top-level/all-packages.nix -, platform ? null, config ? {} }: +, platform ? null, config ? {}, lib }: rec { - lib = import ../../../lib; - bootstrapFiles = if system == "i686-linux" then import ./bootstrap/i686.nix else if system == "x86_64-linux" then import ./bootstrap/x86_64.nix diff --git a/pkgs/stdenv/nix/default.nix b/pkgs/stdenv/nix/default.nix index a496a819a6d..c7dd659195b 100644 --- a/pkgs/stdenv/nix/default.nix +++ b/pkgs/stdenv/nix/default.nix @@ -1,4 +1,4 @@ -{ stdenv, pkgs, config }: +{ stdenv, pkgs, config, lib }: import ../generic rec { inherit config; @@ -7,7 +7,7 @@ import ../generic rec { '' export NIX_ENFORCE_PURITY=1 export NIX_IGNORE_LD_THROUGH_GCC=1 - '' + (if stdenv.isDarwin then '' + '' + lib.optionalString stdenv.isDarwin '' export NIX_ENFORCE_PURITY= export NIX_DONT_SET_RPATH=1 export NIX_NO_SELF_RPATH=1 @@ -18,7 +18,7 @@ import ../generic rec { export SDKROOT=$(/usr/bin/xcrun --show-sdk-path 2> /dev/null || true) export NIX_CFLAGS_COMPILE+=" --sysroot=/var/empty -idirafter $SDKROOT/usr/include -F$SDKROOT/System/Library/Frameworks -Wno-multichar -Wno-deprecated-declarations" export NIX_LDFLAGS_AFTER+=" -L$SDKROOT/usr/lib" - '' else ""); + ''; initialPath = (import ../common-path.nix) {pkgs = pkgs;}; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index c7f4e270076..c3d5f802b52 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -205,7 +205,7 @@ let allStdenvs = import ../stdenv { - inherit system platform config; + inherit system platform config lib; allPackages = args: import ./all-packages.nix ({ inherit config system; } // args); }; From e3875297fac671f20feb803306e7c55789ac749e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 1 Jul 2014 17:39:07 +0200 Subject: [PATCH 17/23] stdenv: Don't use sed to build the setup script --- pkgs/stdenv/generic/builder.sh | 9 +++------ pkgs/stdenv/generic/default.nix | 5 ----- pkgs/stdenv/generic/setup.sh | 14 ++++++-------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/pkgs/stdenv/generic/builder.sh b/pkgs/stdenv/generic/builder.sh index fc41976b7d1..4fa722a73dd 100644 --- a/pkgs/stdenv/generic/builder.sh +++ b/pkgs/stdenv/generic/builder.sh @@ -6,14 +6,11 @@ done mkdir $out -echo "$preHook" > $out/setup +echo "export SHELL=$shell" > $out/setup +echo "initialPath=\"$initialPath\"" >> $out/setup +echo "$preHook" >> $out/setup cat "$setup" >> $out/setup -sed -e "s^@initialPath@^$initialPath^g" \ - -e "s^@shell@^$shell^g" \ - < $out/setup > $out/setup.tmp -mv $out/setup.tmp $out/setup - # Allow the user to install stdenv using nix-env and get the packages # in stdenv. mkdir $out/nix-support diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 2c9ede898de..0ff0bcebbd4 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -112,11 +112,6 @@ let builder = shell; args = ["-e" ./builder.sh]; - /* TODO: special-cased @var@ substitutions are ugly. - However, using substituteAll* from setup.sh seems difficult, - as setup.sh can't be directly sourced. - Suggestion: split similar utility functions into a separate script. - */ setup = setupScript; diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 675d8ce797d..6ed94673ae7 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -163,7 +163,7 @@ shopt -s nullglob # Set up the initial path. PATH= -for i in @initialPath@; do +for i in $initialPath; do if [ "$i" = / ]; then i=; fi addToSearchPath PATH $i/bin addToSearchPath PATH $i/sbin @@ -174,17 +174,15 @@ if [ "$NIX_DEBUG" = 1 ]; then fi -# Execute the pre-hook. -export SHELL=@shell@ -export CONFIG_SHELL="$SHELL" -if [ -z "$shell" ]; then export shell=@shell@; fi -runHook preHook - - # Check that the pre-hook initialised SHELL. if [ -z "$SHELL" ]; then echo "SHELL not set"; exit 1; fi +# Execute the pre-hook. +export CONFIG_SHELL="$SHELL" +if [ -z "$shell" ]; then export shell=$SHELL; fi + + envHooks=() crossEnvHooks=() From 2def8e74990d89bd91b8943c00110027a1f5fafa Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Jul 2014 13:47:09 +0200 Subject: [PATCH 18/23] Remove addHook Just use bash arrays directly. I.e. addHook preConfigure myPreConfigure is now preConfigureHooks+=(myPreConfigure) --- .../setup-hooks/compress-man-pages.sh | 2 +- .../setup-hooks/patch-shebangs.sh | 2 +- pkgs/build-support/setup-hooks/strip.sh | 2 +- .../tools/misc/patchelf/setup-hook.sh | 2 +- pkgs/stdenv/generic/setup.sh | 27 +++++++------------ pkgs/tools/archivers/unzip/setup-hook.sh | 2 +- 6 files changed, 14 insertions(+), 23 deletions(-) diff --git a/pkgs/build-support/setup-hooks/compress-man-pages.sh b/pkgs/build-support/setup-hooks/compress-man-pages.sh index 74c565ebffc..1dd9788419b 100644 --- a/pkgs/build-support/setup-hooks/compress-man-pages.sh +++ b/pkgs/build-support/setup-hooks/compress-man-pages.sh @@ -1,4 +1,4 @@ -addHook fixupOutput 'if [ -z "$dontGzipMan" ]; then compressManPages "$prefix"; fi' +fixupOutputHooks+=('if [ -z "$dontGzipMan" ]; then compressManPages "$prefix"; fi') compressManPages() { local dir="$1" diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh index 6b42291358d..5a7f23b2d81 100644 --- a/pkgs/build-support/setup-hooks/patch-shebangs.sh +++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh @@ -5,7 +5,7 @@ # rewritten to /nix/store//bin/python. Interpreters that are # already in the store are left untouched. -addHook fixupOutput 'if [ -z "$dontPatchShebangs" ]; then patchShebangs "$prefix"; fi' +fixupOutputHooks+=('if [ -z "$dontPatchShebangs" ]; then patchShebangs "$prefix"; fi') patchShebangs() { local dir="$1" diff --git a/pkgs/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh index 1815297cb6d..6860c9b9cb9 100644 --- a/pkgs/build-support/setup-hooks/strip.sh +++ b/pkgs/build-support/setup-hooks/strip.sh @@ -1,6 +1,6 @@ # This setup hook strips libraries and executables in the fixup phase. -addHook fixupOutput _doStrip +fixupOutputHooks+=(_doStrip) _doStrip() { if [ -z "$dontStrip" ]; then diff --git a/pkgs/development/tools/misc/patchelf/setup-hook.sh b/pkgs/development/tools/misc/patchelf/setup-hook.sh index 6bc918a4610..b0d37b73e2b 100644 --- a/pkgs/development/tools/misc/patchelf/setup-hook.sh +++ b/pkgs/development/tools/misc/patchelf/setup-hook.sh @@ -2,7 +2,7 @@ # directories from the RPATH of every library or executable in every # output. -addHook fixupOutput 'if [ -z "$dontPatchELF" ]; then patchELF "$prefix"; fi' +fixupOutputHooks+=('if [ -z "$dontPatchELF" ]; then patchELF "$prefix"; fi') patchELF() { header "patching ELF executables and libraries in $prefix" diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 6ed94673ae7..cdebf6e4b27 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -7,24 +7,15 @@ set -e # Hook handling. -# Add the specified shell code to the named hook, e.g. ‘addHook -# preConfigure "rm ./foo; touch ./bar"’. -addHook() { - local hookName="$1" - local hookCode="$2" - eval "_${hookName}_hooks+=(\"\$hookCode\")" -} - - # Run all hooks with the specified name in the order in which they # were added, stopping if any fails (returns a non-zero exit -# code). Hooks are added using ‘addHooks ’, or -# implicitly by defining a shell function or variable . Note -# that the latter takes precedence over hooks added via ‘addHooks’. +# code). The hooks for are the shell function or variable +# , and the values of the shell array ‘Hooks’. runHook() { local hookName="$1" - local var="_${hookName}_hooks" - eval "local -a dummy=(\"\${_${hookName}_hooks[@]}\")" + local var="$hookName" + if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi + eval "local -a dummy=(\"\${$var[@]}\")" for hook in "_callImplicitHook 0 $hookName" "${dummy[@]}"; do if ! _eval "$hook"; then return 1; fi done @@ -36,8 +27,9 @@ runHook() { # zero exit code). If none succeed, return a non-zero exit code. runOneHook() { local hookName="$1" - local var="_${hookName}_hooks" - eval "local -a dummy=(\"\${_${hookName}_hooks[@]}\")" + local var="$hookName" + if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi + eval "local -a dummy=(\"\${$var[@]}\")" for hook in "_callImplicitHook 1 $hookName" "${dummy[@]}"; do if _eval "$hook"; then return 0 @@ -465,7 +457,7 @@ stripHash() { } -addHook unpackCmd _defaultUnpack +unpackCmdHooks+=(_defaultUnpack) _defaultUnpack() { if [ -d "$curSrc" ]; then @@ -856,7 +848,6 @@ genericBuild() { # Execute the post-hooks. -for i in "${postHooks[@]}"; do $i; done runHook postHook diff --git a/pkgs/tools/archivers/unzip/setup-hook.sh b/pkgs/tools/archivers/unzip/setup-hook.sh index 47894ded023..4cad0fe7e91 100644 --- a/pkgs/tools/archivers/unzip/setup-hook.sh +++ b/pkgs/tools/archivers/unzip/setup-hook.sh @@ -1,4 +1,4 @@ -addHook unpackCmd _tryUnzip +unpackCmdHooks+=(_tryUnzip) _tryUnzip() { if ! [[ "foo.zip" =~ \.zip$ ]]; then return 1; fi unzip -qq "$curSrc" From 11dc9036d0b1f7bb9e277240848e699c0de90d4e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Jul 2014 14:14:28 +0200 Subject: [PATCH 19/23] Allow passing arguments to hooks This allows envHooks and crossEnvHooks to be handled using the regular hook mechanism. --- pkgs/stdenv/generic/setup.sh | 41 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index cdebf6e4b27..daba3b5db41 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -13,11 +13,12 @@ set -e # , and the values of the shell array ‘Hooks’. runHook() { local hookName="$1" + shift local var="$hookName" if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi eval "local -a dummy=(\"\${$var[@]}\")" for hook in "_callImplicitHook 0 $hookName" "${dummy[@]}"; do - if ! _eval "$hook"; then return 1; fi + if ! _eval "$hook" "$@"; then return 1; fi done return 0 } @@ -27,11 +28,12 @@ runHook() { # zero exit code). If none succeed, return a non-zero exit code. runOneHook() { local hookName="$1" + shift local var="$hookName" if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi eval "local -a dummy=(\"\${$var[@]}\")" for hook in "_callImplicitHook 1 $hookName" "${dummy[@]}"; do - if _eval "$hook"; then + if _eval "$hook" "$@"; then return 0 fi done @@ -60,7 +62,12 @@ _callImplicitHook() { # hooks exits the hook, not the caller. _eval() { local code="$1" - eval "$code" + shift + if [ "$(type -t $code)" = function ]; then + eval "$code \"\$@\"" + else + eval "$code" + fi } @@ -175,10 +182,6 @@ export CONFIG_SHELL="$SHELL" if [ -z "$shell" ]; then export shell=$SHELL; fi -envHooks=() -crossEnvHooks=() - - # Allow the caller to augment buildInputs (it's not always possible to # do this before the call to setup.sh, since the PATH is empty at that # point; here we have a basic Unix environment). @@ -235,9 +238,7 @@ _addToNativeEnv() { fi # Run the package-specific hooks set by the setup-hook scripts. - for i in "${envHooks[@]}"; do - $i $pkg - done + runHook envHook "$pkg" } for i in $nativePkgs; do @@ -255,9 +256,7 @@ _addToCrossEnv() { fi # Run the package-specific hooks set by the setup-hook scripts. - for i in "${crossEnvHooks[@]}"; do - $i $pkg - done + runHook crossEnvHook "$pkg" } for i in $crossPkgs; do @@ -459,22 +458,24 @@ stripHash() { unpackCmdHooks+=(_defaultUnpack) _defaultUnpack() { - if [ -d "$curSrc" ]; then + local fn="$1" - stripHash "$curSrc" - cp -prd --no-preserve=timestamps "$curSrc" $strippedName + if [ -d "$fn" ]; then + + stripHash "$fn" + cp -prd --no-preserve=timestamps "$fn" $strippedName else - case "$curSrc" in + case "$fn" in *.tar.xz | *.tar.lzma) # Don't rely on tar knowing about .xz. - xz -d < "$curSrc" | tar xf - + xz -d < "$fn" | tar xf - ;; *.tar | *.tar.* | *.tgz | *.tbz2) # GNU tar can automatically select the decompression method # (info "(tar) gzip"). - tar xf "$curSrc" + tar xf "$fn" ;; *) return 1 @@ -488,7 +489,7 @@ _defaultUnpack() { unpackFile() { curSrc="$1" header "unpacking source archive $curSrc" 3 - if ! runOneHook unpackCmd; then + if ! runOneHook unpackCmd "$curSrc"; then echo "do not know how to unpack source archive $curSrc" exit 1 fi From 2db867eec9f09648cae4c6e4ab8e4eae4cfc98f1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Jul 2014 14:15:44 +0200 Subject: [PATCH 20/23] fixupPhase: Fix making the outputs writable --- pkgs/stdenv/generic/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index daba3b5db41..ebacb9952fc 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -696,7 +696,7 @@ installPhase() { fixupPhase() { # Make sure everything is writable so "strip" et al. work. for output in $outputs; do - if [ -e "$output" ]; then chmod -R u+w "$output"; fi + if [ -e "${!output}" ]; then chmod -R u+w "${!output}"; fi done runHook preFixup From e3f7dbbac800124baa26317fcf792fe08f140655 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Jul 2014 14:20:05 +0200 Subject: [PATCH 21/23] Cleanup: Use += to append to envHooks --- pkgs/applications/science/math/R/setup-hook.sh | 2 +- pkgs/build-support/clang-wrapper/setup-hook.sh | 2 +- pkgs/build-support/gcc-cross-wrapper/setup-hook.sh | 2 +- pkgs/build-support/gcc-wrapper/setup-hook.sh | 2 +- pkgs/build-support/setup-hooks/set-java-classpath.sh | 2 +- pkgs/desktops/e17/e_dbus/setup-hook.sh | 2 +- pkgs/development/interpreters/guile/setup-hook-2.0.sh | 2 +- pkgs/development/interpreters/guile/setup-hook.sh | 2 +- pkgs/development/interpreters/perl/5.10/setup-hook.sh | 2 +- pkgs/development/interpreters/perl/5.14/setup-hook.sh | 2 +- pkgs/development/interpreters/perl/5.16/setup-hook.sh | 2 +- pkgs/development/interpreters/perl/5.20/setup-hook.sh | 2 +- pkgs/development/interpreters/perl/5.8/setup-hook.sh | 2 +- pkgs/development/interpreters/perl/sys-perl/setup-hook.sh | 2 +- pkgs/development/interpreters/pypy/2.3/setup-hook.sh | 2 +- pkgs/development/interpreters/python/2.6/setup-hook.sh | 2 +- pkgs/development/interpreters/python/2.7/setup-hook.sh | 2 +- pkgs/development/interpreters/python/3.2/setup-hook.sh | 2 +- pkgs/development/interpreters/python/3.3/setup-hook.sh | 2 +- pkgs/development/interpreters/python/3.4/setup-hook.sh | 2 +- pkgs/development/libraries/gstreamer/core/setup-hook.sh | 2 +- .../libraries/gstreamer/legacy/gstreamer/setup-hook.sh | 2 +- pkgs/development/libraries/libxml2/setup-hook.sh | 2 +- pkgs/development/libraries/slib/setup-hook.sh | 2 +- pkgs/development/lisp-modules/clwrapper/setup-hook.sh | 2 +- pkgs/development/ocaml-modules/ocamlmake/setup-hook.sh | 2 +- pkgs/development/tools/misc/automake/setup-hook.sh | 2 +- pkgs/development/tools/misc/pkgconfig/setup-hook.sh | 4 ++-- pkgs/development/tools/ocaml/findlib/default.nix | 4 ++-- pkgs/development/web/nodejs/setup-hook.sh | 2 +- pkgs/tools/text/sgml/opensp/setup-hook.sh | 2 +- pkgs/tools/typesetting/tex/tetex/setup-hook.sh | 2 +- pkgs/tools/typesetting/tex/texlive/setup-hook.sh | 2 +- 33 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pkgs/applications/science/math/R/setup-hook.sh b/pkgs/applications/science/math/R/setup-hook.sh index a31289bbfba..09a775db9bf 100644 --- a/pkgs/applications/science/math/R/setup-hook.sh +++ b/pkgs/applications/science/math/R/setup-hook.sh @@ -2,4 +2,4 @@ addRLibPath () { addToSearchPath R_LIBS_SITE $1/library } -envHooks=(${envHooks[@]} addRLibPath) +envHooks+=(addRLibPath) diff --git a/pkgs/build-support/clang-wrapper/setup-hook.sh b/pkgs/build-support/clang-wrapper/setup-hook.sh index 538e6263e72..0bd531050c4 100644 --- a/pkgs/build-support/clang-wrapper/setup-hook.sh +++ b/pkgs/build-support/clang-wrapper/setup-hook.sh @@ -14,7 +14,7 @@ addCVars () { fi } -envHooks=(${envHooks[@]} addCVars) +envHooks+=(addCVars) # Note: these come *after* $out in the PATH (see setup.sh). diff --git a/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh b/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh index 433d36ced43..ce5f6e56136 100644 --- a/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh +++ b/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh @@ -11,7 +11,7 @@ crossAddCVars () { fi } -crossEnvHooks=(${crossEnvHooks[@]} crossAddCVars) +crossEnvHooks+=(crossAddCVars) crossStripDirs() { local dirs="$1" diff --git a/pkgs/build-support/gcc-wrapper/setup-hook.sh b/pkgs/build-support/gcc-wrapper/setup-hook.sh index ea762e9b405..a3ada9e984f 100644 --- a/pkgs/build-support/gcc-wrapper/setup-hook.sh +++ b/pkgs/build-support/gcc-wrapper/setup-hook.sh @@ -14,7 +14,7 @@ addCVars () { fi } -envHooks=(${envHooks[@]} addCVars) +envHooks+=(addCVars) # Note: these come *after* $out in the PATH (see setup.sh). diff --git a/pkgs/build-support/setup-hooks/set-java-classpath.sh b/pkgs/build-support/setup-hooks/set-java-classpath.sh index 76e8e42ca26..047da91bc97 100644 --- a/pkgs/build-support/setup-hooks/set-java-classpath.sh +++ b/pkgs/build-support/setup-hooks/set-java-classpath.sh @@ -10,4 +10,4 @@ addPkgToClassPath () { done } -envHooks=(''${envHooks[@]} addPkgToClassPath) +envHooks+=(addPkgToClassPath) diff --git a/pkgs/desktops/e17/e_dbus/setup-hook.sh b/pkgs/desktops/e17/e_dbus/setup-hook.sh index d98f24b4c04..33e3a6b0f18 100644 --- a/pkgs/desktops/e17/e_dbus/setup-hook.sh +++ b/pkgs/desktops/e17/e_dbus/setup-hook.sh @@ -5,4 +5,4 @@ addDbusIncludePath () { fi } -envHooks=(${envHooks[@]} addDbusIncludePath) +envHooks+=(addDbusIncludePath) diff --git a/pkgs/development/interpreters/guile/setup-hook-2.0.sh b/pkgs/development/interpreters/guile/setup-hook-2.0.sh index 6994c4cd8dc..fd1dc944ed4 100644 --- a/pkgs/development/interpreters/guile/setup-hook-2.0.sh +++ b/pkgs/development/interpreters/guile/setup-hook-2.0.sh @@ -10,4 +10,4 @@ addGuileLibPath () { fi } -envHooks=(${envHooks[@]} addGuileLibPath) +envHooks+=(addGuileLibPath) diff --git a/pkgs/development/interpreters/guile/setup-hook.sh b/pkgs/development/interpreters/guile/setup-hook.sh index 87cb5118506..c1d19e579ed 100644 --- a/pkgs/development/interpreters/guile/setup-hook.sh +++ b/pkgs/development/interpreters/guile/setup-hook.sh @@ -5,4 +5,4 @@ addGuileLibPath () { fi } -envHooks=(${envHooks[@]} addGuileLibPath) +envHooks+=(addGuileLibPath) diff --git a/pkgs/development/interpreters/perl/5.10/setup-hook.sh b/pkgs/development/interpreters/perl/5.10/setup-hook.sh index 6a144a7f780..a8656b8531d 100644 --- a/pkgs/development/interpreters/perl/5.10/setup-hook.sh +++ b/pkgs/development/interpreters/perl/5.10/setup-hook.sh @@ -2,4 +2,4 @@ addPerlLibPath () { addToSearchPath PERL5LIB $1/lib/perl5/site_perl } -envHooks=(${envHooks[@]} addPerlLibPath) +envHooks+=(addPerlLibPath) diff --git a/pkgs/development/interpreters/perl/5.14/setup-hook.sh b/pkgs/development/interpreters/perl/5.14/setup-hook.sh index 6a144a7f780..a8656b8531d 100644 --- a/pkgs/development/interpreters/perl/5.14/setup-hook.sh +++ b/pkgs/development/interpreters/perl/5.14/setup-hook.sh @@ -2,4 +2,4 @@ addPerlLibPath () { addToSearchPath PERL5LIB $1/lib/perl5/site_perl } -envHooks=(${envHooks[@]} addPerlLibPath) +envHooks+=(addPerlLibPath) diff --git a/pkgs/development/interpreters/perl/5.16/setup-hook.sh b/pkgs/development/interpreters/perl/5.16/setup-hook.sh index 6a144a7f780..a8656b8531d 100644 --- a/pkgs/development/interpreters/perl/5.16/setup-hook.sh +++ b/pkgs/development/interpreters/perl/5.16/setup-hook.sh @@ -2,4 +2,4 @@ addPerlLibPath () { addToSearchPath PERL5LIB $1/lib/perl5/site_perl } -envHooks=(${envHooks[@]} addPerlLibPath) +envHooks+=(addPerlLibPath) diff --git a/pkgs/development/interpreters/perl/5.20/setup-hook.sh b/pkgs/development/interpreters/perl/5.20/setup-hook.sh index 6a144a7f780..a8656b8531d 100644 --- a/pkgs/development/interpreters/perl/5.20/setup-hook.sh +++ b/pkgs/development/interpreters/perl/5.20/setup-hook.sh @@ -2,4 +2,4 @@ addPerlLibPath () { addToSearchPath PERL5LIB $1/lib/perl5/site_perl } -envHooks=(${envHooks[@]} addPerlLibPath) +envHooks+=(addPerlLibPath) diff --git a/pkgs/development/interpreters/perl/5.8/setup-hook.sh b/pkgs/development/interpreters/perl/5.8/setup-hook.sh index d61ec82f4f0..75a394c3c0a 100644 --- a/pkgs/development/interpreters/perl/5.8/setup-hook.sh +++ b/pkgs/development/interpreters/perl/5.8/setup-hook.sh @@ -2,4 +2,4 @@ addPerlLibPath () { addToSearchPath PERL5LIB $1/lib/site_perl } -envHooks=(${envHooks[@]} addPerlLibPath) +envHooks+=(addPerlLibPath) diff --git a/pkgs/development/interpreters/perl/sys-perl/setup-hook.sh b/pkgs/development/interpreters/perl/sys-perl/setup-hook.sh index a46a19602e7..7b03c15ec5a 100644 --- a/pkgs/development/interpreters/perl/sys-perl/setup-hook.sh +++ b/pkgs/development/interpreters/perl/sys-perl/setup-hook.sh @@ -2,4 +2,4 @@ addPerlLibPath () { addToSearchPath PERL5LIB $1/@libPrefix@ } -envHooks=(${envHooks[@]} addPerlLibPath) +envHooks+=(addPerlLibPath) diff --git a/pkgs/development/interpreters/pypy/2.3/setup-hook.sh b/pkgs/development/interpreters/pypy/2.3/setup-hook.sh index 67c71bf0081..7d325828d0e 100644 --- a/pkgs/development/interpreters/pypy/2.3/setup-hook.sh +++ b/pkgs/development/interpreters/pypy/2.3/setup-hook.sh @@ -12,4 +12,4 @@ toPythonPath() { echo $result } -envHooks=(${envHooks[@]} addPythonPath) +envHooks+=(addPythonPath) diff --git a/pkgs/development/interpreters/python/2.6/setup-hook.sh b/pkgs/development/interpreters/python/2.6/setup-hook.sh index 290525c3571..4caff9c9d84 100644 --- a/pkgs/development/interpreters/python/2.6/setup-hook.sh +++ b/pkgs/development/interpreters/python/2.6/setup-hook.sh @@ -12,4 +12,4 @@ toPythonPath() { echo $result } -envHooks=(${envHooks[@]} addPythonPath) +envHooks+=(addPythonPath) diff --git a/pkgs/development/interpreters/python/2.7/setup-hook.sh b/pkgs/development/interpreters/python/2.7/setup-hook.sh index a393b70afe1..4770eea886f 100644 --- a/pkgs/development/interpreters/python/2.7/setup-hook.sh +++ b/pkgs/development/interpreters/python/2.7/setup-hook.sh @@ -12,4 +12,4 @@ toPythonPath() { echo $result } -envHooks=(${envHooks[@]} addPythonPath) +envHooks+=(addPythonPath) diff --git a/pkgs/development/interpreters/python/3.2/setup-hook.sh b/pkgs/development/interpreters/python/3.2/setup-hook.sh index e6fa34bf54b..e8215ef9877 100644 --- a/pkgs/development/interpreters/python/3.2/setup-hook.sh +++ b/pkgs/development/interpreters/python/3.2/setup-hook.sh @@ -12,4 +12,4 @@ toPythonPath() { echo $result } -envHooks=(${envHooks[@]} addPythonPath) +envHooks+=(addPythonPath) diff --git a/pkgs/development/interpreters/python/3.3/setup-hook.sh b/pkgs/development/interpreters/python/3.3/setup-hook.sh index c272c87daf1..82a8c0abd32 100644 --- a/pkgs/development/interpreters/python/3.3/setup-hook.sh +++ b/pkgs/development/interpreters/python/3.3/setup-hook.sh @@ -12,4 +12,4 @@ toPythonPath() { echo $result } -envHooks=(${envHooks[@]} addPythonPath) +envHooks+=(addPythonPath) diff --git a/pkgs/development/interpreters/python/3.4/setup-hook.sh b/pkgs/development/interpreters/python/3.4/setup-hook.sh index ae71b4147ab..fddcc0b73fe 100644 --- a/pkgs/development/interpreters/python/3.4/setup-hook.sh +++ b/pkgs/development/interpreters/python/3.4/setup-hook.sh @@ -12,4 +12,4 @@ toPythonPath() { echo $result } -envHooks=(${envHooks[@]} addPythonPath) +envHooks+=(addPythonPath) diff --git a/pkgs/development/libraries/gstreamer/core/setup-hook.sh b/pkgs/development/libraries/gstreamer/core/setup-hook.sh index 04863ab3b61..3dd7812ece6 100644 --- a/pkgs/development/libraries/gstreamer/core/setup-hook.sh +++ b/pkgs/development/libraries/gstreamer/core/setup-hook.sh @@ -5,5 +5,5 @@ addGstreamer1LibPath () { fi } -envHooks=(${envHooks[@]} addGstreamer1LibPath) +envHooks+=(addGstreamer1LibPath) diff --git a/pkgs/development/libraries/gstreamer/legacy/gstreamer/setup-hook.sh b/pkgs/development/libraries/gstreamer/legacy/gstreamer/setup-hook.sh index 10671f9d227..e89aeda5bc1 100644 --- a/pkgs/development/libraries/gstreamer/legacy/gstreamer/setup-hook.sh +++ b/pkgs/development/libraries/gstreamer/legacy/gstreamer/setup-hook.sh @@ -5,4 +5,4 @@ addGstreamerLibPath () { fi } -envHooks=(${envHooks[@]} addGstreamerLibPath) +envHooks+=(addGstreamerLibPath) diff --git a/pkgs/development/libraries/libxml2/setup-hook.sh b/pkgs/development/libraries/libxml2/setup-hook.sh index 112dbe0c513..f9fc633c7da 100644 --- a/pkgs/development/libraries/libxml2/setup-hook.sh +++ b/pkgs/development/libraries/libxml2/setup-hook.sh @@ -23,5 +23,5 @@ if test -z "$libxmlHookDone"; then # xmllint and xsltproc from looking in /etc/xml/catalog. export XML_CATALOG_FILES if test -z "$XML_CATALOG_FILES"; then XML_CATALOG_FILES=" "; fi - envHooks=(${envHooks[@]} addXMLCatalogs) + envHooks+=(addXMLCatalogs) fi diff --git a/pkgs/development/libraries/slib/setup-hook.sh b/pkgs/development/libraries/slib/setup-hook.sh index 32dde7d1f7a..62b72d6dc0a 100644 --- a/pkgs/development/libraries/slib/setup-hook.sh +++ b/pkgs/development/libraries/slib/setup-hook.sh @@ -10,4 +10,4 @@ addSlibPath () { fi } -envHooks=(${envHooks[@]} addSlibPath) +envHooks+=(addSlibPath) diff --git a/pkgs/development/lisp-modules/clwrapper/setup-hook.sh b/pkgs/development/lisp-modules/clwrapper/setup-hook.sh index e5deb47fd5d..b48f916ac7a 100644 --- a/pkgs/development/lisp-modules/clwrapper/setup-hook.sh +++ b/pkgs/development/lisp-modules/clwrapper/setup-hook.sh @@ -33,7 +33,7 @@ collectNixLispLDLP () { export NIX_LISP_COMMAND NIX_LISP CL_SOURCE_REGISTRY NIX_LISP_ASDF -envHooks=(envHooks[@] addASDFPaths setLisp collectNixLispLDLP) +envHooks+=(addASDFPaths setLisp collectNixLispLDLP) mkdir -p "$HOME"/.cache/common-lisp || HOME="$TMP/.temp-$USER-home" mkdir -p "$HOME"/.cache/common-lisp diff --git a/pkgs/development/ocaml-modules/ocamlmake/setup-hook.sh b/pkgs/development/ocaml-modules/ocamlmake/setup-hook.sh index 876556a7b92..a93a7250beb 100644 --- a/pkgs/development/ocaml-modules/ocamlmake/setup-hook.sh +++ b/pkgs/development/ocaml-modules/ocamlmake/setup-hook.sh @@ -2,4 +2,4 @@ addOcamlMakefile () { export OCAMLMAKEFILE="@out@/include/OCamlMakefile" } -envHooks=(${envHooks[@]} addOcamlMakefile) +envHooks+=(addOcamlMakefile) diff --git a/pkgs/development/tools/misc/automake/setup-hook.sh b/pkgs/development/tools/misc/automake/setup-hook.sh index 6f34f0d0ae1..5cd8c6229f6 100644 --- a/pkgs/development/tools/misc/automake/setup-hook.sh +++ b/pkgs/development/tools/misc/automake/setup-hook.sh @@ -2,4 +2,4 @@ addAclocals () { addToSearchPathWithCustomDelimiter : ACLOCAL_PATH $1/share/aclocal } -envHooks=(${envHooks[@]} addAclocals) +envHooks+=(addAclocals) diff --git a/pkgs/development/tools/misc/pkgconfig/setup-hook.sh b/pkgs/development/tools/misc/pkgconfig/setup-hook.sh index 77a69fb1878..1c153976a34 100644 --- a/pkgs/development/tools/misc/pkgconfig/setup-hook.sh +++ b/pkgs/development/tools/misc/pkgconfig/setup-hook.sh @@ -4,7 +4,7 @@ addPkgConfigPath () { } if test -n "$crossConfig"; then - crossEnvHooks=(${crossEnvHooks[@]} addPkgConfigPath) + crossEnvHooks+=(addPkgConfigPath) else - envHooks=(${envHooks[@]} addPkgConfigPath) + envHooks+=(addPkgConfigPath) fi diff --git a/pkgs/development/tools/ocaml/findlib/default.nix b/pkgs/development/tools/ocaml/findlib/default.nix index 4c0176de7e8..cfbabad72cc 100644 --- a/pkgs/development/tools/ocaml/findlib/default.nix +++ b/pkgs/development/tools/ocaml/findlib/default.nix @@ -42,8 +42,8 @@ stdenv.mkDerivation { mkdir -p $OCAMLFIND_DESTDIR fi } - - envHooks=(''${envHooks[@]} addOCamlPath) + + envHooks+=(addOCamlPath) ''; meta = { diff --git a/pkgs/development/web/nodejs/setup-hook.sh b/pkgs/development/web/nodejs/setup-hook.sh index 41a9746ba42..e1f4d9089f3 100644 --- a/pkgs/development/web/nodejs/setup-hook.sh +++ b/pkgs/development/web/nodejs/setup-hook.sh @@ -2,4 +2,4 @@ addNodePath () { addToSearchPath NODE_PATH $1/lib/node_modules } -envHooks=(${envHooks[@]} addNodePath) +envHooks+=(addNodePath) diff --git a/pkgs/tools/text/sgml/opensp/setup-hook.sh b/pkgs/tools/text/sgml/opensp/setup-hook.sh index 2c9142da101..52da517a8cb 100644 --- a/pkgs/tools/text/sgml/opensp/setup-hook.sh +++ b/pkgs/tools/text/sgml/opensp/setup-hook.sh @@ -18,5 +18,5 @@ if test -z "$sgmlHookDone"; then export ftp_proxy=http://nodtd.invalid/ export SGML_CATALOG_FILES - envHooks=(${envHooks[@]} addSGMLCatalogs) + envHooks+=(addSGMLCatalogs) fi diff --git a/pkgs/tools/typesetting/tex/tetex/setup-hook.sh b/pkgs/tools/typesetting/tex/tetex/setup-hook.sh index d79c4fae419..9c5424e881e 100644 --- a/pkgs/tools/typesetting/tex/tetex/setup-hook.sh +++ b/pkgs/tools/typesetting/tex/tetex/setup-hook.sh @@ -4,4 +4,4 @@ addTeXMFPath () { fi } -envHooks=(${envHooks[@]} addTeXMFPath) +envHooks+=(addTeXMFPath) diff --git a/pkgs/tools/typesetting/tex/texlive/setup-hook.sh b/pkgs/tools/typesetting/tex/texlive/setup-hook.sh index d79c4fae419..9c5424e881e 100644 --- a/pkgs/tools/typesetting/tex/texlive/setup-hook.sh +++ b/pkgs/tools/typesetting/tex/texlive/setup-hook.sh @@ -4,4 +4,4 @@ addTeXMFPath () { fi } -envHooks=(${envHooks[@]} addTeXMFPath) +envHooks+=(addTeXMFPath) From 9e31c66d1b4e71c5e09719931d77c794a9608acb Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Jul 2014 14:26:35 +0200 Subject: [PATCH 22/23] stdenv: Put moving docs to $out/share in a separate setup hook --- pkgs/build-support/setup-hooks/move-docs.sh | 24 +++++++++++++++++++++ pkgs/stdenv/generic/default.nix | 3 ++- pkgs/stdenv/generic/setup.sh | 19 ---------------- 3 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 pkgs/build-support/setup-hooks/move-docs.sh diff --git a/pkgs/build-support/setup-hooks/move-docs.sh b/pkgs/build-support/setup-hooks/move-docs.sh new file mode 100644 index 00000000000..b3b93193550 --- /dev/null +++ b/pkgs/build-support/setup-hooks/move-docs.sh @@ -0,0 +1,24 @@ +# This setup hook automatically moves $out/{man,doc,info} to +# $out/share. + +preFixupHooks+=(_moveDocs) + +_moveDocs() { + forceShare=${forceShare:=man doc info} + if [ -z "$forceShare" ]; then return; fi + + for d in $forceShare; do + if [ -d "$prefix/$d" ]; then + if [ -d "$prefix/share/$d" ]; then + echo "both $d/ and share/$d/ exist!" + else + echo "moving $prefix/$d to $prefix/share/$d" + mkdir -p $prefix/share + if [ -w $prefix/share ]; then + mv $prefix/$d $prefix/share + ln -s share/$d $prefix + fi + fi + fi + done +} diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 0ff0bcebbd4..5b3cfdc2c44 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -30,7 +30,8 @@ let unsafeGetAttrPos = builtins.unsafeGetAttrPos or (n: as: null); extraBuildInputs' = extraBuildInputs ++ - [ ../../build-support/setup-hooks/compress-man-pages.sh + [ ../../build-support/setup-hooks/move-docs.sh + ../../build-support/setup-hooks/compress-man-pages.sh ../../build-support/setup-hooks/strip.sh ../../build-support/setup-hooks/patch-shebangs.sh gcc diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index ebacb9952fc..ea2ea947b50 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -701,25 +701,6 @@ fixupPhase() { runHook preFixup - # Put man/doc/info under $out/share. - forceShare=${forceShare:=man doc info} - if [ -n "$forceShare" ]; then - for d in $forceShare; do - if [ -d "$prefix/$d" ]; then - if [ -d "$prefix/share/$d" ]; then - echo "both $d/ and share/$d/ exists!" - else - echo "fixing location of $d/ subdirectory" - mkdir -p $prefix/share - if [ -w $prefix/share ]; then - mv -v $prefix/$d $prefix/share - ln -sv share/$d $prefix - fi - fi - fi - done; - fi - # Apply fixup to each output. local output for output in $outputs; do From a8fc68a5c02488a2228a1dc4984a3fa6351002eb Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Jul 2014 15:33:15 +0200 Subject: [PATCH 23/23] Move share/{man,info,doc} to the corresponding output --- pkgs/build-support/setup-hooks/move-docs.sh | 50 ++++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/pkgs/build-support/setup-hooks/move-docs.sh b/pkgs/build-support/setup-hooks/move-docs.sh index b3b93193550..c819ee12a9c 100644 --- a/pkgs/build-support/setup-hooks/move-docs.sh +++ b/pkgs/build-support/setup-hooks/move-docs.sh @@ -1,24 +1,50 @@ -# This setup hook automatically moves $out/{man,doc,info} to -# $out/share. +# This setup hook moves $out/{man,doc,info} to $out/share; moves +# $out/share/man to $man/share/man; and moves $out/share/doc to +# $man/share/doc. preFixupHooks+=(_moveDocs) -_moveDocs() { +_moveToShare() { forceShare=${forceShare:=man doc info} - if [ -z "$forceShare" ]; then return; fi + if [ -z "$forceShare" -o -z "$out" ]; then return; fi for d in $forceShare; do - if [ -d "$prefix/$d" ]; then - if [ -d "$prefix/share/$d" ]; then + if [ -d "$out/$d" ]; then + if [ -d "$out/share/$d" ]; then echo "both $d/ and share/$d/ exist!" else - echo "moving $prefix/$d to $prefix/share/$d" - mkdir -p $prefix/share - if [ -w $prefix/share ]; then - mv $prefix/$d $prefix/share - ln -s share/$d $prefix - fi + echo "moving $out/$d to $out/share/$d" + mkdir -p $out/share + mv $out/$d $out/share/ fi fi done } + +_moveToOutput() { + local d="$1" + local dst="$2" + if [ -z "$dst" -a ! -e $dst/$d ]; then return; fi + local output + for output in $outputs; do + if [ "${!output}" = "$dst" ]; then continue; fi + if [ -d "${!output}/$d" ]; then + echo "moving ${!output}/$d to $dst/$d" + mkdir -p $dst/share + mv ${!output}/$d $dst/$d + break + fi + done +} + +_moveDocs() { + _moveToShare + _moveToOutput share/man "$man" + _moveToOutput share/info "$info" + _moveToOutput share/doc "$doc" + + # Remove empty share directory. + if [ -d "$out/share" ]; then + rmdir $out/share 2> /dev/null || true + fi +}