···11+export NIX_GCC=@out@
22+13addCVars () {
24 if test -d $1/include; then
35 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
···1214 fi
1315}
14161515-envHooks=(${envHooks[@]} addCVars)
1717+envHooks+=(addCVars)
16181719# Note: these come *after* $out in the PATH (see setup.sh).
1820
+1-3
pkgs/build-support/fetchzip/default.nix
···1313, ... } @ args:
14141515fetchurl ({
1616- # Remove the extension, because otherwise unpackPhase will get
1717- # confused. FIXME: fix unpackPhase.
1818- name = args.name or lib.removeSuffix ".zip" (lib.removeSuffix ".tar.gz" (baseNameOf url));
1616+ name = args.name or (baseNameOf url);
19172018 recursiveHash = true;
2119
···1111 fi
1212}
13131414-crossEnvHooks=(${crossEnvHooks[@]} crossAddCVars)
1414+crossEnvHooks+=(crossAddCVars)
15151616crossStripDirs() {
1717 local dirs="$1"
+3-1
pkgs/build-support/gcc-wrapper/setup-hook.sh
···11+export NIX_GCC=@out@
22+13addCVars () {
24 if test -d $1/include; then
35 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
···1214 fi
1315}
14161515-envHooks=(${envHooks[@]} addCVars)
1717+envHooks+=(addCVars)
16181719# Note: these come *after* $out in the PATH (see setup.sh).
1820
···11+fixupOutputHooks+=('if [ -z "$dontGzipMan" ]; then compressManPages "$prefix"; fi')
22+33+compressManPages() {
44+ local dir="$1"
55+66+ echo "gzipping man pages in $dir"
77+88+ GLOBIGNORE=.:..:*.gz:*.bz2
99+1010+ for f in "$dir"/share/man/*/* "$dir"/share/man/*/*/*; do
1111+ if [ -f "$f" -a ! -L "$f" ]; then
1212+ if gzip -c -n "$f" > "$f".gz; then
1313+ rm "$f"
1414+ else
1515+ rm "$f".gz
1616+ fi
1717+ fi
1818+ done
1919+2020+ for f in "$dir"/share/man/*/* "$dir"/share/man/*/*/*; do
2121+ if [ -L "$f" -a -f `readlink -f "$f"`.gz ]; then
2222+ ln -sf `readlink "$f"`.gz "$f".gz && rm "$f"
2323+ fi
2424+ done
2525+2626+ unset GLOBIGNORE
2727+}
+50
pkgs/build-support/setup-hooks/move-docs.sh
···11+# This setup hook moves $out/{man,doc,info} to $out/share; moves
22+# $out/share/man to $man/share/man; and moves $out/share/doc to
33+# $man/share/doc.
44+55+preFixupHooks+=(_moveDocs)
66+77+_moveToShare() {
88+ forceShare=${forceShare:=man doc info}
99+ if [ -z "$forceShare" -o -z "$out" ]; then return; fi
1010+1111+ for d in $forceShare; do
1212+ if [ -d "$out/$d" ]; then
1313+ if [ -d "$out/share/$d" ]; then
1414+ echo "both $d/ and share/$d/ exist!"
1515+ else
1616+ echo "moving $out/$d to $out/share/$d"
1717+ mkdir -p $out/share
1818+ mv $out/$d $out/share/
1919+ fi
2020+ fi
2121+ done
2222+}
2323+2424+_moveToOutput() {
2525+ local d="$1"
2626+ local dst="$2"
2727+ if [ -z "$dst" -a ! -e $dst/$d ]; then return; fi
2828+ local output
2929+ for output in $outputs; do
3030+ if [ "${!output}" = "$dst" ]; then continue; fi
3131+ if [ -d "${!output}/$d" ]; then
3232+ echo "moving ${!output}/$d to $dst/$d"
3333+ mkdir -p $dst/share
3434+ mv ${!output}/$d $dst/$d
3535+ break
3636+ fi
3737+ done
3838+}
3939+4040+_moveDocs() {
4141+ _moveToShare
4242+ _moveToOutput share/man "$man"
4343+ _moveToOutput share/info "$info"
4444+ _moveToOutput share/doc "$doc"
4545+4646+ # Remove empty share directory.
4747+ if [ -d "$out/share" ]; then
4848+ rmdir $out/share 2> /dev/null || true
4949+ fi
5050+}
+62
pkgs/build-support/setup-hooks/patch-shebangs.sh
···11+# This setup hook causes the fixup phase to rewrite all script
22+# interpreter file names (`#! /path') to paths found in $PATH. E.g.,
33+# /bin/sh will be rewritten to /nix/store/<hash>-some-bash/bin/sh.
44+# /usr/bin/env gets special treatment so that ".../bin/env python" is
55+# rewritten to /nix/store/<hash>/bin/python. Interpreters that are
66+# already in the store are left untouched.
77+88+fixupOutputHooks+=('if [ -z "$dontPatchShebangs" ]; then patchShebangs "$prefix"; fi')
99+1010+patchShebangs() {
1111+ local dir="$1"
1212+ header "patching script interpreter paths in $dir"
1313+ local f
1414+ local oldPath
1515+ local newPath
1616+ local arg0
1717+ local args
1818+ local oldInterpreterLine
1919+ local newInterpreterLine
2020+2121+ find "$dir" -type f -perm +0100 | while read f; do
2222+ if [ "$(head -1 "$f" | head -c +2)" != '#!' ]; then
2323+ # missing shebang => not a script
2424+ continue
2525+ fi
2626+2727+ oldInterpreterLine=$(head -1 "$f" | tail -c +3)
2828+ read -r oldPath arg0 args <<< "$oldInterpreterLine"
2929+3030+ if $(echo "$oldPath" | grep -q "/bin/env$"); then
3131+ # Check for unsupported 'env' functionality:
3232+ # - options: something starting with a '-'
3333+ # - environment variables: foo=bar
3434+ if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then
3535+ echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)"
3636+ exit 1
3737+ fi
3838+ newPath="$(command -v "$arg0" || true)"
3939+ else
4040+ if [ "$oldPath" = "" ]; then
4141+ # If no interpreter is specified linux will use /bin/sh. Set
4242+ # oldpath="/bin/sh" so that we get /nix/store/.../sh.
4343+ oldPath="/bin/sh"
4444+ fi
4545+ newPath="$(command -v "$(basename "$oldPath")" || true)"
4646+ args="$arg0 $args"
4747+ fi
4848+4949+ newInterpreterLine="$newPath $args"
5050+5151+ if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then
5252+ if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then
5353+ echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
5454+ # escape the escape chars so that sed doesn't interpret them
5555+ escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
5656+ sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f"
5757+ fi
5858+ fi
5959+ done
6060+6161+ stopNest
6262+}
···11+# This setup hook strips libraries and executables in the fixup phase.
22+33+fixupOutputHooks+=(_doStrip)
44+55+_doStrip() {
66+ if [ -z "$dontStrip" ]; then
77+ stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin}
88+ if [ -n "$stripDebugList" ]; then
99+ stripDirs "$stripDebugList" "${stripDebugFlags:--S}"
1010+ fi
1111+1212+ stripAllList=${stripAllList:-}
1313+ if [ -n "$stripAllList" ]; then
1414+ stripDirs "$stripAllList" "${stripAllFlags:--s}"
1515+ fi
1616+ fi
1717+}
1818+1919+stripDirs() {
2020+ local dirs="$1"
2121+ local stripFlags="$2"
2222+ local dirsNew=
2323+2424+ for d in ${dirs}; do
2525+ if [ -d "$prefix/$d" ]; then
2626+ dirsNew="${dirsNew} $prefix/$d "
2727+ fi
2828+ done
2929+ dirs=${dirsNew}
3030+3131+ if [ -n "${dirs}" ]; then
3232+ header "stripping (with flags $stripFlags) in$dirs"
3333+ find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} strip $commonStripFlags $stripFlags || true
3434+ stopNest
3535+ fi
3636+}
+1-1
pkgs/desktops/e17/e_dbus/setup-hook.sh
···55 fi
66}
7788-envHooks=(${envHooks[@]} addDbusIncludePath)
88+envHooks+=(addDbusIncludePath)
···55 fi
66}
7788-envHooks=(${envHooks[@]} addGstreamerLibPath)
88+envHooks+=(addGstreamerLibPath)
+1-1
pkgs/development/libraries/libxml2/setup-hook.sh
···2323 # xmllint and xsltproc from looking in /etc/xml/catalog.
2424 export XML_CATALOG_FILES
2525 if test -z "$XML_CATALOG_FILES"; then XML_CATALOG_FILES=" "; fi
2626- envHooks=(${envHooks[@]} addXMLCatalogs)
2626+ envHooks+=(addXMLCatalogs)
2727fi
+1-1
pkgs/development/libraries/slib/setup-hook.sh
···1010 fi
1111}
12121313-envHooks=(${envHooks[@]} addSlibPath)
1313+envHooks+=(addSlibPath)
···11+# This setup hook calls patchelf to automatically remove unneeded
22+# directories from the RPATH of every library or executable in every
33+# output.
44+55+fixupOutputHooks+=('if [ -z "$dontPatchELF" ]; then patchELF "$prefix"; fi')
66+77+patchELF() {
88+ header "patching ELF executables and libraries in $prefix"
99+ if [ -e "$prefix" ]; then
1010+ find "$prefix" \( \
1111+ \( -type f -a -name "*.so*" \) -o \
1212+ \( -type f -a -perm +0100 \) \
1313+ \) -print -exec patchelf --shrink-rpath '{}' \;
1414+ fi
1515+ stopNest
1616+}
···1818 "MANDIR=share/man/man1"
1919 ];
20202121+ setupHook = ./setup-hook.sh;
2222+2123 meta = with stdenv.lib; {
2224 description = "A tool for controlling PaX flags on a per binary basis";
2325 homepage = "https://pax.grsecurity.net";
···55# Posix utilities, the GNU C compiler, and so on. On other systems,
66# we use the native C library.
7788-{ system, allPackages ? import ../.., platform, config }:
88+{ system, allPackages ? import ../.., platform, config, lib }:
9910101111rec {
···28282929 # The Nix build environment.
3030 stdenvNix = import ./nix {
3131- inherit config;
3131+ inherit config lib;
3232 stdenv = stdenvNative;
3333 pkgs = stdenvNativePkgs;
3434 };
353536363737 # Linux standard environment.
3838- stdenvLinux = (import ./linux { inherit system allPackages platform config;}).stdenvLinux;
3838+ stdenvLinux = (import ./linux { inherit system allPackages platform config lib; }).stdenvLinux;
393940404141 # Select the appropriate stdenv for the platform `system'.
+3-8
pkgs/stdenv/generic/builder.sh
···6677mkdir $out
8899-echo "$preHook" > $out/setup
99+echo "export SHELL=$shell" > $out/setup
1010+echo "initialPath=\"$initialPath\"" >> $out/setup
1111+echo "$preHook" >> $out/setup
1012cat "$setup" >> $out/setup
1111-1212-sed -e "s^@initialPath@^$initialPath^g" \
1313- -e "s^@gcc@^$gcc^g" \
1414- -e "s^@shell@^$shell^g" \
1515- -e "s^@needsPax@^$needsPax^g" \
1616- < $out/setup > $out/setup.tmp
1717-mv $out/setup.tmp $out/setup
18131914# Allow the user to install stdenv using nix-env and get the packages
2015# in stdenv.
+86-81
pkgs/stdenv/generic/default.nix
···1010, setupScript ? ./setup.sh
11111212, extraBuildInputs ? []
1313-1414-, skipPaxMarking ? false
1513}:
16141715let
···2321 # {pkgs, ...}:
2422 # {
2523 # allowUnfree = false;
2626- # allowUnfreePredicate = (x: pkgs.lib.hasPrefix "flashplayero-" x.name);
2424+ # allowUnfreePredicate = (x: pkgs.lib.hasPrefix "flashplayer-" x.name);
2725 # }
2826 allowUnfreePredicate = config.allowUnfreePredicate or (x: false);
2927···41394240 unsafeGetAttrPos = builtins.unsafeGetAttrPos or (n: as: null);
43414242+ extraBuildInputs' = extraBuildInputs ++
4343+ [ ../../build-support/setup-hooks/move-docs.sh
4444+ ../../build-support/setup-hooks/compress-man-pages.sh
4545+ ../../build-support/setup-hooks/strip.sh
4646+ ../../build-support/setup-hooks/patch-shebangs.sh
4747+ gcc
4848+ ];
4949+5050+ # Add a utility function to produce derivations that use this
5151+ # stdenv and its shell.
5252+ mkDerivation = attrs:
5353+ let
5454+ pos =
5555+ if attrs.meta.description or null != null then
5656+ unsafeGetAttrPos "description" attrs.meta
5757+ else
5858+ unsafeGetAttrPos "name" attrs;
5959+ pos' = if pos != null then "‘" + pos.file + ":" + toString pos.line + "’" else "«unknown-file»";
6060+ in
6161+ if !allowUnfree
6262+ && (let l = lib.lists.toList attrs.meta.license or []; in lib.lists.elem "unfree" l || lib.lists.elem "unfree-redistributable" l)
6363+ && !allowUnfreePredicate attrs then
6464+ throw ''
6565+ Package ‘${attrs.name}’ in ${pos'} has an unfree license, refusing to evaluate.
6666+ ${forceEvalHelp "Unfree"}''
6767+ else if !allowBroken && attrs.meta.broken or false then
6868+ throw ''
6969+ Package ‘${attrs.name}’ in ${pos'} is marked as broken, refusing to evaluate.
7070+ ${forceEvalHelp "Broken"}''
7171+ else if !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem result.system attrs.meta.platforms then
7272+ throw ''
7373+ Package ‘${attrs.name}’ in ${pos'} is not supported on ‘${result.system}’, refusing to evaluate.
7474+ ${forceEvalHelp "Broken"}''
7575+ else
7676+ lib.addPassthru (derivation (
7777+ (removeAttrs attrs ["meta" "passthru" "crossAttrs"])
7878+ // (let
7979+ buildInputs = attrs.buildInputs or [];
8080+ nativeBuildInputs = attrs.nativeBuildInputs or [];
8181+ propagatedBuildInputs = attrs.propagatedBuildInputs or [];
8282+ propagatedNativeBuildInputs = attrs.propagatedNativeBuildInputs or [];
8383+ crossConfig = attrs.crossConfig or null;
8484+ in
8585+ {
8686+ builder = attrs.realBuilder or shell;
8787+ args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)];
8888+ stdenv = result;
8989+ system = result.system;
9090+ userHook = config.stdenv.userHook or null;
9191+ __ignoreNulls = true;
9292+9393+ # Inputs built by the cross compiler.
9494+ buildInputs = lib.optionals (crossConfig != null) (buildInputs ++ extraBuildInputs');
9595+ propagatedBuildInputs = lib.optionals (crossConfig != null) propagatedBuildInputs;
9696+ # Inputs built by the usual native compiler.
9797+ nativeBuildInputs = nativeBuildInputs ++ lib.optionals (crossConfig == null) (buildInputs ++ extraBuildInputs');
9898+ propagatedNativeBuildInputs = propagatedNativeBuildInputs ++
9999+ lib.optionals (crossConfig == null) propagatedBuildInputs;
100100+ }))) (
101101+ {
102102+ # The meta attribute is passed in the resulting attribute set,
103103+ # but it's not part of the actual derivation, i.e., it's not
104104+ # passed to the builder and is not a dependency. But since we
105105+ # include it in the result, it *is* available to nix-env for
106106+ # queries. We also a meta.position attribute here to
107107+ # identify the source location of the package.
108108+ meta = attrs.meta or {} // (if pos != null then {
109109+ position = pos.file + ":" + (toString pos.line);
110110+ } else {});
111111+ passthru = attrs.passthru or {};
112112+ } //
113113+ # Pass through extra attributes that are not inputs, but
114114+ # should be made available to Nix expressions using the
115115+ # derivation (e.g., in assertions).
116116+ (attrs.passthru or {}));
117117+44118 # The stdenv that we are producing.
45119 result =
46120···50124 builder = shell;
5112552126 args = ["-e" ./builder.sh];
5353- /* TODO: special-cased @var@ substitutions are ugly.
5454- However, using substituteAll* from setup.sh seems difficult,
5555- as setup.sh can't be directly sourced.
5656- Suggestion: split similar utility functions into a separate script.
5757- */
5812759128 setup = setupScript;
601296161- inherit preHook initialPath gcc shell;
6262-6363- # Whether we should run paxctl to pax-mark binaries
6464- needsPax = result.isLinux && !skipPaxMarking;
130130+ inherit preHook initialPath shell;
6513166132 propagatedUserEnvPkgs = [gcc] ++
67133 lib.filter lib.isDerivation initialPath;
···6913570136 // rec {
711377272- meta = {
7373- description = "The default build environment for Unix packages in Nixpkgs";
7474- };
7575-7676- # Add a utility function to produce derivations that use this
7777- # stdenv and its shell.
7878- mkDerivation = attrs:
7979- let
8080- pos =
8181- if attrs.meta.description or null != null then
8282- unsafeGetAttrPos "description" attrs.meta
8383- else
8484- unsafeGetAttrPos "name" attrs;
8585- pos' = if pos != null then "‘" + pos.file + ":" + toString pos.line + "’" else "«unknown-file»";
8686- in
8787- 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
8888- throw ''
8989- Package ‘${attrs.name}’ in ${pos'} has an unfree license, refusing to evaluate.
9090- ${forceEvalHelp "Unfree"}''
9191- else if !allowBroken && attrs.meta.broken or false then
9292- throw ''
9393- Package ‘${attrs.name}’ in ${pos'} is marked as broken, refusing to evaluate.
9494- ${forceEvalHelp "Broken"}''
9595- else if !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem result.system attrs.meta.platforms then
9696- throw ''
9797- Package ‘${attrs.name}’ in ${pos'} is not supported on ‘${result.system}’, refusing to evaluate.
9898- ${forceEvalHelp "Broken"}''
9999- else
100100- lib.addPassthru (derivation (
101101- (removeAttrs attrs ["meta" "passthru" "crossAttrs"])
102102- // (let
103103- buildInputs = attrs.buildInputs or [];
104104- nativeBuildInputs = attrs.nativeBuildInputs or [];
105105- propagatedBuildInputs = attrs.propagatedBuildInputs or [];
106106- propagatedNativeBuildInputs = attrs.propagatedNativeBuildInputs or [];
107107- crossConfig = attrs.crossConfig or null;
108108- in
109109- {
110110- builder = attrs.realBuilder or shell;
111111- args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)];
112112- stdenv = result;
113113- system = result.system;
114114- userHook = config.stdenv.userHook or null;
115115- __ignoreNulls = true;
116116-117117- # Inputs built by the cross compiler.
118118- buildInputs = lib.optionals (crossConfig != null) (buildInputs ++ extraBuildInputs);
119119- propagatedBuildInputs = lib.optionals (crossConfig != null) propagatedBuildInputs;
120120- # Inputs built by the usual native compiler.
121121- nativeBuildInputs = nativeBuildInputs ++ lib.optionals (crossConfig == null) (buildInputs ++ extraBuildInputs);
122122- propagatedNativeBuildInputs = propagatedNativeBuildInputs ++
123123- lib.optionals (crossConfig == null) propagatedBuildInputs;
124124- }))) (
125125- {
126126- # The meta attribute is passed in the resulting attribute set,
127127- # but it's not part of the actual derivation, i.e., it's not
128128- # passed to the builder and is not a dependency. But since we
129129- # include it in the result, it *is* available to nix-env for
130130- # queries. We also a meta.position attribute here to
131131- # identify the source location of the package.
132132- meta = attrs.meta or {} // (if pos != null then {
133133- position = pos.file + ":" + (toString pos.line);
134134- } else {});
135135- passthru = attrs.passthru or {};
136136- } //
137137- # Pass through extra attributes that are not inputs, but
138138- # should be made available to Nix expressions using the
139139- # derivation (e.g., in assertions).
140140- (attrs.passthru or {}));
138138+ meta.description = "The default build environment for Unix packages in Nixpkgs";
141139142140 # Utility flags to test the type of platform.
143141 isDarwin = system == "x86_64-darwin";
···185183 || system == "armv6l-linux"
186184 || system == "armv7l-linux";
187185186186+ # Whether we should run paxctl to pax-mark binaries.
187187+ needsPax = isLinux;
188188+189189+ inherit mkDerivation;
190190+188191 # For convenience, bring in the library functions in lib/ so
189192 # packages don't have to do that themselves.
190193 inherit lib;
···192195 inherit fetchurlBoot;
193196194197 inherit overrides;
198198+199199+ inherit gcc;
195200 }
196201197202 # Propagate any extra attributes. For instance, we use this to
+146-252
pkgs/stdenv/generic/setup.sh
···11-# Run the named hook, either by calling the function with that name or
22-# by evaluating the variable with that name. This allows convenient
33-# setting of hooks both from Nix expressions (as attributes /
44-# environment variables) and from shell scripts (as functions).
11+set -e
22+33+: ${outputs:=out}
44+55+66+######################################################################
77+# Hook handling.
88+99+1010+# Run all hooks with the specified name in the order in which they
1111+# were added, stopping if any fails (returns a non-zero exit
1212+# code). The hooks for <hookName> are the shell function or variable
1313+# <hookName>, and the values of the shell array ‘<hookName>Hooks’.
514runHook() {
615 local hookName="$1"
1616+ shift
1717+ local var="$hookName"
1818+ if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
1919+ eval "local -a dummy=(\"\${$var[@]}\")"
2020+ for hook in "_callImplicitHook 0 $hookName" "${dummy[@]}"; do
2121+ if ! _eval "$hook" "$@"; then return 1; fi
2222+ done
2323+ return 0
2424+}
2525+2626+2727+# Run all hooks with the specified name, until one succeeds (returns a
2828+# zero exit code). If none succeed, return a non-zero exit code.
2929+runOneHook() {
3030+ local hookName="$1"
3131+ shift
3232+ local var="$hookName"
3333+ if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
3434+ eval "local -a dummy=(\"\${$var[@]}\")"
3535+ for hook in "_callImplicitHook 1 $hookName" "${dummy[@]}"; do
3636+ if _eval "$hook" "$@"; then
3737+ return 0
3838+ fi
3939+ done
4040+ return 1
4141+}
4242+4343+4444+# Run the named hook, either by calling the function with that name or
4545+# by evaluating the variable with that name. This allows convenient
4646+# setting of hooks both from Nix expressions (as attributes /
4747+# environment variables) and from shell scripts (as functions). If you
4848+# want to allow multiple hooks, use runHook instead.
4949+_callImplicitHook() {
5050+ local def="$1"
5151+ local hookName="$2"
752 case "$(type -t $hookName)" in
853 (function|alias|builtin) $hookName;;
954 (file) source $hookName;;
1055 (keyword) :;;
1111- (*) eval "${!hookName}";;
5656+ (*) if [ -z "${!hookName}" ]; then return "$def"; else eval "${!hookName}"; fi;;
1257 esac
1358}
145915606161+# A function wrapper around ‘eval’ that ensures that ‘return’ inside
6262+# hooks exits the hook, not the caller.
6363+_eval() {
6464+ local code="$1"
6565+ shift
6666+ if [ "$(type -t $code)" = function ]; then
6767+ eval "$code \"\$@\""
6868+ else
6969+ eval "$code"
7070+ fi
7171+}
7272+7373+7474+######################################################################
7575+# Error handling.
7676+1677exitHandler() {
1778 exitCode=$?
1879 set +e
···551165611757118######################################################################
5858-# Helper functions that might be useful in setup hooks.
119119+# Helper functions.
591206012161122addToSearchPathWithCustomDelimiter() {
···74135}
75136761377777-######################################################################
7878-# Initialisation.
138138+ensureDir() {
139139+ echo "warning: ‘ensureDir’ is deprecated; use ‘mkdir’ instead" >&2
140140+ local dir
141141+ for dir in "$@"; do
142142+ if ! [ -x "$dir" ]; then mkdir -p "$dir"; fi
143143+ done
144144+}
145145+146146+147147+installBin() {
148148+ mkdir -p $out/bin
149149+ cp "$@" $out/bin
150150+}
791518080-set -e
811528282-[ -z $NIX_GCC ] && NIX_GCC=@gcc@
153153+######################################################################
154154+# Initialisation.
831558415685157# Wildcard expansions that don't match should expand to an empty list.
···9016291163# Set up the initial path.
92164PATH=
9393-for i in $NIX_GCC @initialPath@; do
165165+for i in $initialPath; do
94166 if [ "$i" = / ]; then i=; fi
95167 addToSearchPath PATH $i/bin
96168 addToSearchPath PATH $i/sbin
···101173fi
102174103175104104-# Execute the pre-hook.
105105-export SHELL=@shell@
106106-export CONFIG_SHELL="$SHELL"
107107-if [ -z "$shell" ]; then export shell=@shell@; fi
108108-runHook preHook
109109-110110-111176# Check that the pre-hook initialised SHELL.
112177if [ -z "$SHELL" ]; then echo "SHELL not set"; exit 1; fi
113178114114-# Hack: run gcc's setup hook.
115115-envHooks=()
116116-crossEnvHooks=()
117117-if [ -f $NIX_GCC/nix-support/setup-hook ]; then
118118- source $NIX_GCC/nix-support/setup-hook
119119-fi
120179121121-122122-# Ensure that the given directories exists.
123123-ensureDir() {
124124- echo "warning: ‘ensureDir’ is deprecated; use ‘mkdir’ instead" >&2
125125- local dir
126126- for dir in "$@"; do
127127- if ! [ -x "$dir" ]; then mkdir -p "$dir"; fi
128128- done
129129-}
130130-131131-installBin() {
132132- mkdir -p $out/bin
133133- cp "$@" $out/bin
134134-}
180180+# Execute the pre-hook.
181181+export CONFIG_SHELL="$SHELL"
182182+if [ -z "$shell" ]; then export shell=$SHELL; fi
135183136184137185# Allow the caller to augment buildInputs (it's not always possible to
···154202155203 eval $var="'${!var} $pkg '"
156204205205+ if [ -f $pkg ]; then
206206+ source $pkg
207207+ fi
208208+157209 if [ -f $pkg/nix-support/setup-hook ]; then
158210 source $pkg/nix-support/setup-hook
159211 fi
···178230179231# Set the relevant environment variables to point to the build inputs
180232# found above.
181181-addToNativeEnv() {
233233+_addToNativeEnv() {
182234 local pkg=$1
183235184236 if [ -d $1/bin ]; then
···186238 fi
187239188240 # Run the package-specific hooks set by the setup-hook scripts.
189189- for i in "${envHooks[@]}"; do
190190- $i $pkg
191191- done
241241+ runHook envHook "$pkg"
192242}
193243194244for i in $nativePkgs; do
195195- addToNativeEnv $i
245245+ _addToNativeEnv $i
196246done
197247198198-addToCrossEnv() {
248248+_addToCrossEnv() {
199249 local pkg=$1
200250201251 # Some programs put important build scripts (freetype-config and similar)
···206256 fi
207257208258 # Run the package-specific hooks set by the setup-hook scripts.
209209- for i in "${crossEnvHooks[@]}"; do
210210- $i $pkg
211211- done
259259+ runHook crossEnvHook "$pkg"
212260}
213261214262for i in $crossPkgs; do
215215- addToCrossEnv $i
263263+ _addToCrossEnv $i
216264done
217265218266···273321export NIX_BUILD_CORES
274322275323276276-######################################################################
277277-# Misc. helper functions.
324324+# Dummy implementation of the paxmark function. On Linux, this is
325325+# overwritten by paxctl's setup hook.
326326+paxmark() { true; }
278327279328280280-stripDirs() {
281281- local dirs="$1"
282282- local stripFlags="$2"
283283- local dirsNew=
284284-285285- for d in ${dirs}; do
286286- if [ -d "$prefix/$d" ]; then
287287- dirsNew="${dirsNew} $prefix/$d "
288288- fi
289289- done
290290- dirs=${dirsNew}
291291-292292- if [ -n "${dirs}" ]; then
293293- header "stripping (with flags $stripFlags) in $dirs"
294294- find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} strip $commonStripFlags $stripFlags || true
295295- stopNest
296296- fi
297297-}
298298-299299-# PaX-mark binaries
300300-paxmark() {
301301- local flags="$1"
302302- shift
303303-304304- if [ -z "@needsPax@" ]; then
305305- return
306306- fi
307307-308308- paxctl -c "$@"
309309- paxctl -zex -${flags} "$@"
310310-}
311311-312329######################################################################
313330# Textual substitution functions.
314331···439456}
440457441458442442-unpackFile() {
443443- curSrc="$1"
444444- local cmd
459459+unpackCmdHooks+=(_defaultUnpack)
460460+_defaultUnpack() {
461461+ local fn="$1"
445462446446- header "unpacking source archive $curSrc" 3
463463+ if [ -d "$fn" ]; then
447464448448- case "$curSrc" in
449449- *.tar.xz | *.tar.lzma)
450450- # Don't rely on tar knowing about .xz.
451451- xz -d < $curSrc | tar xf -
452452- ;;
453453- *.tar | *.tar.* | *.tgz | *.tbz2)
454454- # GNU tar can automatically select the decompression method
455455- # (info "(tar) gzip").
456456- tar xf $curSrc
457457- ;;
458458- *.zip)
459459- unzip -qq $curSrc
460460- ;;
461461- *)
462462- if [ -d "$curSrc" ]; then
463463- stripHash $curSrc
464464- cp -prd --no-preserve=timestamps $curSrc $strippedName
465465- else
466466- if [ -z "$unpackCmd" ]; then
467467- echo "source archive $curSrc has unknown type"
468468- exit 1
469469- fi
470470- runHook unpackCmd
471471- fi
472472- ;;
473473- esac
465465+ stripHash "$fn"
466466+ cp -prd --no-preserve=timestamps "$fn" $strippedName
467467+468468+ else
474469470470+ case "$fn" in
471471+ *.tar.xz | *.tar.lzma)
472472+ # Don't rely on tar knowing about .xz.
473473+ xz -d < "$fn" | tar xf -
474474+ ;;
475475+ *.tar | *.tar.* | *.tgz | *.tbz2)
476476+ # GNU tar can automatically select the decompression method
477477+ # (info "(tar) gzip").
478478+ tar xf "$fn"
479479+ ;;
480480+ *)
481481+ return 1
482482+ ;;
483483+ esac
484484+485485+ fi
486486+}
487487+488488+489489+unpackFile() {
490490+ curSrc="$1"
491491+ header "unpacking source archive $curSrc" 3
492492+ if ! runOneHook unpackCmd "$curSrc"; then
493493+ echo "do not know how to unpack source archive $curSrc"
494494+ exit 1
495495+ fi
475496 stopNest
476497}
477498···505526506527 # Find the source directory.
507528 if [ -n "$setSourceRoot" ]; then
508508- runHook setSourceRoot
529529+ runOneHook setSourceRoot
509530 elif [ -z "$sourceRoot" ]; then
510531 sourceRoot=
511532 for i in *; do
···654675}
655676656677657657-patchELF() {
658658- # Patch all ELF executables and shared libraries.
659659- header "patching ELF executables and libraries"
660660- if [ -e "$prefix" ]; then
661661- find "$prefix" \( \
662662- \( -type f -a -name "*.so*" \) -o \
663663- \( -type f -a -perm +0100 \) \
664664- \) -print -exec patchelf --shrink-rpath '{}' \;
665665- fi
666666- stopNest
667667-}
668668-669669-670670-patchShebangs() {
671671- # Rewrite all script interpreter file names (`#! /path') under the
672672- # specified directory tree to paths found in $PATH. E.g.,
673673- # /bin/sh will be rewritten to /nix/store/<hash>-some-bash/bin/sh.
674674- # /usr/bin/env gets special treatment so that ".../bin/env python" is
675675- # rewritten to /nix/store/<hash>/bin/python.
676676- # Interpreters that are already in the store are left untouched.
677677- header "patching script interpreter paths"
678678- local dir="$1"
679679- local f
680680- local oldPath
681681- local newPath
682682- local arg0
683683- local args
684684- local oldInterpreterLine
685685- local newInterpreterLine
686686-687687- find "$dir" -type f -perm +0100 | while read f; do
688688- if [ "$(head -1 "$f" | head -c +2)" != '#!' ]; then
689689- # missing shebang => not a script
690690- continue
691691- fi
692692-693693- oldInterpreterLine=$(head -1 "$f" | tail -c +3)
694694- read -r oldPath arg0 args <<< "$oldInterpreterLine"
695695-696696- if $(echo "$oldPath" | grep -q "/bin/env$"); then
697697- # Check for unsupported 'env' functionality:
698698- # - options: something starting with a '-'
699699- # - environment variables: foo=bar
700700- if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then
701701- echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)"
702702- exit 1
703703- fi
704704- newPath="$(command -v "$arg0" || true)"
705705- else
706706- if [ "$oldPath" = "" ]; then
707707- # If no interpreter is specified linux will use /bin/sh. Set
708708- # oldpath="/bin/sh" so that we get /nix/store/.../sh.
709709- oldPath="/bin/sh"
710710- fi
711711- newPath="$(command -v "$(basename "$oldPath")" || true)"
712712- args="$arg0 $args"
713713- fi
714714-715715- newInterpreterLine="$newPath $args"
716716-717717- if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then
718718- if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then
719719- echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
720720- # escape the escape chars so that sed doesn't interpret them
721721- escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
722722- sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f"
723723- fi
724724- fi
725725- done
726726-727727- stopNest
728728-}
729729-730730-731678installPhase() {
732679 runHook preInstall
733680···743690}
744691745692746746-# The fixup phase performs generic, package-independent, Nix-related
747747-# stuff, like running patchelf and setting the
748748-# propagated-build-inputs. It should rarely be overriden.
693693+# The fixup phase performs generic, package-independent stuff, like
694694+# stripping binaries, running patchelf and setting
695695+# propagated-build-inputs.
749696fixupPhase() {
750750- runHook preFixup
751751-752697 # Make sure everything is writable so "strip" et al. work.
753753- if [ -e "$prefix" ]; then chmod -R u+w "$prefix"; fi
754754-755755- # Put man/doc/info under $out/share.
756756- forceShare=${forceShare:=man doc info}
757757- if [ -n "$forceShare" ]; then
758758- for d in $forceShare; do
759759- if [ -d "$prefix/$d" ]; then
760760- if [ -d "$prefix/share/$d" ]; then
761761- echo "both $d/ and share/$d/ exists!"
762762- else
763763- echo "fixing location of $d/ subdirectory"
764764- mkdir -p $prefix/share
765765- if [ -w $prefix/share ]; then
766766- mv -v $prefix/$d $prefix/share
767767- ln -sv share/$d $prefix
768768- fi
769769- fi
770770- fi
771771- done;
772772- fi
698698+ for output in $outputs; do
699699+ if [ -e "${!output}" ]; then chmod -R u+w "${!output}"; fi
700700+ done
773701774774- if [ -z "$dontGzipMan" ]; then
775775- echo "gzipping man pages"
776776- GLOBIGNORE=.:..:*.gz:*.bz2
777777- for f in "$out"/share/man/*/* "$out"/share/man/*/*/*; do
778778- if [ -f "$f" -a ! -L "$f" ]; then
779779- if gzip -c -n "$f" > "$f".gz; then
780780- rm "$f"
781781- else
782782- rm "$f".gz
783783- fi
784784- fi
785785- done
786786- for f in "$out"/share/man/*/* "$out"/share/man/*/*/*; do
787787- if [ -L "$f" -a -f `readlink -f "$f"`.gz ]; then
788788- ln -sf `readlink "$f"`.gz "$f".gz && rm "$f"
789789- fi
790790- done
791791- unset GLOBIGNORE
792792- fi
702702+ runHook preFixup
793703794794- # TODO: strip _only_ ELF executables, and return || fail here...
795795- if [ -z "$dontStrip" ]; then
796796- stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin}
797797- if [ -n "$stripDebugList" ]; then
798798- stripDirs "$stripDebugList" "${stripDebugFlags:--S}"
799799- fi
800800-801801- stripAllList=${stripAllList:-}
802802- if [ -n "$stripAllList" ]; then
803803- stripDirs "$stripAllList" "${stripAllFlags:--s}"
804804- fi
805805- fi
806806-807807- if [ "$havePatchELF" = 1 -a -z "$dontPatchELF" ]; then
808808- patchELF "$prefix"
809809- fi
810810-811811- if [ -z "$dontPatchShebangs" ]; then
812812- patchShebangs "$prefix"
813813- fi
704704+ # Apply fixup to each output.
705705+ local output
706706+ for output in $outputs; do
707707+ prefix=${!output} runHook fixupOutput
708708+ done
814709815710 if [ -n "$propagatedBuildInputs" ]; then
816711 mkdir -p "$out/nix-support"
···935830936831937832# Execute the post-hooks.
938938-for i in "${postHooks[@]}"; do $i; done
939833runHook postHook
940834941835
+8-14
pkgs/stdenv/linux/default.nix
···77# The function defaults are for easy testing.
88{ system ? builtins.currentSystem
99, allPackages ? import ../../top-level/all-packages.nix
1010-, platform ? null, config ? {} }:
1010+, platform ? null, config ? {}, lib }:
11111212rec {
1313-1414- lib = import ../../../lib;
15131614 bootstrapFiles =
1715 if system == "i686-linux" then import ./bootstrap/i686.nix
···2624 commonPreHook =
2725 ''
2826 export NIX_ENFORCE_PURITY=1
2929- havePatchELF=1
3027 ${if system == "x86_64-linux" then "NIX_LIB64_IN_SELF_RPATH=1" else ""}
3128 ${if system == "mips64el-linux" then "NIX_LIB32_IN_SELF_RPATH=1" else ""}
3229 '';
···209206 extraAttrs = {
210207 glibc = stage2.pkgs.glibc; # Required by gcc47 build
211208 };
212212- extraPath = [ stage2.pkgs.paxctl ];
209209+ extraPath = [ stage2.pkgs.patchelf stage2.pkgs.paxctl ];
213210 };
214211215212···223220 coreutils = bootstrapTools;
224221 name = "";
225222 };
226226- extraPath = [ stage3.pkgs.xz ];
223223+ extraPath = [ stage2.pkgs.patchelf stage3.pkgs.xz ];
227224 overrides = pkgs: {
228228- # Zlib has to be inherited and not rebuilt in this stage,
229229- # because gcc (since JAR support) already depends on zlib, and
230230- # then if we already have a zlib we want to use that for the
231231- # other purposes (binutils and top-level pkgs) too.
232232- inherit (stage3.pkgs) gettext gnum4 gmp perl glibc zlib;
225225+ inherit (stage3.pkgs) gettext gnum4 gmp perl glibc;
233226 };
234227 };
235228···253246 '';
254247255248 initialPath =
256256- ((import ../common-path.nix) {pkgs = stage4.pkgs;})
257257- ++ [stage4.pkgs.patchelf stage4.pkgs.paxctl ];
249249+ ((import ../common-path.nix) {pkgs = stage4.pkgs;});
250250+251251+ extraBuildInputs = [ stage4.pkgs.patchelf stage4.pkgs.paxctl ];
258252259253 shell = stage4.pkgs.bash + "/bin/bash";
260254···278272 inherit (stage4.pkgs)
279273 gzip bzip2 xz bash binutils coreutils diffutils findutils gawk
280274 glibc gnumake gnused gnutar gnugrep gnupatch patchelf
281281- attr acl paxctl zlib;
275275+ attr acl paxctl;
282276 };
283277 };
284278