git.iko.soy/typeable/nixpkgs
on master help sign in
Merge commit 'b1f5305abd7b1b3d7ed180d9d00301da6e323e41' into HEAD
commit9f73f22c640a1cd03f64a9b028f8c7df66d63fdd authorFrederik Rietdijk <fridh@fridh.nl> dateThu 10 Aug 2017, 19:26 (9 years ago) parent13704f5b1f5305
21 files changed+407−241
pkgs/applications/virtualization/xen/packages.nix−4 pkgs/build-support/cc-wrapper/add-flags.sh+65−14 pkgs/build-support/cc-wrapper/add-hardening.sh+21−19 pkgs/build-support/cc-wrapper/cc-wrapper.sh+24−21 pkgs/build-support/cc-wrapper/default.nix+31−60 pkgs/build-support/cc-wrapper/gnat-wrapper.sh+19−16 pkgs/build-support/cc-wrapper/gnatlink-wrapper.sh+11−8 pkgs/build-support/cc-wrapper/ld-wrapper.sh+37−27 pkgs/build-support/cc-wrapper/setup-hook.sh+103−17 pkgs/build-support/cc-wrapper/utils.sh+1−1 pkgs/build-support/setup-hooks/die.sh+21 pkgs/build-support/setup-hooks/make-wrapper.sh+25−23 pkgs/desktops/gnome-3/3.22/core/evolution-data-server/default.nix+1−1 pkgs/development/interpreters/python/wrapper.nix+3−1 pkgs/development/libraries/serf/default.nix+15−10 pkgs/os-specific/linux/bcc/default.nix+7−5 pkgs/stdenv/generic/setup.sh+13 pkgs/tools/archivers/unzip/default.nix+1−1 pkgs/tools/misc/screenfetch/default.nix+4−11 pkgs/tools/package-management/nix-prefetch-scripts/default.nix+1−1 pkgs/top-level/all-packages.nix+4−1
pkgs/applications/virtualization/xen/packages.nix−4
@@ -10,8 +10,6 @@ rec {
1010 xen_4_5-vanilla = callPackage ./4.5.nix {
1111 # At the very least included seabios and etherboot need gcc49,
1212 # so we have to build all of it with gcc49.
13− stdenv = overrideCC stdenv gcc49;
14−
1513 meta = {
1614 description = "vanilla";
1715 longDescription = ''
@@ -60,8 +58,6 @@ rec {
6058 xen_4_8-vanilla = callPackage ./4.8.nix {
6159 # At the very least included seabios and etherboot need gcc49,
6260 # so we have to build all of it with gcc49.
63− stdenv = overrideCC stdenv gcc49;
64−
6561 meta = {
6662 description = "vanilla";
6763 longDescription = ''
pkgs/build-support/cc-wrapper/add-flags.sh+65−14
@@ -1,37 +1,88 @@
1+# N.B. It may be a surprise that the derivation-specific variables are exported,
2+# since this is just sourced by the wrapped binaries---the end consumers. This
3+# is because one wrapper binary may invoke another (e.g. cc invoking ld). In
4+# that case, it is cheaper/better to not repeat this step and let the forked
5+# wrapped binary just inherit the work of the forker's wrapper script.
6+
7+var_templates=(
8+ NIX_CC_WRAPPER+START_HOOK
9+ NIX_CC_WRAPPER+EXEC_HOOK
10+ NIX_LD_WRAPPER+START_HOOK
11+ NIX_LD_WRAPPER+EXEC_HOOK
12+
13+ NIX+CFLAGS_COMPILE
14+ NIX+CFLAGS_LINK
15+ NIX+CXXSTDLIB_COMPILE
16+ NIX+CXXSTDLIB_LINK
17+ NIX+GNATFLAGS_COMPILE
18+ NIX+IGNORE_LD_THROUGH_GCC
19+ NIX+LDFLAGS
20+ NIX+LDFLAGS_BEFORE
21+ NIX+LDFLAGS_AFTER
22+ NIX+LDFLAGS_HARDEN
23+
24+ NIX+SET_BUILD_ID
25+ NIX+DONT_SET_RPATH
26+ NIX+ENFORCE_NO_NATIVE
27+)
28+
29+# Accumulate infixes for taking in the right input parameters. See setup-hook
30+# for details.
31+declare -a role_infixes=()
32+if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD:-}" ]; then
33+ role_infixes+=(_BUILD_)
34+fi
35+if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST:-}" ]; then
36+ role_infixes+=(_)
37+fi
38+if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_TARGET:-}" ]; then
39+ role_infixes+=(_TARGET_)
40+fi
41+
42+# We need to mangle names for hygiene, but also take parameters/overrides
43+# from the environment.
44+for var in "${var_templates[@]}"; do
45+ outputVar="${var/+/_@infixSalt@_}"
46+ export ${outputVar}+=''
47+ # For each role we serve, we accumulate the input parameters into our own
48+ # cc-wrapper-derivation-specific environment variables.
49+ for infix in "${role_infixes[@]}"; do
50+ inputVar="${var/+/${infix}}"
51+ if [ -v "$inputVar" ]; then
52+ export ${outputVar}+="${!outputVar:+ }${!inputVar}"
53+ fi
54+ done
55+done
56+
157# `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld.
2−export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE"
58+NIX_@infixSalt@_CFLAGS_COMPILE="-B@out@/bin/ $NIX_@infixSalt@_CFLAGS_COMPILE"
359
460# Export and assign separately in order that a failing $(..) will fail
561# the script.
662
763if [ -e @out@/nix-support/libc-cflags ]; then
8− export NIX_CFLAGS_COMPILE
9− NIX_CFLAGS_COMPILE="$(< @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE"
64+ NIX_@infixSalt@_CFLAGS_COMPILE="$(< @out@/nix-support/libc-cflags) $NIX_@infixSalt@_CFLAGS_COMPILE"
1065fi
1166
1267if [ -e @out@/nix-support/cc-cflags ]; then
13− export NIX_CFLAGS_COMPILE
14− NIX_CFLAGS_COMPILE="$(< @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE"
68+ NIX_@infixSalt@_CFLAGS_COMPILE="$(< @out@/nix-support/cc-cflags) $NIX_@infixSalt@_CFLAGS_COMPILE"
1569fi
1670
1771if [ -e @out@/nix-support/gnat-cflags ]; then
18− export NIX_GNATFLAGS_COMPILE
19− NIX_GNATFLAGS_COMPILE="$(< @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE"
72+ NIX_@infixSalt@_GNATFLAGS_COMPILE="$(< @out@/nix-support/gnat-cflags) $NIX_@infixSalt@_GNATFLAGS_COMPILE"
2073fi
2174
2275if [ -e @out@/nix-support/libc-ldflags ]; then
23− export NIX_LDFLAGS
24− NIX_LDFLAGS+=" $(< @out@/nix-support/libc-ldflags)"
76+ NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/libc-ldflags)"
2577fi
2678
2779if [ -e @out@/nix-support/cc-ldflags ]; then
28− export NIX_LDFLAGS
29− NIX_LDFLAGS+=" $(< @out@/nix-support/cc-ldflags)"
80+ NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/cc-ldflags)"
3081fi
3182
3283if [ -e @out@/nix-support/libc-ldflags-before ]; then
33− export NIX_LDFLAGS_BEFORE
34− NIX_LDFLAGS_BEFORE="$(< @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE"
84+ NIX_@infixSalt@_LDFLAGS_BEFORE="$(< @out@/nix-support/libc-ldflags-before) $NIX_@infixSalt@_LDFLAGS_BEFORE"
3585fi
3686
37−export NIX_CC_WRAPPER_FLAGS_SET=1
87+# That way forked processes will not extend these environment variables again.
88+export NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET=1
pkgs/build-support/cc-wrapper/add-hardening.sh+21−19
@@ -1,67 +1,69 @@
11hardeningFlags=(fortify stackprotector pic strictoverflow format relro bindnow)
2−# Intentionally word-split in case 'hardeningEnable' is defined in Nix.
3−hardeningFlags+=(${hardeningEnable[@]})
2+# Intentionally word-split in case 'hardeningEnable' is defined in
3+# Nix. Also, our bootstrap tools version of bash is old enough that
4+# undefined arrays trip `set -u`.
5+if [[ -v hardeningEnable[@] ]]; then
6+ hardeningFlags+=(${hardeningEnable[@]})
7+fi
48hardeningCFlags=()
59hardeningLDFlags=()
610
711declare -A hardeningDisableMap
812
9−# Intentionally word-split in case 'hardeningDisable' is defined in Nix. The
10−# array expansion also prevents undefined variables from causing trouble with
11−# `set -u`.
12−for flag in ${hardeningDisable[@]} @hardening_unsupported_flags@
13+# Intentionally word-split in case 'hardeningDisable' is defined in Nix.
14+for flag in ${hardeningDisable[@]:-IGNORED_KEY} @hardening_unsupported_flags@
1315do
1416 hardeningDisableMap[$flag]=1
1517done
1618
17−if [[ -n "$NIX_DEBUG" ]]; then
19+if [[ -n "${NIX_DEBUG:-}" ]]; then
1820 printf 'HARDENING: disabled flags:' >&2
1921 (( "${#hardeningDisableMap[@]}" )) && printf ' %q' "${!hardeningDisableMap[@]}" >&2
2022 echo >&2
2123fi
2224
23−if [[ -z "${hardeningDisableMap[all]}" ]]; then
24− if [[ -n "$NIX_DEBUG" ]]; then
25+if [[ -z "${hardeningDisableMap[all]:-}" ]]; then
26+ if [[ -n "${NIX_DEBUG:-}" ]]; then
2527 echo 'HARDENING: Is active (not completely disabled with "all" flag)' >&2;
2628 fi
2729 for flag in "${hardeningFlags[@]}"
2830 do
29− if [[ -z "${hardeningDisableMap[$flag]}" ]]; then
31+ if [[ -z "${hardeningDisableMap[$flag]:-}" ]]; then
3032 case $flag in
3133 fortify)
32− if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling fortify >&2; fi
34+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling fortify >&2; fi
3335 hardeningCFlags+=('-O2' '-D_FORTIFY_SOURCE=2')
3436 ;;
3537 stackprotector)
36− if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling stackprotector >&2; fi
38+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling stackprotector >&2; fi
3739 hardeningCFlags+=('-fstack-protector-strong' '--param' 'ssp-buffer-size=4')
3840 ;;
3941 pie)
40− if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling CFlags -fPIE >&2; fi
42+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling CFlags -fPIE >&2; fi
4143 hardeningCFlags+=('-fPIE')
4244 if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static ") ]]; then
43− if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling LDFlags -pie >&2; fi
45+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling LDFlags -pie >&2; fi
4446 hardeningLDFlags+=('-pie')
4547 fi
4648 ;;
4749 pic)
48− if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling pic >&2; fi
50+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling pic >&2; fi
4951 hardeningCFlags+=('-fPIC')
5052 ;;
5153 strictoverflow)
52− if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling strictoverflow >&2; fi
54+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling strictoverflow >&2; fi
5355 hardeningCFlags+=('-fno-strict-overflow')
5456 ;;
5557 format)
56− if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling format >&2; fi
58+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling format >&2; fi
5759 hardeningCFlags+=('-Wformat' '-Wformat-security' '-Werror=format-security')
5860 ;;
5961 relro)
60− if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling relro >&2; fi
62+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling relro >&2; fi
6163 hardeningLDFlags+=('-z' 'relro')
6264 ;;
6365 bindnow)
64− if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling bindnow >&2; fi
66+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling bindnow >&2; fi
6567 hardeningLDFlags+=('-z' 'now')
6668 ;;
6769 *)
pkgs/build-support/cc-wrapper/cc-wrapper.sh+24−21
@@ -1,5 +1,5 @@
11#! @shell@
2−set -e -o pipefail
2+set -eu -o pipefail
33shopt -s nullglob
44
55path_backup="$PATH"
@@ -11,12 +11,12 @@ if [[ -n "@coreutils_bin@" && -n "@gnugrep_bin@" ]]; then
1111 PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin"
1212fi
1313
14−if [ -n "$NIX_CC_WRAPPER_START_HOOK" ]; then
15− source "$NIX_CC_WRAPPER_START_HOOK"
14+if [ -z "${NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then
15+ source @out@/nix-support/add-flags.sh
1616fi
1717
18−if [ -z "$NIX_CC_WRAPPER_FLAGS_SET" ]; then
19− source @out@/nix-support/add-flags.sh
18+if [ -n "$NIX_CC_WRAPPER_@infixSalt@_START_HOOK" ]; then
19+ source "$NIX_CC_WRAPPER_@infixSalt@_START_HOOK"
2020fi
2121
2222source @out@/nix-support/utils.sh
@@ -36,7 +36,7 @@ declare -i n=0
3636nParams=${#params[@]}
3737while [ "$n" -lt "$nParams" ]; do
3838 p=${params[n]}
39− p2=${params[n+1]}
39+ p2=${params[n+1]:-} # handle `p` being last one
4040 if [ "$p" = -c ]; then
4141 dontLink=1
4242 elif [ "$p" = -S ]; then
@@ -63,7 +63,7 @@ while [ "$n" -lt "$nParams" ]; do
6363 nonFlagArgs=1
6464 elif [ "$p" = -m32 ]; then
6565 if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
66− NIX_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)"
66+ NIX_@infixSalt@_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)"
6767 fi
6868 fi
6969 n+=1
@@ -79,13 +79,13 @@ if [ "$nonFlagArgs" = 0 ]; then
7979fi
8080
8181# Optionally filter out paths not refering to the store.
82−if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE" ]]; then
82+if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then
8383 rest=()
8484 nParams=${#params[@]}
8585 declare -i n=0
8686 while [ "$n" -lt "$nParams" ]; do
8787 p=${params[n]}
88− p2=${params[n+1]}
88+ p2=${params[n+1]:-} # handle `p` being last one
8989 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
9090 skip "${p:2}"
9191 elif [ "$p" = -L ] && badPath "$p2"; then
@@ -106,7 +106,7 @@ fi
106106
107107
108108# Clear march/mtune=native -- they bring impurity.
109−if [ "$NIX_ENFORCE_NO_NATIVE" = 1 ]; then
109+if [ "$NIX_@infixSalt@_ENFORCE_NO_NATIVE" = 1 ]; then
110110 rest=()
111111 for p in "${params[@]}"; do
112112 if [[ "$p" = -m*=native ]]; then
@@ -120,36 +120,36 @@ fi
120120
121121if [[ "$isCpp" = 1 ]]; then
122122 if [[ "$cppInclude" = 1 ]]; then
123− NIX_CFLAGS_COMPILE+=" ${NIX_CXXSTDLIB_COMPILE-@default_cxx_stdlib_compile@}"
123+ NIX_@infixSalt@_CFLAGS_COMPILE+=" ${NIX_@infixSalt@_CXXSTDLIB_COMPILE-@default_cxx_stdlib_compile@}"
124124 fi
125− NIX_CFLAGS_LINK+=" $NIX_CXXSTDLIB_LINK"
125+ NIX_@infixSalt@_CFLAGS_LINK+=" $NIX_@infixSalt@_CXXSTDLIB_LINK"
126126fi
127127
128128source @out@/nix-support/add-hardening.sh
129129
130130# Add the flags for the C compiler proper.
131−extraAfter=($NIX_CFLAGS_COMPILE "${hardeningCFlags[@]}")
131+extraAfter=($NIX_@infixSalt@_CFLAGS_COMPILE "${hardeningCFlags[@]}")
132132extraBefore=()
133133
134134if [ "$dontLink" != 1 ]; then
135135
136136 # Add the flags that should only be passed to the compiler when
137137 # linking.
138− extraAfter+=($NIX_CFLAGS_LINK "${hardeningLDFlags[@]}")
138+ extraAfter+=($NIX_@infixSalt@_CFLAGS_LINK "${hardeningLDFlags[@]}")
139139
140140 # Add the flags that should be passed to the linker (and prevent
141− # `ld-wrapper' from adding NIX_LDFLAGS again).
142− for i in $NIX_LDFLAGS_BEFORE; do
141+ # `ld-wrapper' from adding NIX_@infixSalt@_LDFLAGS again).
142+ for i in $NIX_@infixSalt@_LDFLAGS_BEFORE; do
143143 extraBefore+=("-Wl,$i")
144144 done
145− for i in $NIX_LDFLAGS; do
145+ for i in $NIX_@infixSalt@_LDFLAGS; do
146146 if [ "${i:0:3}" = -L/ ]; then
147147 extraAfter+=("$i")
148148 else
149149 extraAfter+=("-Wl,$i")
150150 fi
151151 done
152− export NIX_LDFLAGS_SET=1
152+ export NIX_@infixSalt@_LDFLAGS_SET=1
153153fi
154154
155155# As a very special hack, if the arguments are just `-v', then don't
@@ -162,18 +162,21 @@ if [ "$*" = -v ]; then
162162fi
163163
164164# Optionally print debug info.
165−if [ -n "$NIX_DEBUG" ]; then
165+if [ -n "${NIX_DEBUG:-}" ]; then
166+ set +u # Old bash workaround, see ld-wrapper for explanation.
166167 echo "extra flags before to @prog@:" >&2
167168 printf " %q\n" "${extraBefore[@]}" >&2
168169 echo "original flags to @prog@:" >&2
169170 printf " %q\n" "${params[@]}" >&2
170171 echo "extra flags after to @prog@:" >&2
171172 printf " %q\n" "${extraAfter[@]}" >&2
173+ set -u
172174fi
173175
174−if [ -n "$NIX_CC_WRAPPER_EXEC_HOOK" ]; then
175− source "$NIX_CC_WRAPPER_EXEC_HOOK"
176+if [ -n "$NIX_CC_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then
177+ source "$NIX_CC_WRAPPER_@infixSalt@_EXEC_HOOK"
176178fi
177179
178180PATH="$path_backup"
181+set +u # Old bash workaround, see above.
179182exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
pkgs/build-support/cc-wrapper/default.nix+31−60
@@ -53,42 +53,13 @@ let
5353 "-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/$(${cc.gcc}/bin/gcc -dumpmachine)";
5454
5555 dashlessTarget = stdenv.lib.replaceStrings ["-"] ["_"] targetPlatform.config;
56− # TODO(@Ericson2314) Make unconditional
57− infixSalt = stdenv.lib.optionalString (targetPlatform != hostPlatform) dashlessTarget;
58− infixSalt_ = stdenv.lib.optionalString (targetPlatform != hostPlatform) (dashlessTarget + "_");
59− _infixSalt = stdenv.lib.optionalString (targetPlatform != hostPlatform) ("_" + dashlessTarget);
60−
61− # We want to prefix all NIX_ flags with the target triple
62− preWrap = textFile:
63− # TODO: Do even when not cross on next mass-rebuild
64− # TODO: use @target_tripple@ for consistency
65− if targetPlatform == hostPlatform
66− then textFile
67− else runCommand "sed-nix-env-vars" {} (''
68− cp --no-preserve=mode ${textFile} $out
69−
70− sed -i $out \
71− -e 's^NIX_^NIX_${infixSalt_}^g' \
72− -e 's^addCVars^addCVars${_infixSalt}^g' \
73− -e 's^\[ -z "\$crossConfig" \]^\[\[ "${builtins.toString (targetPlatform != hostPlatform)}" || -z "$crossConfig" \]\]^g'
74−
75− # NIX_ things which we don't both use and define, we revert them
76− #asymmetric=$(
77− # for pre in "" "\\$"
78− # do
79− # grep -E -ho $pre'NIX_[a-zA-Z_]*' ./* | sed 's/\$//' | sort | uniq
80− # done | sort | uniq -c | sort -nr | sed -n 's/^1 NIX_//gp')
81−
82− # hard-code for now
83− asymmetric=("CXXSTDLIB_COMPILE" "CC")
84−
85− # The ([^a-zA-Z_]|$) bussiness is to ensure environment variables that
86− # begin with `NIX_CC` don't also get blacklisted.
87− for var in "''${asymmetric[@]}"
88− do
89− sed -i $out -E -e "s~NIX_${infixSalt_}$var([^a-zA-Z_]|$)~NIX_$var\1~g"
90− done
91− '');
56+
57+ # The "infix salt" is a arbitrary string added in the middle of env vars
58+ # defined by cc-wrapper's hooks so that multiple cc-wrappers can be used
59+ # without interfering. For the moment, it is defined as the target triple,
60+ # adjusted to be a valid bash identifier. This should be considered an
61+ # unstable implementation detail, however.
62+ infixSalt = dashlessTarget;
9263
9364 # The dynamic linker has different names on different platforms. This is a
9465 # shell glob that ought to match it.
@@ -129,20 +100,21 @@ stdenv.mkDerivation {
129100 gnugrep_bin = if nativeTools then "" else gnugrep;
130101
131102 binPrefix = prefix;
103+ inherit infixSalt;
132104
133105 passthru = {
134106 inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile
135− prefix infixSalt infixSalt_ _infixSalt;
107+ prefix;
136108
137109 emacsBufferSetup = pkgs: ''
138110 ; We should handle propagation here too
139111 (mapc (lambda (arg)
140112 (when (file-directory-p (concat arg "/include"))
141− (setenv "NIX_${infixSalt_}CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt_}CFLAGS_COMPILE") " -isystem " arg "/include")))
113+ (setenv "NIX_${infixSalt}_CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt}_CFLAGS_COMPILE") " -isystem " arg "/include")))
142114 (when (file-directory-p (concat arg "/lib"))
143− (setenv "NIX_${infixSalt_}LDFLAGS" (concat (getenv "NIX_${infixSalt_}LDFLAGS") " -L" arg "/lib")))
115+ (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib")))
144116 (when (file-directory-p (concat arg "/lib64"))
145− (setenv "NIX_${infixSalt_}LDFLAGS" (concat (getenv "NIX_${infixSalt_}LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
117+ (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
146118 '';
147119 };
148120
@@ -268,7 +240,7 @@ stdenv.mkDerivation {
268240 # Solaris needs an additional ld wrapper.
269241 ldPath="${nativePrefix}/bin"
270242 exec="$ldPath/${prefix}ld"
271− wrap ld-solaris ${preWrap ./ld-solaris-wrapper.sh}
243+ wrap ld-solaris ${./ld-solaris-wrapper.sh}
272244 '')
273245
274246 + ''
@@ -282,7 +254,6 @@ stdenv.mkDerivation {
282254 '' + (if !useMacosReexportHack then ''
283255 wrap ${prefix}ld ${./ld-wrapper.sh} ''${ld:-$ldPath/${prefix}ld}
284256 '' else ''
285− export binPrefix=${prefix}
286257 ldInner="${prefix}ld-reexport-delegate"
287258 wrap "$ldInner" ${./macos-sierra-reexport-hack.bash} ''${ld:-$ldPath/${prefix}ld}
288259 wrap "${prefix}ld" ${./ld-wrapper.sh} "$out/bin/$ldInner"
@@ -290,11 +261,11 @@ stdenv.mkDerivation {
290261 '') + ''
291262
292263 if [ -e ${binutils_bin}/bin/${prefix}ld.gold ]; then
293− wrap ${prefix}ld.gold ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold
264+ wrap ${prefix}ld.gold ${./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold
294265 fi
295266
296267 if [ -e ${binutils_bin}/bin/ld.bfd ]; then
297− wrap ${prefix}ld.bfd ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd
268+ wrap ${prefix}ld.bfd ${./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd
298269 fi
299270
300271 # We export environment variables pointing to the wrapped nonstandard
@@ -306,49 +277,49 @@ stdenv.mkDerivation {
306277 export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}"
307278
308279 if [ -e $ccPath/${prefix}gcc ]; then
309− wrap ${prefix}gcc ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcc
280+ wrap ${prefix}gcc ${./cc-wrapper.sh} $ccPath/${prefix}gcc
310281 ln -s ${prefix}gcc $out/bin/${prefix}cc
311282 export named_cc=${prefix}gcc
312283 export named_cxx=${prefix}g++
313284 elif [ -e $ccPath/clang ]; then
314− wrap ${prefix}clang ${preWrap ./cc-wrapper.sh} $ccPath/clang
285+ wrap ${prefix}clang ${./cc-wrapper.sh} $ccPath/clang
315286 ln -s ${prefix}clang $out/bin/${prefix}cc
316287 export named_cc=${prefix}clang
317288 export named_cxx=${prefix}clang++
318289 fi
319290
320291 if [ -e $ccPath/${prefix}g++ ]; then
321− wrap ${prefix}g++ ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}g++
292+ wrap ${prefix}g++ ${./cc-wrapper.sh} $ccPath/${prefix}g++
322293 ln -s ${prefix}g++ $out/bin/${prefix}c++
323294 elif [ -e $ccPath/clang++ ]; then
324− wrap ${prefix}clang++ ${preWrap ./cc-wrapper.sh} $ccPath/clang++
295+ wrap ${prefix}clang++ ${./cc-wrapper.sh} $ccPath/clang++
325296 ln -s ${prefix}clang++ $out/bin/${prefix}c++
326297 fi
327298
328299 if [ -e $ccPath/cpp ]; then
329− wrap ${prefix}cpp ${preWrap ./cc-wrapper.sh} $ccPath/cpp
300+ wrap ${prefix}cpp ${./cc-wrapper.sh} $ccPath/cpp
330301 fi
331302 ''
332303
333304 + optionalString cc.langFortran or false ''
334− wrap ${prefix}gfortran ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gfortran
305+ wrap ${prefix}gfortran ${./cc-wrapper.sh} $ccPath/${prefix}gfortran
335306 ln -sv ${prefix}gfortran $out/bin/${prefix}g77
336307 ln -sv ${prefix}gfortran $out/bin/${prefix}f77
337308 ''
338309
339310 + optionalString cc.langJava or false ''
340− wrap ${prefix}gcj ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcj
311+ wrap ${prefix}gcj ${./cc-wrapper.sh} $ccPath/${prefix}gcj
341312 ''
342313
343314 + optionalString cc.langGo or false ''
344− wrap ${prefix}gccgo ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gccgo
315+ wrap ${prefix}gccgo ${./cc-wrapper.sh} $ccPath/${prefix}gccgo
345316 ''
346317
347318 + optionalString cc.langAda or false ''
348− wrap ${prefix}gnatgcc ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gnatgcc
349− wrap ${prefix}gnatmake ${preWrap ./gnat-wrapper.sh} $ccPath/${prefix}gnatmake
350− wrap ${prefix}gnatbind ${preWrap ./gnat-wrapper.sh} $ccPath/${prefix}gnatbind
351− wrap ${prefix}gnatlink ${preWrap ./gnatlink-wrapper.sh} $ccPath/${prefix}gnatlink
319+ wrap ${prefix}gnatgcc ${./cc-wrapper.sh} $ccPath/${prefix}gnatgcc
320+ wrap ${prefix}gnatmake ${./gnat-wrapper.sh} $ccPath/${prefix}gnatmake
321+ wrap ${prefix}gnatbind ${./gnat-wrapper.sh} $ccPath/${prefix}gnatbind
322+ wrap ${prefix}gnatlink ${./gnatlink-wrapper.sh} $ccPath/${prefix}gnatlink
352323 ''
353324
354325 + optionalString cc.langVhdl or false ''
@@ -356,7 +327,7 @@ stdenv.mkDerivation {
356327 ''
357328
358329 + ''
359− substituteAll ${preWrap ./setup-hook.sh} $out/nix-support/setup-hook.tmp
330+ substituteAll ${./setup-hook.sh} $out/nix-support/setup-hook.tmp
360331 cat $out/nix-support/setup-hook.tmp >> $out/nix-support/setup-hook
361332 rm $out/nix-support/setup-hook.tmp
362333
@@ -375,9 +346,9 @@ stdenv.mkDerivation {
375346 ''
376347
377348 + ''
378− substituteAll ${preWrap ./add-flags.sh} $out/nix-support/add-flags.sh
379− substituteAll ${preWrap ./add-hardening.sh} $out/nix-support/add-hardening.sh
380− substituteAll ${preWrap ./utils.sh} $out/nix-support/utils.sh
349+ substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
350+ substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
351+ substituteAll ${./utils.sh} $out/nix-support/utils.sh
381352 ''
382353 + extraBuildCommands;
383354
pkgs/build-support/cc-wrapper/gnat-wrapper.sh+19−16
@@ -1,7 +1,10 @@
11#! @shell@
2−set -e -o pipefail
2+set -eu -o pipefail
33shopt -s nullglob
44
5+# N.B. Gnat is not used during bootstrapping, so we don't need to
6+# worry about the old bash empty array `set -u` workarounds.
7+
58path_backup="$PATH"
69
710# phase separation makes this look useless
@@ -10,12 +13,12 @@ if [ -n "@coreutils_bin@" ]; then
1013 PATH="@coreutils_bin@/bin"
1114fi
1215
13−if [ -n "$NIX_GNAT_WRAPPER_START_HOOK" ]; then
14− source "$NIX_GNAT_WRAPPER_START_HOOK"
16+if [ -z "${NIX_@infixSalt@_GNAT_WRAPPER_FLAGS_SET:-}" ]; then
17+ source @out@/nix-support/add-flags.sh
1518fi
1619
17−if [ -z "$NIX_GNAT_WRAPPER_FLAGS_SET" ]; then
18− source @out@/nix-support/add-flags.sh
20+if [ -n "$NIX_@infixSalt@_GNAT_WRAPPER_START_HOOK" ]; then
21+ source "$NIX_@infixSalt@_GNAT_WRAPPER_START_HOOK"
1922fi
2023
2124source @out@/nix-support/utils.sh
@@ -35,7 +38,7 @@ for i in "$@"; do
3538 nonFlagArgs=1
3639 elif [ "$i" = -m32 ]; then
3740 if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
38− NIX_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)"
41+ NIX_@infixSalt@_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)"
3942 fi
4043 fi
4144done
@@ -52,7 +55,7 @@ fi
5255
5356# Optionally filter out paths not refering to the store.
5457params=("$@")
55−if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE" ]]; then
58+if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then
5659 rest=()
5760 for p in "${params[@]}"; do
5861 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
@@ -72,7 +75,7 @@ fi
7275
7376
7477# Clear march/mtune=native -- they bring impurity.
75−if [ "$NIX_ENFORCE_NO_NATIVE" = 1 ]; then
78+if [ "$NIX_@infixSalt@_ENFORCE_NO_NATIVE" = 1 ]; then
7679 rest=()
7780 for p in "${params[@]}"; do
7881 if [[ "$p" = -m*=native ]]; then
@@ -86,7 +89,7 @@ fi
8689
8790
8891# Add the flags for the GNAT compiler proper.
89−extraAfter=($NIX_GNATFLAGS_COMPILE)
92+extraAfter=($NIX_@infixSalt@_GNATFLAGS_COMPILE)
9093extraBefore=()
9194
9295if [ "$(basename "$0")x" = "gnatmakex" ]; then
@@ -95,22 +98,22 @@ fi
9598
9699#if [ "$dontLink" != 1 ]; then
97100# # Add the flags that should be passed to the linker (and prevent
98−# # `ld-wrapper' from adding NIX_LDFLAGS again).
99−# for i in $NIX_LDFLAGS_BEFORE; do
101+# # `ld-wrapper' from adding NIX_@infixSalt@_LDFLAGS again).
102+# for i in $NIX_@infixSalt@_LDFLAGS_BEFORE; do
100103# extraBefore+=("-largs" "$i")
101104# done
102−# for i in $NIX_LDFLAGS; do
105+# for i in $NIX_@infixSalt@_LDFLAGS; do
103106# if [ "${i:0:3}" = -L/ ]; then
104107# extraAfter+=("$i")
105108# else
106109# extraAfter+=("-largs" "$i")
107110# fi
108111# done
109−# export NIX_LDFLAGS_SET=1
112+# export NIX_@infixSalt@_LDFLAGS_SET=1
110113#fi
111114
112115# Optionally print debug info.
113−if [ -n "$NIX_DEBUG" ]; then
116+if [ -n "${NIX_DEBUG:-}" ]; then
114117 echo "extra flags before to @prog@:" >&2
115118 printf " %q\n" "${extraBefore[@]}" >&2
116119 echo "original flags to @prog@:" >&2
@@ -119,8 +122,8 @@ if [ -n "$NIX_DEBUG" ]; then
119122 printf " %q\n" "${extraAfter[@]}" >&2
120123fi
121124
122−if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
123− source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
125+if [ -n "$NIX_@infixSalt@_GNAT_WRAPPER_EXEC_HOOK" ]; then
126+ source "$NIX_@infixSalt@_GNAT_WRAPPER_EXEC_HOOK"
124127fi
125128
126129PATH="$path_backup"
pkgs/build-support/cc-wrapper/gnatlink-wrapper.sh+11−8
@@ -1,27 +1,30 @@
11#! @shell@
2−set -e -o pipefail
2+set -eu -o pipefail
33shopt -s nullglob
44
5+# N.B. Gnat is not used during bootstrapping, so we don't need to
6+# worry about the old bash empty array `set -u` workarounds.
7+
58# Add the flags for the GNAT compiler proper.
69extraAfter=("--GCC=@out@/bin/gcc")
710extraBefore=()
811
912## Add the flags that should be passed to the linker (and prevent
10−## `ld-wrapper' from adding NIX_LDFLAGS again).
11−#for i in $NIX_LDFLAGS_BEFORE; do
13+## `ld-wrapper' from adding NIX_@infixSalt@_LDFLAGS again).
14+#for i in $NIX_@infixSalt@_LDFLAGS_BEFORE; do
1215# extraBefore+=("-largs" "$i")
1316#done
14−#for i in $NIX_LDFLAGS; do
17+#for i in $NIX_@infixSalt@_LDFLAGS; do
1518# if [ "${i:0:3}" = -L/ ]; then
1619# extraAfter+=("$i")
1720# else
1821# extraAfter+=("-largs" "$i")
1922# fi
2023#done
21−#export NIX_LDFLAGS_SET=1
24+#export NIX_@infixSalt@_LDFLAGS_SET=1
2225
2326# Optionally print debug info.
24−if [ -n "$NIX_DEBUG" ]; then
27+if [ -n "${NIX_DEBUG:-}" ]; then
2528 echo "extra flags before to @prog@:" >&2
2629 printf " %q\n" "${extraBefore[@]}" >&2
2730 echo "original flags to @prog@:" >&2
@@ -30,8 +33,8 @@ if [ -n "$NIX_DEBUG" ]; then
3033 printf " %q\n" "${extraAfter[@]}" >&2
3134fi
3235
33−if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
34− source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
36+if [ -n "$NIX_@infixSalt@_GNAT_WRAPPER_EXEC_HOOK" ]; then
37+ source "$NIX_@infixSalt@_GNAT_WRAPPER_EXEC_HOOK"
3538fi
3639
3740exec @prog@ "${extraBefore[@]}" "$@" "${extraAfter[@]}"
pkgs/build-support/cc-wrapper/ld-wrapper.sh+37−27
@@ -1,5 +1,5 @@
11#! @shell@
2−set -e -o pipefail
2+set -eu -o pipefail
33shopt -s nullglob
44
55path_backup="$PATH"
@@ -10,12 +10,12 @@ if [ -n "@coreutils_bin@" ]; then
1010 PATH="@coreutils_bin@/bin"
1111fi
1212
13−if [ -n "$NIX_LD_WRAPPER_START_HOOK" ]; then
14− source "$NIX_LD_WRAPPER_START_HOOK"
13+if [ -z "${NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then
14+ source @out@/nix-support/add-flags.sh
1515fi
1616
17−if [ -z "$NIX_CC_WRAPPER_FLAGS_SET" ]; then
18− source @out@/nix-support/add-flags.sh
17+if [ -n "$NIX_LD_WRAPPER_@infixSalt@_START_HOOK" ]; then
18+ source "$NIX_LD_WRAPPER_@infixSalt@_START_HOOK"
1919fi
2020
2121source @out@/nix-support/utils.sh
@@ -23,14 +23,14 @@ source @out@/nix-support/utils.sh
2323
2424# Optionally filter out paths not refering to the store.
2525expandResponseParams "$@"
26−if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE"
27− && ( -z "$NIX_IGNORE_LD_THROUGH_GCC" || -z "$NIX_LDFLAGS_SET" ) ]]; then
26+if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "${NIX_STORE:-}"
27+ && ( -z "$NIX_@infixSalt@_IGNORE_LD_THROUGH_GCC" || -z "${NIX_@infixSalt@_LDFLAGS_SET:-}" ) ]]; then
2828 rest=()
2929 nParams=${#params[@]}
3030 declare -i n=0
3131 while [ "$n" -lt "$nParams" ]; do
3232 p=${params[n]}
33− p2=${params[n+1]}
33+ p2=${params[n+1]:-} # handle `p` being last one
3434 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
3535 skip "${p:2}"
3636 elif [ "$p" = -L ] && badPath "$p2"; then
@@ -59,21 +59,25 @@ source @out@/nix-support/add-hardening.sh
5959extraAfter=("${hardeningLDFlags[@]}")
6060extraBefore=()
6161
62−if [ -z "$NIX_LDFLAGS_SET" ]; then
63− extraAfter+=($NIX_LDFLAGS)
64− extraBefore+=($NIX_LDFLAGS_BEFORE)
62+if [ -z "${NIX_@infixSalt@_LDFLAGS_SET:-}" ]; then
63+ extraAfter+=($NIX_@infixSalt@_LDFLAGS)
64+ extraBefore+=($NIX_@infixSalt@_LDFLAGS_BEFORE)
6565fi
6666
67−extraAfter+=($NIX_LDFLAGS_AFTER $NIX_LDFLAGS_HARDEN)
67+extraAfter+=($NIX_@infixSalt@_LDFLAGS_AFTER $NIX_@infixSalt@_LDFLAGS_HARDEN)
6868
6969declare -a libDirs
7070declare -A libs
7171relocatable=
7272
7373# Find all -L... switches for rpath, and relocatable flags for build id.
74−if [ "$NIX_DONT_SET_RPATH" != 1 ] || [ "$NIX_SET_BUILD_ID" = 1 ]; then
74+if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ] || [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ]; then
7575 prev=
76+ # Old bash thinks empty arrays are undefined, ugh, so temporarily disable
77+ # `set -u`.
78+ set +u
7679 for p in "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"; do
80+ set -u
7781 case "$prev" in
7882 -L)
7983 libDirs+=("$p")
@@ -92,7 +96,7 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ] || [ "$NIX_SET_BUILD_ID" = 1 ]; then
9296 -l?*)
9397 libs["lib${p:2}.so"]=1
9498 ;;
95− "$NIX_STORE"/*.so | "$NIX_STORE"/*.so.*)
99+ "${NIX_STORE:-}"/*.so | "${NIX_STORE:-}"/*.so.*)
96100 # This is a direct reference to a shared library.
97101 libDirs+=("${p%/*}")
98102 libs["${p##*/}"]=1
@@ -108,7 +112,7 @@ fi
108112
109113
110114# Add all used dynamic libraries to the rpath.
111−if [ "$NIX_DONT_SET_RPATH" != 1 ]; then
115+if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ]; then
112116 # For each directory in the library search path (-L...),
113117 # see if it contains a dynamic library used by a -l... flag. If
114118 # so, add the directory to the rpath.
@@ -119,20 +123,23 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then
119123 if [[ "$dir" =~ [/.][/.] ]] && dir2=$(readlink -f "$dir"); then
120124 dir="$dir2"
121125 fi
122− if [ "${rpaths[$dir]}" ] || [[ "$dir" != "$NIX_STORE"/* ]]; then
126+ if [ -n "${rpaths[$dir]:-}" ] || [[ "$dir" != "${NIX_STORE:-}"/* ]]; then
123127 # If the path is not in the store, don't add it to the rpath.
124128 # This typically happens for libraries in /tmp that are later
125129 # copied to $out/lib. If not, we're screwed.
126130 continue
127131 fi
128− for path in "$dir"/lib*.so; do
132+ for path in "$dir"/*; do
129133 file="${path##*/}"
130− if [ "${libs[$file]}" ]; then
131− libs["$file"]=
132− if [ ! "${rpaths[$dir]}" ]; then
133− rpaths["$dir"]=1
134− extraAfter+=(-rpath "$dir")
135− fi
134+ if [ "${libs[$file]:-}" ]; then
135+ # This library may have been provided by a previous directory,
136+ # but if that library file is inside an output of the current
137+ # derivation, it can be deleted after this compilation and
138+ # should be found in a later directory, so we add all
139+ # directories that contain any of the libraries to rpath.
140+ rpaths["$dir"]=1
141+ extraAfter+=(-rpath "$dir")
142+ break
136143 fi
137144 done
138145 done
@@ -141,24 +148,27 @@ fi
141148
142149# Only add --build-id if this is a final link. FIXME: should build gcc
143150# with --enable-linker-build-id instead?
144−if [ "$NIX_SET_BUILD_ID" = 1 ] && [ ! "$relocatable" ]; then
151+if [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ] && [ ! "$relocatable" ]; then
145152 extraAfter+=(--build-id)
146153fi
147154
148155
149156# Optionally print debug info.
150−if [ -n "$NIX_DEBUG" ]; then
157+if [ -n "${NIX_DEBUG:-}" ]; then
158+ set +u # Old bash workaround, see above.
151159 echo "extra flags before to @prog@:" >&2
152160 printf " %q\n" "${extraBefore[@]}" >&2
153161 echo "original flags to @prog@:" >&2
154162 printf " %q\n" "${params[@]}" >&2
155163 echo "extra flags after to @prog@:" >&2
156164 printf " %q\n" "${extraAfter[@]}" >&2
165+ set -u
157166fi
158167
159−if [ -n "$NIX_LD_WRAPPER_EXEC_HOOK" ]; then
160− source "$NIX_LD_WRAPPER_EXEC_HOOK"
168+if [ -n "$NIX_LD_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then
169+ source "$NIX_LD_WRAPPER_@infixSalt@_EXEC_HOOK"
161170fi
162171
163172PATH="$path_backup"
173+set +u # Old bash workaround, see above.
164174exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
pkgs/build-support/cc-wrapper/setup-hook.sh+103−17
@@ -1,22 +1,112 @@
1−addCVars () {
1+# CC Wrapper hygiene
2+#
3+# For at least cross compilation, we need to depend on multiple cc-wrappers at
4+# once---specifically up to one per sort of dependency. This follows from having
5+# different tools targeting different platforms, and different flags for those
6+# tools. For example:
7+#
8+# # Flags for compiling (whether or not linking) C code for the...
9+# NIX_BUILD_CFLAGS_COMPILE # ...build platform
10+# NIX_CFLAGS_COMPILE # ...host platform
11+# NIX_TARGET_CFLAGS_COMPILE # ...target platform
12+#
13+# Notice that these platforms are the 3 *relative* to the package using
14+# cc-wrapper, not absolute like `x86_64-pc-linux-gnu`.
15+#
16+# The simplest solution would be to have separate cc-wrappers per (3 intended
17+# use-cases * n absolute concrete platforms). For the use-case axis, we would
18+# @-splice in 'BUILD_' '' 'TARGET_' to use the write environment variables when
19+# building the cc-wrapper, and likewise prefix the binaries' names so they didn't
20+# clobber each other on the PATH. But the need for 3x cc-wrappers, along with
21+# non-standard name prefixes, is annoying and liable to break packages' build
22+# systems.
23+#
24+# Instead, we opt to have just one cc-wrapper per absolute platform. Matching
25+# convention, the binaries' names can just be prefixed with their target
26+# platform. On the other hand, that means packages will depend on not just
27+# multiple cc-wrappers, but the exact same cc-wrapper derivation multiple ways.
28+# That means the exact same cc-wrapper derivation must be able to avoid
29+# conflicting with itself, despite the fact that `setup-hook.sh`, the `addCvars`
30+# function, and `add-flags.sh` are all communicating with each other with
31+# environment variables. Yuck.
32+#
33+# The basic strategy is:
34+#
35+# - Everyone exclusively *adds information* to relative-platform-specific
36+# environment variables, like `NIX_TARGET_CFLAGS_COMPILE`, to communicate
37+# with the wrapped binaries.
38+#
39+# - The wrapped binaries will exclusively *read* cc-wrapper-derivation-specific
40+# environment variables distinguished with with `infixSalt`, like
41+# `NIX_@infixSalt@_CFLAGS_COMPILE`.
42+#
43+# - `add-flags`, beyond its old task of reading extra flags stuck inside the
44+# cc-wrapper derivation, will convert the relative-platform-specific
45+# variables to cc-wrapper-derivation-specific variables. This conversion is
46+# the only time all but one of the cc-wrapper-derivation-specific variables
47+# are set.
48+#
49+# This ensures the flow of information is exclusive from
50+# relative-platform-specific variables to cc-wrapper-derivation-specific
51+# variables. This allows us to support the general case of a many--many relation
52+# between relative platforms and cc-wrapper derivations.
53+#
54+# For more details, read the individual files where the mechanisms used to
55+# accomplish this will be individually documented.
56+
57+
58+# It's fine that any other cc-wrapper will redefine this. Bash functions close
59+# over no state, and there's no @-substitutions within, so any redefined
60+# function is guaranteed to be exactly the same.
61+ccWrapper_addCVars () {
62+ # The `depOffset` describes how the platforms of the dependencies are slid
63+ # relative to the depending package. It is brought into scope of the
64+ # environment hook defined as the role of the dependency being applied.
65+ case $depOffset in
66+ -1) local role='BUILD_' ;;
67+ 0) local role='' ;;
68+ 1) local role='TARGET_' ;;
69+ *) echo "cc-wrapper: Error: Cannot be used with $depOffset-offset deps, " >2;
70+ return 1 ;;
71+ esac
72+
273 if [[ -d "$1/include" ]]; then
3− export NIX_CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include"
74+ export NIX_${role}CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include"
475 fi
576
677 if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then
7− export NIX_LDFLAGS+=" -L$1/lib64"
78+ export NIX_${role}LDFLAGS+=" -L$1/lib64"
879 fi
980
1081 if [[ -d "$1/lib" ]]; then
11− export NIX_LDFLAGS+=" -L$1/lib"
82+ export NIX_${role}LDFLAGS+=" -L$1/lib"
1283 fi
1384
1485 if [[ -d "$1/Library/Frameworks" ]]; then
15− export NIX_CFLAGS_COMPILE+=" -F$1/Library/Frameworks"
86+ export NIX_${role}CFLAGS_COMPILE+=" -F$1/Library/Frameworks"
1687 fi
1788}
1889
19−envHooks+=(addCVars)
90+# Since the same cc-wrapper derivation can be depend on in multiple ways, we
91+# need to accumulate *each* role (i.e. target platform relative the depending
92+# derivation) in which the cc-wrapper derivation is used.
93+# `NIX_CC_WRAPPER_@infixSalt@_TARGET_*` tracks this (needs to be an exported env
94+# var so can't use fancier data structures).
95+#
96+# We also need to worry about what role is being added on *this* invocation of
97+# setup-hook, which `role` tracks.
98+if [ -n "${crossConfig:-}" ]; then
99+ export NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD=1
100+ role="BUILD_"
101+else
102+ export NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST=1
103+ role=""
104+fi
105+
106+# Eventually the exact sort of env-hook we create will depend on the role. This
107+# is because based on what relative platform we are targeting, we use different
108+# dependencies.
109+envHooks+=(ccWrapper_addCVars)
20110
21111# Note 1: these come *after* $out in the PATH (see setup.sh).
22112# Note 2: phase separation makes this look useless to shellcheck.
@@ -41,16 +131,12 @@ if [ -n "@coreutils_bin@" ]; then
41131 addToSearchPath _PATH @coreutils_bin@/bin
42132fi
43133
44−if [ -z "${crossConfig:-}" ]; then
45− ENV_PREFIX=""
46−else
47− ENV_PREFIX="BUILD_"
48−fi
134+# Export tool environment variables so various build systems use the right ones.
49135
50−export NIX_${ENV_PREFIX}CC=@out@
136+export NIX_${role}CC=@out@
51137
52−export ${ENV_PREFIX}CC=@named_cc@
53−export ${ENV_PREFIX}CXX=@named_cxx@
138+export ${role}CC=@named_cc@
139+export ${role}CXX=@named_cxx@
54140
55141for CMD in \
56142 cpp \
@@ -59,9 +145,9 @@ do
59145 if
60146 PATH=$_PATH type -p "@binPrefix@$CMD" > /dev/null
61147 then
62− export "${ENV_PREFIX}$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=@binPrefix@${CMD}";
148+ export "${role}$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=@binPrefix@${CMD}";
63149 fi
64150done
65151
66−# No local scope available for sourced files
67−unset ENV_PREFIX
152+# No local scope in sourced file
153+unset role
pkgs/build-support/cc-wrapper/utils.sh+1−1
@@ -1,5 +1,5 @@
11skip () {
2− if [ -n "$NIX_DEBUG" ]; then
2+ if [ -n "${NIX_DEBUG:-}" ]; then
33 echo "skipping impure path $1" >&2
44 fi
55}
pkgs/build-support/setup-hooks/die.shnew file+21
@@ -0,0 +1,21 @@
1+# Exit with backtrace and error message
2+#
3+# Usage: die "Error message"
4+die() {
5+ # Let us be a little sloppy with errors, because otherwise the final
6+ # invocation of `caller` below will cause the script to exit.
7+ set +e
8+
9+ # Print our error message
10+ printf "\nBuilder called die: %b\n" "$*"
11+ printf "Backtrace:\n"
12+
13+ # Print a backtrace.
14+ local frame=0
15+ while caller $frame; do
16+ ((frame++));
17+ done
18+ printf "\n"
19+
20+ exit 1
21+}
pkgs/build-support/setup-hooks/make-wrapper.sh+25−23
@@ -1,3 +1,12 @@
1+# Assert that FILE exists and is executable
2+#
3+# assertExecutable FILE
4+assertExecutable() {
5+ local file="$1"
6+ [[ -f "${file}" && -x "${file}" ]] || \
7+ die "Cannot wrap ${file} because it is not an executable file"
8+}
9+
110# construct an executable file that wraps the actual executable
211# makeWrapper EXECUTABLE ARGS
312
@@ -24,6 +33,8 @@ makeWrapper() {
2433 local params varName value command separator n fileNames
2534 local argv0 flagsBefore flags
2635
36+ assertExecutable "${original}"
37+
2738 mkdir -p "$(dirname "$wrapper")"
2839
2940 echo "#! $SHELL -e" > "$wrapper"
@@ -32,26 +43,20 @@ makeWrapper() {
3243 for ((n = 2; n < ${#params[*]}; n += 1)); do
3344 p="${params[$n]}"
3445
35− if test "$p" = "--set"; then
46+ if [[ "$p" == "--set" ]]; then
3647 varName="${params[$((n + 1))]}"
3748 value="${params[$((n + 2))]}"
3849 n=$((n + 2))
3950 echo "export $varName=\"$value\"" >> "$wrapper"
40− fi
41−
42− if test "$p" = "--unset"; then
51+ elif [[ "$p" == "--unset" ]]; then
4352 varName="${params[$((n + 1))]}"
4453 n=$((n + 1))
4554 echo "unset $varName" >> "$wrapper"
46− fi
47−
48− if test "$p" = "--run"; then
55+ elif [[ "$p" == "--run" ]]; then
4956 command="${params[$((n + 1))]}"
5057 n=$((n + 1))
5158 echo "$command" >> "$wrapper"
52− fi
53−
54− if test "$p" = "--suffix" -o "$p" = "--prefix"; then
59+ elif [[ ("$p" == "--suffix") || ("$p" == "--prefix") ]]; then
5560 varName="${params[$((n + 1))]}"
5661 separator="${params[$((n + 2))]}"
5762 value="${params[$((n + 3))]}"
@@ -63,9 +68,7 @@ makeWrapper() {
6368 echo "export $varName=$value\${$varName:+$separator}\$$varName" >> "$wrapper"
6469 fi
6570 fi
66− fi
67−
68− if test "$p" = "--suffix-each"; then
71+ elif [[ "$p" == "--suffix-each" ]]; then
6972 varName="${params[$((n + 1))]}"
7073 separator="${params[$((n + 2))]}"
7174 values="${params[$((n + 3))]}"
@@ -73,9 +76,7 @@ makeWrapper() {
7376 for value in $values; do
7477 echo "export $varName=\$$varName\${$varName:+$separator}$value" >> "$wrapper"
7578 done
76− fi
77−
78− if test "$p" = "--suffix-contents" -o "$p" = "--prefix-contents"; then
79+ elif [[ ("$p" == "--suffix-contents") || ("$p" == "--prefix-contents") ]]; then
7980 varName="${params[$((n + 1))]}"
8081 separator="${params[$((n + 2))]}"
8182 fileNames="${params[$((n + 3))]}"
@@ -87,17 +88,15 @@ makeWrapper() {
8788 echo "export $varName=$(cat "$fileName")\${$varName:+$separator}\$$varName" >> "$wrapper"
8889 fi
8990 done
90− fi
91−
92− if test "$p" = "--add-flags"; then
91+ elif [[ "$p" == "--add-flags" ]]; then
9392 flags="${params[$((n + 1))]}"
9493 n=$((n + 1))
9594 flagsBefore="$flagsBefore $flags"
96− fi
97−
98− if test "$p" = "--argv0"; then
95+ elif [[ "$p" == "--argv0" ]]; then
9996 argv0="${params[$((n + 1))]}"
10097 n=$((n + 1))
98+ else
99+ die "makeWrapper doesn't understand the arg $p"
101100 fi
102101 done
103102
@@ -131,6 +130,9 @@ filterExisting() {
131130wrapProgram() {
132131 local prog="$1"
133132 local hidden
133+
134+ assertExecutable "${prog}"
135+
134136 hidden="$(dirname "$prog")/.$(basename "$prog")"-wrapped
135137 while [ -e "$hidden" ]; do
136138 hidden="${hidden}_"
@@ -138,5 +140,5 @@ wrapProgram() {
138140 mv "$prog" "$hidden"
139141 # Silence warning about unexpanded $0:
140142 # shellcheck disable=SC2016
141− makeWrapper "$hidden" "$prog" --argv0 '$0' "$@"
143+ makeWrapper "$hidden" "$prog" --argv0 '$0' "${@:2}"
142144}
pkgs/desktops/gnome-3/3.22/core/evolution-data-server/default.nix+1−1
@@ -19,7 +19,7 @@ stdenv.mkDerivation rec {
1919 enableParallelBuilding = true;
2020
2121 preFixup = ''
22− for f in "$out/libexec/"*; do
22+ for f in $(find $out/libexec/ -type f -executable); do
2323 wrapProgram "$f" \
2424 --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH" \
2525 --prefix GIO_EXTRA_MODULES : "${stdenv.lib.getLib dconf}/lib/gio/modules"
pkgs/development/interpreters/python/wrapper.nix+3−1
@@ -28,7 +28,9 @@ let
2828 for prg in *; do
2929 if [ -f "$prg" ]; then
3030 rm -f "$out/bin/$prg"
31− makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out" --set PYTHONNOUSERSITE "true"
31+ if [ -x "$prg" ]; then
32+ makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out" --set PYTHONNOUSERSITE "true"
33+ fi
3234 fi
3335 done
3436 fi
pkgs/development/libraries/serf/default.nix+15−10
@@ -1,4 +1,5 @@
1−{ stdenv, fetchurl, apr, scons, openssl, aprutil, zlib, kerberos, pkgconfig, gnused }:
1+{ stdenv, fetchurl, apr, scons, openssl, aprutil, zlib, kerberos
2+, pkgconfig, gnused, expat, openldap, libiconv }:
23
34stdenv.mkDerivation rec {
45 name = "serf-1.3.9";
@@ -8,18 +9,22 @@ stdenv.mkDerivation rec {
89 sha256 = "1k47gbgpp52049andr28y28nbwh9m36bbb0g8p0aka3pqlhjv72l";
910 };
1011
11− buildInputs = [ apr scons openssl aprutil zlib ]
12− ++ stdenv.lib.optional (!stdenv.isCygwin) kerberos
13− ++ [ pkgconfig ];
14−
15− configurePhase = ''
16− ${gnused}/bin/sed -e '/^env[.]Append(BUILDERS/ienv.Append(ENV={"PATH":os.environ["PATH"]})' -i SConstruct
17− ${gnused}/bin/sed -e '/^env[.]Append(BUILDERS/ienv.Append(ENV={"NIX_CFLAGS_COMPILE":os.environ["NIX_CFLAGS_COMPILE"]})' -i SConstruct
18− ${gnused}/bin/sed -e '/^env[.]Append(BUILDERS/ienv.Append(ENV={"NIX_LDFLAGS":os.environ["NIX_LDFLAGS"]})' -i SConstruct
12+ nativeBuildInputs = [ pkgconfig ];
13+ buildInputs = [ apr scons openssl aprutil zlib libiconv ]
14+ ++ stdenv.lib.optional (!stdenv.isCygwin) kerberos;
15+
16+ postPatch = ''
17+ sed -e '/^env[.]Append(BUILDERS/ienv.Append(ENV={"PATH":os.environ["PATH"]})' \
18+ -e '/^env[.]Append(BUILDERS/ienv.Append(ENV={"NIX_CFLAGS_COMPILE":os.environ["NIX_CFLAGS_COMPILE"]})' \
19+ -e '/^env[.]Append(BUILDERS/ienv.Append(ENV={"NIX_LDFLAGS":os.environ["NIX_LDFLAGS"]})' \
20+ -e 's,$OPENSSL/lib,${openssl.out}/lib,' \
21+ -e 's,$OPENSSL/include,${openssl.dev}/include,' \
22+ -i SConstruct
1923 '';
2024
2125 buildPhase = ''
22− scons PREFIX="$out" OPENSSL="${openssl.dev}" ZLIB="${zlib.dev}" APR="$(echo "${apr.dev}"/bin/*-config)" \
26+ scons PREFIX="$out" OPENSSL="${openssl}" ZLIB="${zlib}" APR="$(echo "${apr.dev}"/bin/*-config)" CFLAGS="-I${zlib.dev}/include" \
27+ LINKFLAGS="-L${zlib.out}/lib -L${expat}/lib -L${openldap}/lib -L${libiconv}/lib" \
2328 APU="$(echo "${aprutil.dev}"/bin/*-config)" CC="${
2429 if stdenv.cc.isClang then "clang" else "${stdenv.cc}/bin/gcc"
2530 }" ${
pkgs/os-specific/linux/bcc/default.nix+7−5
@@ -25,11 +25,13 @@ stdenv.mkDerivation rec {
2525 mv $out/share/bcc/man $out/share/
2626
2727 for f in $out/share/bcc/tools\/*; do
28− ln -s $f $out/bin/$(basename $f)
29− wrapProgram $f \
30− --prefix LD_LIBRARY_PATH : $out/lib \
31− --prefix PYTHONPATH : $out/lib/python2.7/site-packages \
32− --prefix PYTHONPATH : :${pythonPackages.netaddr}/lib/${python.libPrefix}/site-packages
28+ if [ -x $f ]; then
29+ ln -s $f $out/bin/$(basename $f)
30+ wrapProgram $f \
31+ --prefix LD_LIBRARY_PATH : $out/lib \
32+ --prefix PYTHONPATH : $out/lib/python2.7/site-packages \
33+ --prefix PYTHONPATH : ${pythonPackages.netaddr}/lib/${python.libPrefix}/site-packages
34+ fi
3335 done
3436 '';
3537
pkgs/stdenv/generic/setup.sh+13
@@ -336,8 +336,20 @@ fi
336336
337337# Set the relevant environment variables to point to the build inputs
338338# found above.
339+#
340+# These `depOffset`s tell the env hook what sort of dependency
341+# (ignoring propagatedness) is being passed to the env hook. In a real
342+# language, we'd append a closure with this information to the
343+# relevant env hook array, but bash doesn't have closures, so it's
344+# easier to just pass this in.
345+
339346_addToNativeEnv() {
340347 local pkg="$1"
348+ if [[ -n "${crossConfig:-}" ]]; then
349+ local -i depOffset=-1
350+ else
351+ local -i depOffset=0
352+ fi
341353
342354 # Run the package-specific hooks set by the setup-hook scripts.
343355 runHook envHook "$pkg"
@@ -349,6 +361,7 @@ done
349361
350362_addToCrossEnv() {
351363 local pkg="$1"
364+ local -i depOffset=0
352365
353366 # Run the package-specific hooks set by the setup-hook scripts.
354367 runHook crossEnvHook "$pkg"
pkgs/tools/archivers/unzip/default.nix+1−1
@@ -37,7 +37,7 @@ stdenv.mkDerivation {
3737
3838 makefile = "unix/Makefile";
3939
40− ${"NIX_${stdenv.cc.infixSalt_}LDFLAGS"} = [ "-lbz2" ] ++ stdenv.lib.optional enableNLS "-lnatspec";
40+ NIX_LDFLAGS = [ "-lbz2" ] ++ stdenv.lib.optional enableNLS "-lnatspec";
4141
4242 buildFlags = "generic D_USE_BZ2=-DUSE_BZIP2 L_BZ2=-lbz2";
4343
pkgs/tools/misc/screenfetch/default.nix+4−11
@@ -21,17 +21,10 @@ stdenv.mkDerivation {
2121 # Fix all of the depedencies of screenfetch
2222 patchShebangs $out/bin/screenfetch
2323 wrapProgram "$out/bin/screenfetch" \
24− --set PATH : "" \
25− --prefix PATH : "${coreutils}/bin" \
26− --prefix PATH : "${gawk}/bin" \
27− --prefix PATH : "${procps}/bin" \
28− --prefix PATH : "${gnused}/bin" \
29− --prefix PATH : "${findutils}/bin" \
30− --prefix PATH : "${xdpyinfo}/bin" \
31− --prefix PATH : "${xprop}/bin" \
32− --prefix PATH : "${gnugrep}/bin" \
33− --prefix PATH : "${ncurses}/bin" \
34− --prefix PATH : "${bc}/bin"
24+ --set PATH ${stdenv.lib.makeBinPath [
25+ coreutils gawk procps gnused findutils xdpyinfo
26+ xprop gnugrep ncurses bc
27+ ]}
3528 '';
3629
3730 meta = {
pkgs/tools/package-management/nix-prefetch-scripts/default.nix+1−1
@@ -19,7 +19,7 @@ let mkPrefetchScript = tool: src: deps:
1919 done
2020 wrapArgs="$wrapArgs --prefix PATH : ${gnused}/bin"
2121 wrapArgs="$wrapArgs --prefix PATH : ${nix.out}/bin" # For nix-hash
22− wrapArgs="$wrapArgs --set HOME : /homeless-shelter"
22+ wrapArgs="$wrapArgs --set HOME /homeless-shelter"
2323 wrapProgram $out/bin/$name $wrapArgs
2424 '';
2525
pkgs/top-level/all-packages.nix+4−1
@@ -100,6 +100,8 @@ with pkgs;
100100
101101 diffPlugins = (callPackage ../build-support/plugins.nix {}).diffPlugins;
102102
103+ dieHook = makeSetupHook {} ../build-support/setup-hooks/die.sh;
104+
103105 dockerTools = callPackage ../build-support/docker { };
104106
105107 docker_compose = pythonPackages.docker_compose;
@@ -287,7 +289,8 @@ with pkgs;
287289 inherit contents compressor prepend;
288290 };
289291
290− makeWrapper = makeSetupHook { } ../build-support/setup-hooks/make-wrapper.sh;
292+ makeWrapper = makeSetupHook { deps = [ dieHook ]; }
293+ ../build-support/setup-hooks/make-wrapper.sh;
291294
292295 makeModulesClosure = { kernel, rootModules, allowMissing ? false }:
293296 callPackage ../build-support/kernel/modules-closure.nix {