···001addCVars () {
2 if test -d $1/include; then
3 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
···12 fi
13}
1415-envHooks=(${envHooks[@]} addCVars)
1617# Note: these come *after* $out in the PATH (see setup.sh).
18
···1+export NIX_GCC=@out@
2+3addCVars () {
4 if test -d $1/include; then
5 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
···14 fi
15}
1617+envHooks+=(addCVars)
1819# Note: these come *after* $out in the PATH (see setup.sh).
20
+1-3
pkgs/build-support/fetchzip/default.nix
···13, ... } @ args:
1415fetchurl ({
16- # Remove the extension, because otherwise unpackPhase will get
17- # confused. FIXME: fix unpackPhase.
18- name = args.name or lib.removeSuffix ".zip" (lib.removeSuffix ".tar.gz" (baseNameOf url));
1920 recursiveHash = true;
21
···13, ... } @ args:
1415fetchurl ({
16+ name = args.name or (baseNameOf url);
001718 recursiveHash = true;
19
···11 fi
12}
1314-crossEnvHooks=(${crossEnvHooks[@]} crossAddCVars)
1516crossStripDirs() {
17 local dirs="$1"
···11 fi
12}
1314+crossEnvHooks+=(crossAddCVars)
1516crossStripDirs() {
17 local dirs="$1"
+3-1
pkgs/build-support/gcc-wrapper/setup-hook.sh
···001addCVars () {
2 if test -d $1/include; then
3 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
···12 fi
13}
1415-envHooks=(${envHooks[@]} addCVars)
1617# Note: these come *after* $out in the PATH (see setup.sh).
18
···1+export NIX_GCC=@out@
2+3addCVars () {
4 if test -d $1/include; then
5 export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
···14 fi
15}
1617+envHooks+=(addCVars)
1819# Note: these come *after* $out in the PATH (see setup.sh).
20
···1+fixupOutputHooks+=('if [ -z "$dontGzipMan" ]; then compressManPages "$prefix"; fi')
2+3+compressManPages() {
4+ local dir="$1"
5+6+ echo "gzipping man pages in $dir"
7+8+ GLOBIGNORE=.:..:*.gz:*.bz2
9+10+ for f in "$dir"/share/man/*/* "$dir"/share/man/*/*/*; do
11+ if [ -f "$f" -a ! -L "$f" ]; then
12+ if gzip -c -n "$f" > "$f".gz; then
13+ rm "$f"
14+ else
15+ rm "$f".gz
16+ fi
17+ fi
18+ done
19+20+ for f in "$dir"/share/man/*/* "$dir"/share/man/*/*/*; do
21+ if [ -L "$f" -a -f `readlink -f "$f"`.gz ]; then
22+ ln -sf `readlink "$f"`.gz "$f".gz && rm "$f"
23+ fi
24+ done
25+26+ unset GLOBIGNORE
27+}
···1+# This setup hook moves $out/{man,doc,info} to $out/share; moves
2+# $out/share/man to $man/share/man; and moves $out/share/doc to
3+# $man/share/doc.
4+5+preFixupHooks+=(_moveDocs)
6+7+_moveToShare() {
8+ forceShare=${forceShare:=man doc info}
9+ if [ -z "$forceShare" -o -z "$out" ]; then return; fi
10+11+ for d in $forceShare; do
12+ if [ -d "$out/$d" ]; then
13+ if [ -d "$out/share/$d" ]; then
14+ echo "both $d/ and share/$d/ exist!"
15+ else
16+ echo "moving $out/$d to $out/share/$d"
17+ mkdir -p $out/share
18+ mv $out/$d $out/share/
19+ fi
20+ fi
21+ done
22+}
23+24+_moveToOutput() {
25+ local d="$1"
26+ local dst="$2"
27+ if [ -z "$dst" -a ! -e $dst/$d ]; then return; fi
28+ local output
29+ for output in $outputs; do
30+ if [ "${!output}" = "$dst" ]; then continue; fi
31+ if [ -d "${!output}/$d" ]; then
32+ echo "moving ${!output}/$d to $dst/$d"
33+ mkdir -p $dst/share
34+ mv ${!output}/$d $dst/$d
35+ break
36+ fi
37+ done
38+}
39+40+_moveDocs() {
41+ _moveToShare
42+ _moveToOutput share/man "$man"
43+ _moveToOutput share/info "$info"
44+ _moveToOutput share/doc "$doc"
45+46+ # Remove empty share directory.
47+ if [ -d "$out/share" ]; then
48+ rmdir $out/share 2> /dev/null || true
49+ fi
50+}
···1+# This setup hook causes the fixup phase to rewrite all script
2+# interpreter file names (`#! /path') to paths found in $PATH. E.g.,
3+# /bin/sh will be rewritten to /nix/store/<hash>-some-bash/bin/sh.
4+# /usr/bin/env gets special treatment so that ".../bin/env python" is
5+# rewritten to /nix/store/<hash>/bin/python. Interpreters that are
6+# already in the store are left untouched.
7+8+fixupOutputHooks+=('if [ -z "$dontPatchShebangs" ]; then patchShebangs "$prefix"; fi')
9+10+patchShebangs() {
11+ local dir="$1"
12+ header "patching script interpreter paths in $dir"
13+ local f
14+ local oldPath
15+ local newPath
16+ local arg0
17+ local args
18+ local oldInterpreterLine
19+ local newInterpreterLine
20+21+ find "$dir" -type f -perm +0100 | while read f; do
22+ if [ "$(head -1 "$f" | head -c +2)" != '#!' ]; then
23+ # missing shebang => not a script
24+ continue
25+ fi
26+27+ oldInterpreterLine=$(head -1 "$f" | tail -c +3)
28+ read -r oldPath arg0 args <<< "$oldInterpreterLine"
29+30+ if $(echo "$oldPath" | grep -q "/bin/env$"); then
31+ # Check for unsupported 'env' functionality:
32+ # - options: something starting with a '-'
33+ # - environment variables: foo=bar
34+ if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then
35+ echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)"
36+ exit 1
37+ fi
38+ newPath="$(command -v "$arg0" || true)"
39+ else
40+ if [ "$oldPath" = "" ]; then
41+ # If no interpreter is specified linux will use /bin/sh. Set
42+ # oldpath="/bin/sh" so that we get /nix/store/.../sh.
43+ oldPath="/bin/sh"
44+ fi
45+ newPath="$(command -v "$(basename "$oldPath")" || true)"
46+ args="$arg0 $args"
47+ fi
48+49+ newInterpreterLine="$newPath $args"
50+51+ if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then
52+ if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then
53+ echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
54+ # escape the escape chars so that sed doesn't interpret them
55+ escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
56+ sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f"
57+ fi
58+ fi
59+ done
60+61+ stopNest
62+}
···1+# This setup hook strips libraries and executables in the fixup phase.
2+3+fixupOutputHooks+=(_doStrip)
4+5+_doStrip() {
6+ if [ -z "$dontStrip" ]; then
7+ stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin}
8+ if [ -n "$stripDebugList" ]; then
9+ stripDirs "$stripDebugList" "${stripDebugFlags:--S}"
10+ fi
11+12+ stripAllList=${stripAllList:-}
13+ if [ -n "$stripAllList" ]; then
14+ stripDirs "$stripAllList" "${stripAllFlags:--s}"
15+ fi
16+ fi
17+}
18+19+stripDirs() {
20+ local dirs="$1"
21+ local stripFlags="$2"
22+ local dirsNew=
23+24+ for d in ${dirs}; do
25+ if [ -d "$prefix/$d" ]; then
26+ dirsNew="${dirsNew} $prefix/$d "
27+ fi
28+ done
29+ dirs=${dirsNew}
30+31+ if [ -n "${dirs}" ]; then
32+ header "stripping (with flags $stripFlags) in$dirs"
33+ find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} strip $commonStripFlags $stripFlags || true
34+ stopNest
35+ fi
36+}
+1-1
pkgs/desktops/e17/e_dbus/setup-hook.sh
···5 fi
6}
78-envHooks=(${envHooks[@]} addDbusIncludePath)
···23 # xmllint and xsltproc from looking in /etc/xml/catalog.
24 export XML_CATALOG_FILES
25 if test -z "$XML_CATALOG_FILES"; then XML_CATALOG_FILES=" "; fi
26- envHooks=(${envHooks[@]} addXMLCatalogs)
27fi
···23 # xmllint and xsltproc from looking in /etc/xml/catalog.
24 export XML_CATALOG_FILES
25 if test -z "$XML_CATALOG_FILES"; then XML_CATALOG_FILES=" "; fi
26+ envHooks+=(addXMLCatalogs)
27fi
+1-1
pkgs/development/libraries/slib/setup-hook.sh
···10 fi
11}
1213-envHooks=(${envHooks[@]} addSlibPath)
···1+# This setup hook calls patchelf to automatically remove unneeded
2+# directories from the RPATH of every library or executable in every
3+# output.
4+5+fixupOutputHooks+=('if [ -z "$dontPatchELF" ]; then patchELF "$prefix"; fi')
6+7+patchELF() {
8+ header "patching ELF executables and libraries in $prefix"
9+ if [ -e "$prefix" ]; then
10+ find "$prefix" \( \
11+ \( -type f -a -name "*.so*" \) -o \
12+ \( -type f -a -perm +0100 \) \
13+ \) -print -exec patchelf --shrink-rpath '{}' \;
14+ fi
15+ stopNest
16+}
···18 "MANDIR=share/man/man1"
19 ];
200021 meta = with stdenv.lib; {
22 description = "A tool for controlling PaX flags on a per binary basis";
23 homepage = "https://pax.grsecurity.net";
···18 "MANDIR=share/man/man1"
19 ];
2021+ setupHook = ./setup-hook.sh;
22+23 meta = with stdenv.lib; {
24 description = "A tool for controlling PaX flags on a per binary basis";
25 homepage = "https://pax.grsecurity.net";
···5# Posix utilities, the GNU C compiler, and so on. On other systems,
6# we use the native C library.
78-{ system, allPackages ? import ../.., platform, config }:
91011rec {
···2829 # The Nix build environment.
30 stdenvNix = import ./nix {
31- inherit config;
32 stdenv = stdenvNative;
33 pkgs = stdenvNativePkgs;
34 };
353637 # Linux standard environment.
38- stdenvLinux = (import ./linux { inherit system allPackages platform config;}).stdenvLinux;
394041 # Select the appropriate stdenv for the platform `system'.
···5# Posix utilities, the GNU C compiler, and so on. On other systems,
6# we use the native C library.
78+{ system, allPackages ? import ../.., platform, config, lib }:
91011rec {
···2829 # The Nix build environment.
30 stdenvNix = import ./nix {
31+ inherit config lib;
32 stdenv = stdenvNative;
33 pkgs = stdenvNativePkgs;
34 };
353637 # Linux standard environment.
38+ stdenvLinux = (import ./linux { inherit system allPackages platform config lib; }).stdenvLinux;
394041 # Select the appropriate stdenv for the platform `system'.
+3-8
pkgs/stdenv/generic/builder.sh
···67mkdir $out
89-echo "$preHook" > $out/setup
0010cat "$setup" >> $out/setup
11-12-sed -e "s^@initialPath@^$initialPath^g" \
13- -e "s^@gcc@^$gcc^g" \
14- -e "s^@shell@^$shell^g" \
15- -e "s^@needsPax@^$needsPax^g" \
16- < $out/setup > $out/setup.tmp
17-mv $out/setup.tmp $out/setup
1819# Allow the user to install stdenv using nix-env and get the packages
20# in stdenv.
···67mkdir $out
89+echo "export SHELL=$shell" > $out/setup
10+echo "initialPath=\"$initialPath\"" >> $out/setup
11+echo "$preHook" >> $out/setup
12cat "$setup" >> $out/setup
00000001314# Allow the user to install stdenv using nix-env and get the packages
15# in stdenv.
+86-81
pkgs/stdenv/generic/default.nix
···10, setupScript ? ./setup.sh
1112, extraBuildInputs ? []
13-14-, skipPaxMarking ? false
15}:
1617let
···23 # {pkgs, ...}:
24 # {
25 # allowUnfree = false;
26- # allowUnfreePredicate = (x: pkgs.lib.hasPrefix "flashplayero-" x.name);
27 # }
28 allowUnfreePredicate = config.allowUnfreePredicate or (x: false);
29···4142 unsafeGetAttrPos = builtins.unsafeGetAttrPos or (n: as: null);
43000000000000000000000000000000000000000000000000000000000000000000000000000044 # The stdenv that we are producing.
45 result =
46···50 builder = shell;
5152 args = ["-e" ./builder.sh];
53- /* TODO: special-cased @var@ substitutions are ugly.
54- However, using substituteAll* from setup.sh seems difficult,
55- as setup.sh can't be directly sourced.
56- Suggestion: split similar utility functions into a separate script.
57- */
5859 setup = setupScript;
6061- inherit preHook initialPath gcc shell;
62-63- # Whether we should run paxctl to pax-mark binaries
64- needsPax = result.isLinux && !skipPaxMarking;
6566 propagatedUserEnvPkgs = [gcc] ++
67 lib.filter lib.isDerivation initialPath;
···6970 // rec {
7172- meta = {
73- description = "The default build environment for Unix packages in Nixpkgs";
74- };
75-76- # Add a utility function to produce derivations that use this
77- # stdenv and its shell.
78- mkDerivation = attrs:
79- let
80- pos =
81- if attrs.meta.description or null != null then
82- unsafeGetAttrPos "description" attrs.meta
83- else
84- unsafeGetAttrPos "name" attrs;
85- pos' = if pos != null then "‘" + pos.file + ":" + toString pos.line + "’" else "«unknown-file»";
86- in
87- 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
88- throw ''
89- Package ‘${attrs.name}’ in ${pos'} has an unfree license, refusing to evaluate.
90- ${forceEvalHelp "Unfree"}''
91- else if !allowBroken && attrs.meta.broken or false then
92- throw ''
93- Package ‘${attrs.name}’ in ${pos'} is marked as broken, refusing to evaluate.
94- ${forceEvalHelp "Broken"}''
95- else if !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem result.system attrs.meta.platforms then
96- throw ''
97- Package ‘${attrs.name}’ in ${pos'} is not supported on ‘${result.system}’, refusing to evaluate.
98- ${forceEvalHelp "Broken"}''
99- else
100- lib.addPassthru (derivation (
101- (removeAttrs attrs ["meta" "passthru" "crossAttrs"])
102- // (let
103- buildInputs = attrs.buildInputs or [];
104- nativeBuildInputs = attrs.nativeBuildInputs or [];
105- propagatedBuildInputs = attrs.propagatedBuildInputs or [];
106- propagatedNativeBuildInputs = attrs.propagatedNativeBuildInputs or [];
107- crossConfig = attrs.crossConfig or null;
108- in
109- {
110- builder = attrs.realBuilder or shell;
111- args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)];
112- stdenv = result;
113- system = result.system;
114- userHook = config.stdenv.userHook or null;
115- __ignoreNulls = true;
116-117- # Inputs built by the cross compiler.
118- buildInputs = lib.optionals (crossConfig != null) (buildInputs ++ extraBuildInputs);
119- propagatedBuildInputs = lib.optionals (crossConfig != null) propagatedBuildInputs;
120- # Inputs built by the usual native compiler.
121- nativeBuildInputs = nativeBuildInputs ++ lib.optionals (crossConfig == null) (buildInputs ++ extraBuildInputs);
122- propagatedNativeBuildInputs = propagatedNativeBuildInputs ++
123- lib.optionals (crossConfig == null) propagatedBuildInputs;
124- }))) (
125- {
126- # The meta attribute is passed in the resulting attribute set,
127- # but it's not part of the actual derivation, i.e., it's not
128- # passed to the builder and is not a dependency. But since we
129- # include it in the result, it *is* available to nix-env for
130- # queries. We also a meta.position attribute here to
131- # identify the source location of the package.
132- meta = attrs.meta or {} // (if pos != null then {
133- position = pos.file + ":" + (toString pos.line);
134- } else {});
135- passthru = attrs.passthru or {};
136- } //
137- # Pass through extra attributes that are not inputs, but
138- # should be made available to Nix expressions using the
139- # derivation (e.g., in assertions).
140- (attrs.passthru or {}));
141142 # Utility flags to test the type of platform.
143 isDarwin = system == "x86_64-darwin";
···185 || system == "armv6l-linux"
186 || system == "armv7l-linux";
18700000188 # For convenience, bring in the library functions in lib/ so
189 # packages don't have to do that themselves.
190 inherit lib;
···192 inherit fetchurlBoot;
193194 inherit overrides;
00195 }
196197 # Propagate any extra attributes. For instance, we use this to
···10, setupScript ? ./setup.sh
1112, extraBuildInputs ? []
0013}:
1415let
···21 # {pkgs, ...}:
22 # {
23 # allowUnfree = false;
24+ # allowUnfreePredicate = (x: pkgs.lib.hasPrefix "flashplayer-" x.name);
25 # }
26 allowUnfreePredicate = config.allowUnfreePredicate or (x: false);
27···3940 unsafeGetAttrPos = builtins.unsafeGetAttrPos or (n: as: null);
4142+ extraBuildInputs' = extraBuildInputs ++
43+ [ ../../build-support/setup-hooks/move-docs.sh
44+ ../../build-support/setup-hooks/compress-man-pages.sh
45+ ../../build-support/setup-hooks/strip.sh
46+ ../../build-support/setup-hooks/patch-shebangs.sh
47+ gcc
48+ ];
49+50+ # Add a utility function to produce derivations that use this
51+ # stdenv and its shell.
52+ mkDerivation = attrs:
53+ let
54+ pos =
55+ if attrs.meta.description or null != null then
56+ unsafeGetAttrPos "description" attrs.meta
57+ else
58+ unsafeGetAttrPos "name" attrs;
59+ pos' = if pos != null then "‘" + pos.file + ":" + toString pos.line + "’" else "«unknown-file»";
60+ in
61+ if !allowUnfree
62+ && (let l = lib.lists.toList attrs.meta.license or []; in lib.lists.elem "unfree" l || lib.lists.elem "unfree-redistributable" l)
63+ && !allowUnfreePredicate attrs then
64+ throw ''
65+ Package ‘${attrs.name}’ in ${pos'} has an unfree license, refusing to evaluate.
66+ ${forceEvalHelp "Unfree"}''
67+ else if !allowBroken && attrs.meta.broken or false then
68+ throw ''
69+ Package ‘${attrs.name}’ in ${pos'} is marked as broken, refusing to evaluate.
70+ ${forceEvalHelp "Broken"}''
71+ else if !allowBroken && attrs.meta.platforms or null != null && !lib.lists.elem result.system attrs.meta.platforms then
72+ throw ''
73+ Package ‘${attrs.name}’ in ${pos'} is not supported on ‘${result.system}’, refusing to evaluate.
74+ ${forceEvalHelp "Broken"}''
75+ else
76+ lib.addPassthru (derivation (
77+ (removeAttrs attrs ["meta" "passthru" "crossAttrs"])
78+ // (let
79+ buildInputs = attrs.buildInputs or [];
80+ nativeBuildInputs = attrs.nativeBuildInputs or [];
81+ propagatedBuildInputs = attrs.propagatedBuildInputs or [];
82+ propagatedNativeBuildInputs = attrs.propagatedNativeBuildInputs or [];
83+ crossConfig = attrs.crossConfig or null;
84+ in
85+ {
86+ builder = attrs.realBuilder or shell;
87+ args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)];
88+ stdenv = result;
89+ system = result.system;
90+ userHook = config.stdenv.userHook or null;
91+ __ignoreNulls = true;
92+93+ # Inputs built by the cross compiler.
94+ buildInputs = lib.optionals (crossConfig != null) (buildInputs ++ extraBuildInputs');
95+ propagatedBuildInputs = lib.optionals (crossConfig != null) propagatedBuildInputs;
96+ # Inputs built by the usual native compiler.
97+ nativeBuildInputs = nativeBuildInputs ++ lib.optionals (crossConfig == null) (buildInputs ++ extraBuildInputs');
98+ propagatedNativeBuildInputs = propagatedNativeBuildInputs ++
99+ lib.optionals (crossConfig == null) propagatedBuildInputs;
100+ }))) (
101+ {
102+ # The meta attribute is passed in the resulting attribute set,
103+ # but it's not part of the actual derivation, i.e., it's not
104+ # passed to the builder and is not a dependency. But since we
105+ # include it in the result, it *is* available to nix-env for
106+ # queries. We also a meta.position attribute here to
107+ # identify the source location of the package.
108+ meta = attrs.meta or {} // (if pos != null then {
109+ position = pos.file + ":" + (toString pos.line);
110+ } else {});
111+ passthru = attrs.passthru or {};
112+ } //
113+ # Pass through extra attributes that are not inputs, but
114+ # should be made available to Nix expressions using the
115+ # derivation (e.g., in assertions).
116+ (attrs.passthru or {}));
117+118 # The stdenv that we are producing.
119 result =
120···124 builder = shell;
125126 args = ["-e" ./builder.sh];
00000127128 setup = setupScript;
129130+ inherit preHook initialPath shell;
000131132 propagatedUserEnvPkgs = [gcc] ++
133 lib.filter lib.isDerivation initialPath;
···135136 // rec {
137138+ meta.description = "The default build environment for Unix packages in Nixpkgs";
00000000000000000000000000000000000000000000000000000000000000000000139140 # Utility flags to test the type of platform.
141 isDarwin = system == "x86_64-darwin";
···183 || system == "armv6l-linux"
184 || system == "armv7l-linux";
185186+ # Whether we should run paxctl to pax-mark binaries.
187+ needsPax = isLinux;
188+189+ inherit mkDerivation;
190+191 # For convenience, bring in the library functions in lib/ so
192 # packages don't have to do that themselves.
193 inherit lib;
···195 inherit fetchurlBoot;
196197 inherit overrides;
198+199+ inherit gcc;
200 }
201202 # Propagate any extra attributes. For instance, we use this to
+146-252
pkgs/stdenv/generic/setup.sh
···1-# Run the named hook, either by calling the function with that name or
2-# by evaluating the variable with that name. This allows convenient
3-# setting of hooks both from Nix expressions (as attributes /
4-# environment variables) and from shell scripts (as functions).
0000000005runHook() {
6 local hookName="$1"
0000000000000000000000000000000000007 case "$(type -t $hookName)" in
8 (function|alias|builtin) $hookName;;
9 (file) source $hookName;;
10 (keyword) :;;
11- (*) eval "${!hookName}";;
12 esac
13}
1415000000000000000016exitHandler() {
17 exitCode=$?
18 set +e
···555657######################################################################
58-# Helper functions that might be useful in setup hooks.
596061addToSearchPathWithCustomDelimiter() {
···74}
757677-######################################################################
78-# Initialisation.
000000000007980-set -e
8182-[ -z $NIX_GCC ] && NIX_GCC=@gcc@
0838485# Wildcard expansions that don't match should expand to an empty list.
···9091# Set up the initial path.
92PATH=
93-for i in $NIX_GCC @initialPath@; do
94 if [ "$i" = / ]; then i=; fi
95 addToSearchPath PATH $i/bin
96 addToSearchPath PATH $i/sbin
···101fi
102103104-# Execute the pre-hook.
105-export SHELL=@shell@
106-export CONFIG_SHELL="$SHELL"
107-if [ -z "$shell" ]; then export shell=@shell@; fi
108-runHook preHook
109-110-111# Check that the pre-hook initialised SHELL.
112if [ -z "$SHELL" ]; then echo "SHELL not set"; exit 1; fi
113114-# Hack: run gcc's setup hook.
115-envHooks=()
116-crossEnvHooks=()
117-if [ -f $NIX_GCC/nix-support/setup-hook ]; then
118- source $NIX_GCC/nix-support/setup-hook
119-fi
120121-122-# Ensure that the given directories exists.
123-ensureDir() {
124- echo "warning: ‘ensureDir’ is deprecated; use ‘mkdir’ instead" >&2
125- local dir
126- for dir in "$@"; do
127- if ! [ -x "$dir" ]; then mkdir -p "$dir"; fi
128- done
129-}
130-131-installBin() {
132- mkdir -p $out/bin
133- cp "$@" $out/bin
134-}
135136137# Allow the caller to augment buildInputs (it's not always possible to
···154155 eval $var="'${!var} $pkg '"
1560000157 if [ -f $pkg/nix-support/setup-hook ]; then
158 source $pkg/nix-support/setup-hook
159 fi
···178179# Set the relevant environment variables to point to the build inputs
180# found above.
181-addToNativeEnv() {
182 local pkg=$1
183184 if [ -d $1/bin ]; then
···186 fi
187188 # Run the package-specific hooks set by the setup-hook scripts.
189- for i in "${envHooks[@]}"; do
190- $i $pkg
191- done
192}
193194for i in $nativePkgs; do
195- addToNativeEnv $i
196done
197198-addToCrossEnv() {
199 local pkg=$1
200201 # Some programs put important build scripts (freetype-config and similar)
···206 fi
207208 # Run the package-specific hooks set by the setup-hook scripts.
209- for i in "${crossEnvHooks[@]}"; do
210- $i $pkg
211- done
212}
213214for i in $crossPkgs; do
215- addToCrossEnv $i
216done
217218···273export NIX_BUILD_CORES
274275276-######################################################################
277-# Misc. helper functions.
0278279280-stripDirs() {
281- local dirs="$1"
282- local stripFlags="$2"
283- local dirsNew=
284-285- for d in ${dirs}; do
286- if [ -d "$prefix/$d" ]; then
287- dirsNew="${dirsNew} $prefix/$d "
288- fi
289- done
290- dirs=${dirsNew}
291-292- if [ -n "${dirs}" ]; then
293- header "stripping (with flags $stripFlags) in $dirs"
294- find $dirs -type f -print0 | xargs -0 ${xargsFlags:--r} strip $commonStripFlags $stripFlags || true
295- stopNest
296- fi
297-}
298-299-# PaX-mark binaries
300-paxmark() {
301- local flags="$1"
302- shift
303-304- if [ -z "@needsPax@" ]; then
305- return
306- fi
307-308- paxctl -c "$@"
309- paxctl -zex -${flags} "$@"
310-}
311-312######################################################################
313# Textual substitution functions.
314···439}
440441442-unpackFile() {
443- curSrc="$1"
444- local cmd
445446- header "unpacking source archive $curSrc" 3
447448- case "$curSrc" in
449- *.tar.xz | *.tar.lzma)
450- # Don't rely on tar knowing about .xz.
451- xz -d < $curSrc | tar xf -
452- ;;
453- *.tar | *.tar.* | *.tgz | *.tbz2)
454- # GNU tar can automatically select the decompression method
455- # (info "(tar) gzip").
456- tar xf $curSrc
457- ;;
458- *.zip)
459- unzip -qq $curSrc
460- ;;
461- *)
462- if [ -d "$curSrc" ]; then
463- stripHash $curSrc
464- cp -prd --no-preserve=timestamps $curSrc $strippedName
465- else
466- if [ -z "$unpackCmd" ]; then
467- echo "source archive $curSrc has unknown type"
468- exit 1
469- fi
470- runHook unpackCmd
471- fi
472- ;;
473- esac
47400000000000000000000000000475 stopNest
476}
477···505506 # Find the source directory.
507 if [ -n "$setSourceRoot" ]; then
508- runHook setSourceRoot
509 elif [ -z "$sourceRoot" ]; then
510 sourceRoot=
511 for i in *; do
···654}
655656657-patchELF() {
658- # Patch all ELF executables and shared libraries.
659- header "patching ELF executables and libraries"
660- if [ -e "$prefix" ]; then
661- find "$prefix" \( \
662- \( -type f -a -name "*.so*" \) -o \
663- \( -type f -a -perm +0100 \) \
664- \) -print -exec patchelf --shrink-rpath '{}' \;
665- fi
666- stopNest
667-}
668-669-670-patchShebangs() {
671- # Rewrite all script interpreter file names (`#! /path') under the
672- # specified directory tree to paths found in $PATH. E.g.,
673- # /bin/sh will be rewritten to /nix/store/<hash>-some-bash/bin/sh.
674- # /usr/bin/env gets special treatment so that ".../bin/env python" is
675- # rewritten to /nix/store/<hash>/bin/python.
676- # Interpreters that are already in the store are left untouched.
677- header "patching script interpreter paths"
678- local dir="$1"
679- local f
680- local oldPath
681- local newPath
682- local arg0
683- local args
684- local oldInterpreterLine
685- local newInterpreterLine
686-687- find "$dir" -type f -perm +0100 | while read f; do
688- if [ "$(head -1 "$f" | head -c +2)" != '#!' ]; then
689- # missing shebang => not a script
690- continue
691- fi
692-693- oldInterpreterLine=$(head -1 "$f" | tail -c +3)
694- read -r oldPath arg0 args <<< "$oldInterpreterLine"
695-696- if $(echo "$oldPath" | grep -q "/bin/env$"); then
697- # Check for unsupported 'env' functionality:
698- # - options: something starting with a '-'
699- # - environment variables: foo=bar
700- if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then
701- echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)"
702- exit 1
703- fi
704- newPath="$(command -v "$arg0" || true)"
705- else
706- if [ "$oldPath" = "" ]; then
707- # If no interpreter is specified linux will use /bin/sh. Set
708- # oldpath="/bin/sh" so that we get /nix/store/.../sh.
709- oldPath="/bin/sh"
710- fi
711- newPath="$(command -v "$(basename "$oldPath")" || true)"
712- args="$arg0 $args"
713- fi
714-715- newInterpreterLine="$newPath $args"
716-717- if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then
718- if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then
719- echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
720- # escape the escape chars so that sed doesn't interpret them
721- escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
722- sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f"
723- fi
724- fi
725- done
726-727- stopNest
728-}
729-730-731installPhase() {
732 runHook preInstall
733···743}
744745746-# The fixup phase performs generic, package-independent, Nix-related
747-# stuff, like running patchelf and setting the
748-# propagated-build-inputs. It should rarely be overriden.
749fixupPhase() {
750- runHook preFixup
751-752 # Make sure everything is writable so "strip" et al. work.
753- if [ -e "$prefix" ]; then chmod -R u+w "$prefix"; fi
754-755- # Put man/doc/info under $out/share.
756- forceShare=${forceShare:=man doc info}
757- if [ -n "$forceShare" ]; then
758- for d in $forceShare; do
759- if [ -d "$prefix/$d" ]; then
760- if [ -d "$prefix/share/$d" ]; then
761- echo "both $d/ and share/$d/ exists!"
762- else
763- echo "fixing location of $d/ subdirectory"
764- mkdir -p $prefix/share
765- if [ -w $prefix/share ]; then
766- mv -v $prefix/$d $prefix/share
767- ln -sv share/$d $prefix
768- fi
769- fi
770- fi
771- done;
772- fi
773774- if [ -z "$dontGzipMan" ]; then
775- echo "gzipping man pages"
776- GLOBIGNORE=.:..:*.gz:*.bz2
777- for f in "$out"/share/man/*/* "$out"/share/man/*/*/*; do
778- if [ -f "$f" -a ! -L "$f" ]; then
779- if gzip -c -n "$f" > "$f".gz; then
780- rm "$f"
781- else
782- rm "$f".gz
783- fi
784- fi
785- done
786- for f in "$out"/share/man/*/* "$out"/share/man/*/*/*; do
787- if [ -L "$f" -a -f `readlink -f "$f"`.gz ]; then
788- ln -sf `readlink "$f"`.gz "$f".gz && rm "$f"
789- fi
790- done
791- unset GLOBIGNORE
792- fi
793794- # TODO: strip _only_ ELF executables, and return || fail here...
795- if [ -z "$dontStrip" ]; then
796- stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin}
797- if [ -n "$stripDebugList" ]; then
798- stripDirs "$stripDebugList" "${stripDebugFlags:--S}"
799- fi
800-801- stripAllList=${stripAllList:-}
802- if [ -n "$stripAllList" ]; then
803- stripDirs "$stripAllList" "${stripAllFlags:--s}"
804- fi
805- fi
806-807- if [ "$havePatchELF" = 1 -a -z "$dontPatchELF" ]; then
808- patchELF "$prefix"
809- fi
810-811- if [ -z "$dontPatchShebangs" ]; then
812- patchShebangs "$prefix"
813- fi
814815 if [ -n "$propagatedBuildInputs" ]; then
816 mkdir -p "$out/nix-support"
···935936937# Execute the post-hooks.
938-for i in "${postHooks[@]}"; do $i; done
939runHook postHook
940941
···1+set -e
2+3+: ${outputs:=out}
4+5+6+######################################################################
7+# Hook handling.
8+9+10+# Run all hooks with the specified name in the order in which they
11+# were added, stopping if any fails (returns a non-zero exit
12+# code). The hooks for <hookName> are the shell function or variable
13+# <hookName>, and the values of the shell array ‘<hookName>Hooks’.
14runHook() {
15 local hookName="$1"
16+ shift
17+ local var="$hookName"
18+ if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
19+ eval "local -a dummy=(\"\${$var[@]}\")"
20+ for hook in "_callImplicitHook 0 $hookName" "${dummy[@]}"; do
21+ if ! _eval "$hook" "$@"; then return 1; fi
22+ done
23+ return 0
24+}
25+26+27+# Run all hooks with the specified name, until one succeeds (returns a
28+# zero exit code). If none succeed, return a non-zero exit code.
29+runOneHook() {
30+ local hookName="$1"
31+ shift
32+ local var="$hookName"
33+ if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
34+ eval "local -a dummy=(\"\${$var[@]}\")"
35+ for hook in "_callImplicitHook 1 $hookName" "${dummy[@]}"; do
36+ if _eval "$hook" "$@"; then
37+ return 0
38+ fi
39+ done
40+ return 1
41+}
42+43+44+# Run the named hook, either by calling the function with that name or
45+# by evaluating the variable with that name. This allows convenient
46+# setting of hooks both from Nix expressions (as attributes /
47+# environment variables) and from shell scripts (as functions). If you
48+# want to allow multiple hooks, use runHook instead.
49+_callImplicitHook() {
50+ local def="$1"
51+ local hookName="$2"
52 case "$(type -t $hookName)" in
53 (function|alias|builtin) $hookName;;
54 (file) source $hookName;;
55 (keyword) :;;
56+ (*) if [ -z "${!hookName}" ]; then return "$def"; else eval "${!hookName}"; fi;;
57 esac
58}
596061+# A function wrapper around ‘eval’ that ensures that ‘return’ inside
62+# hooks exits the hook, not the caller.
63+_eval() {
64+ local code="$1"
65+ shift
66+ if [ "$(type -t $code)" = function ]; then
67+ eval "$code \"\$@\""
68+ else
69+ eval "$code"
70+ fi
71+}
72+73+74+######################################################################
75+# Error handling.
76+77exitHandler() {
78 exitCode=$?
79 set +e
···116117118######################################################################
119+# Helper functions.
120121122addToSearchPathWithCustomDelimiter() {
···135}
136137138+ensureDir() {
139+ echo "warning: ‘ensureDir’ is deprecated; use ‘mkdir’ instead" >&2
140+ local dir
141+ for dir in "$@"; do
142+ if ! [ -x "$dir" ]; then mkdir -p "$dir"; fi
143+ done
144+}
145+146+147+installBin() {
148+ mkdir -p $out/bin
149+ cp "$@" $out/bin
150+}
1510152153+######################################################################
154+# Initialisation.
155156157# Wildcard expansions that don't match should expand to an empty list.
···162163# Set up the initial path.
164PATH=
165+for i in $initialPath; do
166 if [ "$i" = / ]; then i=; fi
167 addToSearchPath PATH $i/bin
168 addToSearchPath PATH $i/sbin
···173fi
1741750000000176# Check that the pre-hook initialised SHELL.
177if [ -z "$SHELL" ]; then echo "SHELL not set"; exit 1; fi
178000000179180+# Execute the pre-hook.
181+export CONFIG_SHELL="$SHELL"
182+if [ -z "$shell" ]; then export shell=$SHELL; fi
00000000000183184185# Allow the caller to augment buildInputs (it's not always possible to
···202203 eval $var="'${!var} $pkg '"
204205+ if [ -f $pkg ]; then
206+ source $pkg
207+ fi
208+209 if [ -f $pkg/nix-support/setup-hook ]; then
210 source $pkg/nix-support/setup-hook
211 fi
···230231# Set the relevant environment variables to point to the build inputs
232# found above.
233+_addToNativeEnv() {
234 local pkg=$1
235236 if [ -d $1/bin ]; then
···238 fi
239240 # Run the package-specific hooks set by the setup-hook scripts.
241+ runHook envHook "$pkg"
00242}
243244for i in $nativePkgs; do
245+ _addToNativeEnv $i
246done
247248+_addToCrossEnv() {
249 local pkg=$1
250251 # Some programs put important build scripts (freetype-config and similar)
···256 fi
257258 # Run the package-specific hooks set by the setup-hook scripts.
259+ runHook crossEnvHook "$pkg"
00260}
261262for i in $crossPkgs; do
263+ _addToCrossEnv $i
264done
265266···321export NIX_BUILD_CORES
322323324+# Dummy implementation of the paxmark function. On Linux, this is
325+# overwritten by paxctl's setup hook.
326+paxmark() { true; }
32732800000000000000000000000000000000329######################################################################
330# Textual substitution functions.
331···456}
457458459+unpackCmdHooks+=(_defaultUnpack)
460+_defaultUnpack() {
461+ local fn="$1"
462463+ if [ -d "$fn" ]; then
464465+ stripHash "$fn"
466+ cp -prd --no-preserve=timestamps "$fn" $strippedName
467+468+ else
0000000000000000000000469470+ case "$fn" in
471+ *.tar.xz | *.tar.lzma)
472+ # Don't rely on tar knowing about .xz.
473+ xz -d < "$fn" | tar xf -
474+ ;;
475+ *.tar | *.tar.* | *.tgz | *.tbz2)
476+ # GNU tar can automatically select the decompression method
477+ # (info "(tar) gzip").
478+ tar xf "$fn"
479+ ;;
480+ *)
481+ return 1
482+ ;;
483+ esac
484+485+ fi
486+}
487+488+489+unpackFile() {
490+ curSrc="$1"
491+ header "unpacking source archive $curSrc" 3
492+ if ! runOneHook unpackCmd "$curSrc"; then
493+ echo "do not know how to unpack source archive $curSrc"
494+ exit 1
495+ fi
496 stopNest
497}
498···526527 # Find the source directory.
528 if [ -n "$setSourceRoot" ]; then
529+ runOneHook setSourceRoot
530 elif [ -z "$sourceRoot" ]; then
531 sourceRoot=
532 for i in *; do
···675}
67667700000000000000000000000000000000000000000000000000000000000000000000000000678installPhase() {
679 runHook preInstall
680···690}
691692693+# The fixup phase performs generic, package-independent stuff, like
694+# stripping binaries, running patchelf and setting
695+# propagated-build-inputs.
696fixupPhase() {
00697 # Make sure everything is writable so "strip" et al. work.
698+ for output in $outputs; do
699+ if [ -e "${!output}" ]; then chmod -R u+w "${!output}"; fi
700+ done
00000000000000000701702+ runHook preFixup
000000000000000000703704+ # Apply fixup to each output.
705+ local output
706+ for output in $outputs; do
707+ prefix=${!output} runHook fixupOutput
708+ done
000000000000000709710 if [ -n "$propagatedBuildInputs" ]; then
711 mkdir -p "$out/nix-support"
···830831832# Execute the post-hooks.
0833runHook postHook
834835
+8-14
pkgs/stdenv/linux/default.nix
···7# The function defaults are for easy testing.
8{ system ? builtins.currentSystem
9, allPackages ? import ../../top-level/all-packages.nix
10-, platform ? null, config ? {} }:
1112rec {
13-14- lib = import ../../../lib;
1516 bootstrapFiles =
17 if system == "i686-linux" then import ./bootstrap/i686.nix
···26 commonPreHook =
27 ''
28 export NIX_ENFORCE_PURITY=1
29- havePatchELF=1
30 ${if system == "x86_64-linux" then "NIX_LIB64_IN_SELF_RPATH=1" else ""}
31 ${if system == "mips64el-linux" then "NIX_LIB32_IN_SELF_RPATH=1" else ""}
32 '';
···209 extraAttrs = {
210 glibc = stage2.pkgs.glibc; # Required by gcc47 build
211 };
212- extraPath = [ stage2.pkgs.paxctl ];
213 };
214215···223 coreutils = bootstrapTools;
224 name = "";
225 };
226- extraPath = [ stage3.pkgs.xz ];
227 overrides = pkgs: {
228- # Zlib has to be inherited and not rebuilt in this stage,
229- # because gcc (since JAR support) already depends on zlib, and
230- # then if we already have a zlib we want to use that for the
231- # other purposes (binutils and top-level pkgs) too.
232- inherit (stage3.pkgs) gettext gnum4 gmp perl glibc zlib;
233 };
234 };
235···253 '';
254255 initialPath =
256- ((import ../common-path.nix) {pkgs = stage4.pkgs;})
257- ++ [stage4.pkgs.patchelf stage4.pkgs.paxctl ];
0258259 shell = stage4.pkgs.bash + "/bin/bash";
260···278 inherit (stage4.pkgs)
279 gzip bzip2 xz bash binutils coreutils diffutils findutils gawk
280 glibc gnumake gnused gnutar gnugrep gnupatch patchelf
281- attr acl paxctl zlib;
282 };
283 };
284