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 f7687651eaf..0bd531050c4 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" @@ -12,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/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/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 298ade21d1f..a3ada9e984f 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" @@ -12,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/compress-man-pages.sh b/pkgs/build-support/setup-hooks/compress-man-pages.sh new file mode 100644 index 00000000000..1dd9788419b --- /dev/null +++ b/pkgs/build-support/setup-hooks/compress-man-pages.sh @@ -0,0 +1,27 @@ +fixupOutputHooks+=('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/move-docs.sh b/pkgs/build-support/setup-hooks/move-docs.sh new file mode 100644 index 00000000000..c819ee12a9c --- /dev/null +++ b/pkgs/build-support/setup-hooks/move-docs.sh @@ -0,0 +1,50 @@ +# 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) + +_moveToShare() { + forceShare=${forceShare:=man doc info} + if [ -z "$forceShare" -o -z "$out" ]; then return; fi + + for d in $forceShare; do + if [ -d "$out/$d" ]; then + if [ -d "$out/share/$d" ]; then + echo "both $d/ and share/$d/ exist!" + else + 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 +} 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..5a7f23b2d81 --- /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. + +fixupOutputHooks+=('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/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/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh new file mode 100644 index 00000000000..6860c9b9cb9 --- /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. + +fixupOutputHooks+=(_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/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.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/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/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..b0d37b73e2b --- /dev/null +++ b/pkgs/development/tools/misc/patchelf/setup-hook.sh @@ -0,0 +1,16 @@ +# This setup hook calls patchelf to automatically remove unneeded +# directories from the RPATH of every library or executable in every +# output. + +fixupOutputHooks+=('if [ -z "$dontPatchELF" ]; then 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/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/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/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/generic/builder.sh b/pkgs/stdenv/generic/builder.sh index 60360e7b825..4fa722a73dd 100644 --- a/pkgs/stdenv/generic/builder.sh +++ b/pkgs/stdenv/generic/builder.sh @@ -6,16 +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^@gcc@^$gcc^g" \ - -e "s^@shell@^$shell^g" \ - -e "s^@needsPax@^$needsPax^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 29e4455f7cb..1e21dd5b277 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 @@ -23,7 +21,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); @@ -41,6 +39,82 @@ let unsafeGetAttrPos = builtins.unsafeGetAttrPos or (n: as: null); + extraBuildInputs' = extraBuildInputs ++ + [ ../../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 + ]; + + # 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. + ${forceEvalHelp "Unfree"}'' + else if !allowBroken && attrs.meta.broken or false then + throw '' + Package ‘${attrs.name}’ in ${pos'} is marked as broken, refusing to evaluate. + ${forceEvalHelp "Broken"}'' + else if !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem result.system attrs.meta.platforms then + throw '' + Package ‘${attrs.name}’ in ${pos'} is not supported on ‘${result.system}’, refusing to evaluate. + ${forceEvalHelp "Broken"}'' + 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 = @@ -50,18 +124,10 @@ 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; - inherit preHook initialPath gcc shell; - - # Whether we should run paxctl to pax-mark binaries - needsPax = result.isLinux && !skipPaxMarking; + inherit preHook initialPath shell; propagatedUserEnvPkgs = [gcc] ++ lib.filter lib.isDerivation initialPath; @@ -69,75 +135,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. - ${forceEvalHelp "Unfree"}'' - else if !allowBroken && attrs.meta.broken or false then - throw '' - Package ‘${attrs.name}’ in ${pos'} is marked as broken, refusing to evaluate. - ${forceEvalHelp "Broken"}'' - else if !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem result.system attrs.meta.platforms then - throw '' - Package ‘${attrs.name}’ in ${pos'} is not supported on ‘${result.system}’, refusing to evaluate. - ${forceEvalHelp "Broken"}'' - 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"; @@ -185,6 +183,11 @@ let || system == "armv6l-linux" || system == "armv7l-linux"; + # 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; @@ -192,6 +195,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 c3b9033b49a..ea2ea947b50 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -1,18 +1,79 @@ -# 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). +set -e + +: ${outputs:=out} + + +###################################################################### +# Hook handling. + + +# 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). The hooks for are the shell function or variable +# , 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 + 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" + 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 + 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. +_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 } +# A function wrapper around ‘eval’ that ensures that ‘return’ inside +# hooks exits the hook, not the caller. +_eval() { + local code="$1" + shift + if [ "$(type -t $code)" = function ]; then + eval "$code \"\$@\"" + else + eval "$code" + fi +} + + +###################################################################### +# Error handling. + exitHandler() { exitCode=$? set +e @@ -55,7 +116,7 @@ trap "exitHandler" EXIT ###################################################################### -# Helper functions that might be useful in setup hooks. +# Helper functions. addToSearchPathWithCustomDelimiter() { @@ -74,13 +135,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 @@ -90,7 +162,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 @@ -101,37 +173,13 @@ 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 -# 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 -} +# Execute the pre-hook. +export CONFIG_SHELL="$SHELL" +if [ -z "$shell" ]; then export shell=$SHELL; fi # Allow the caller to augment buildInputs (it's not always possible to @@ -154,6 +202,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 @@ -178,7 +230,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 @@ -186,16 +238,14 @@ 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 - addToNativeEnv $i + _addToNativeEnv $i done -addToCrossEnv() { +_addToCrossEnv() { local pkg=$1 # Some programs put important build scripts (freetype-config and similar) @@ -206,13 +256,11 @@ 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 - addToCrossEnv $i + _addToCrossEnv $i done @@ -273,42 +321,11 @@ fi export NIX_BUILD_CORES -###################################################################### -# Misc. helper functions. +# Dummy implementation of the paxmark function. On Linux, this is +# overwritten by paxctl's setup hook. +paxmark() { true; } -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" - shift - - if [ -z "@needsPax@" ]; then - return - fi - - paxctl -c "$@" - paxctl -zex -${flags} "$@" -} - ###################################################################### # Textual substitution functions. @@ -439,39 +456,43 @@ stripHash() { } +unpackCmdHooks+=(_defaultUnpack) +_defaultUnpack() { + local fn="$1" + + if [ -d "$fn" ]; then + + stripHash "$fn" + cp -prd --no-preserve=timestamps "$fn" $strippedName + + else + + case "$fn" in + *.tar.xz | *.tar.lzma) + # Don't rely on tar knowing about .xz. + xz -d < "$fn" | tar xf - + ;; + *.tar | *.tar.* | *.tgz | *.tbz2) + # GNU tar can automatically select the decompression method + # (info "(tar) gzip"). + tar xf "$fn" + ;; + *) + return 1 + ;; + esac + + fi +} + + unpackFile() { curSrc="$1" - local cmd - 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 [ -z "$unpackCmd" ]; then - echo "source archive $curSrc has unknown type" - exit 1 - fi - runHook unpackCmd - fi - ;; - esac - + if ! runOneHook unpackCmd "$curSrc"; then + echo "do not know how to unpack source archive $curSrc" + exit 1 + fi stopNest } @@ -505,7 +526,7 @@ unpackPhase() { # Find the source directory. if [ -n "$setSourceRoot" ]; then - runHook setSourceRoot + runOneHook setSourceRoot elif [ -z "$sourceRoot" ]; then sourceRoot= for i in *; do @@ -654,80 +675,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., - # /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 @@ -743,74 +690,22 @@ 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() { + # 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 + done + runHook preFixup - # Make sure everything is writable so "strip" et al. work. - if [ -e "$prefix" ]; then chmod -R u+w "$prefix"; fi - - # 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 - - if [ -z "$dontGzipMan" ]; then - echo "gzipping man pages" - GLOBIGNORE=.:..:*.gz:*.bz2 - for f in "$out"/share/man/*/* "$out"/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 "$out"/share/man/*/* "$out"/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 [ "$havePatchELF" = 1 -a -z "$dontPatchELF" ]; then - patchELF "$prefix" - fi - - if [ -z "$dontPatchShebangs" ]; then - patchShebangs "$prefix" - 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" @@ -935,7 +830,6 @@ genericBuild() { # Execute the post-hooks. -for i in "${postHooks[@]}"; do $i; done runHook postHook diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 6f8b42c2266..6b15808285b 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 @@ -26,7 +24,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 ""} ''; @@ -209,7 +206,7 @@ rec { extraAttrs = { glibc = stage2.pkgs.glibc; # Required by gcc47 build }; - extraPath = [ stage2.pkgs.paxctl ]; + extraPath = [ stage2.pkgs.patchelf stage2.pkgs.paxctl ]; }; @@ -223,13 +220,9 @@ rec { coreutils = bootstrapTools; name = ""; }; - extraPath = [ stage3.pkgs.xz ]; + extraPath = [ stage2.pkgs.patchelf stage3.pkgs.xz ]; overrides = pkgs: { - # Zlib has to be inherited and not rebuilt in this stage, - # because gcc (since JAR support) already depends on zlib, and - # then if we already have a zlib we want to use that for the - # other purposes (binutils and top-level pkgs) too. - inherit (stage3.pkgs) gettext gnum4 gmp perl glibc zlib; + inherit (stage3.pkgs) gettext gnum4 gmp perl glibc; }; }; @@ -253,8 +246,9 @@ rec { ''; initialPath = - ((import ../common-path.nix) {pkgs = stage4.pkgs;}) - ++ [stage4.pkgs.patchelf stage4.pkgs.paxctl ]; + ((import ../common-path.nix) {pkgs = stage4.pkgs;}); + + extraBuildInputs = [ stage4.pkgs.patchelf stage4.pkgs.paxctl ]; shell = stage4.pkgs.bash + "/bin/bash"; @@ -278,7 +272,7 @@ rec { inherit (stage4.pkgs) gzip bzip2 xz bash binutils coreutils diffutils findutils gawk glibc gnumake gnused gnutar gnugrep gnupatch patchelf - attr acl paxctl zlib; + attr acl paxctl; }; }; 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/tools/archivers/unzip/default.nix b/pkgs/tools/archivers/unzip/default.nix index f939c968c44..7f2c81e2797 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; @@ -24,19 +31,12 @@ 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"; 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 {})) +} diff --git a/pkgs/tools/archivers/unzip/setup-hook.sh b/pkgs/tools/archivers/unzip/setup-hook.sh new file mode 100644 index 00000000000..4cad0fe7e91 --- /dev/null +++ b/pkgs/tools/archivers/unzip/setup-hook.sh @@ -0,0 +1,5 @@ +unpackCmdHooks+=(_tryUnzip) +_tryUnzip() { + if ! [[ "foo.zip" =~ \.zip$ ]]; then return 1; fi + unzip -qq "$curSrc" +} 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) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 145236569f9..47953749272 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); };