···1-set -e
2set -o pipefail
34: ${outputs:=out}
···13# code). The hooks for <hookName> are the shell function or variable
14# <hookName>, and the values of the shell array ‘<hookName>Hooks’.
15runHook() {
00016 local hookName="$1"
17 shift
18- local var="$hookName"
19- if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
2021- local varRef="$var[@]"
22 local hook
23- for hook in "_callImplicitHook 0 $hookName" "${!varRef}"; do
0024 _eval "$hook" "$@"
025 done
0026 return 0
27}
28···30# Run all hooks with the specified name, until one succeeds (returns a
31# zero exit code). If none succeed, return a non-zero exit code.
32runOneHook() {
00033 local hookName="$1"
34 shift
35- local var="$hookName"
36- if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
3738- local varRef="$var[@]"
39- local hook
40- for hook in "_callImplicitHook 1 $hookName" "${!varRef}"; do
41 if _eval "$hook" "$@"; then
42- return 0
043 fi
044 done
45- return 1
0046}
4748···52# environment variables) and from shell scripts (as functions). If you
53# want to allow multiple hooks, use runHook instead.
54_callImplicitHook() {
055 local def="$1"
56 local hookName="$2"
57 case "$(type -t "$hookName")" in
58- (function|alias|builtin) "$hookName";;
59- (file) source "$hookName";;
000060 (keyword) :;;
61- (*) if [ -z "${!hookName}" ]; then return "$def"; else eval "${!hookName}"; fi;;
0000062 esac
00063}
646566# A function wrapper around ‘eval’ that ensures that ‘return’ inside
67-# hooks exits the hook, not the caller.
068_eval() {
69- local code="$1"
70- shift
71- if [ "$(type -t "$code")" = function ]; then
72- eval "$code \"\$@\""
73 else
74- eval "$code"
075 fi
076}
7778···103 exitCode="$?"
104 set +e
105106- if [ -n "$showBuildStats" ]; then
107 times > "$NIX_BUILD_TOP/.times"
108 local -a times=($(cat "$NIX_BUILD_TOP/.times"))
109 # Print the following statistics:
···114 echo "build time elapsed: " "${times[@]}"
115 fi
116117- if [ "$exitCode" != 0 ]; then
118 runHook failureHook
119120 # If the builder had a non-zero exit code and
121 # $succeedOnFailure is set, create the file
122 # ‘$out/nix-support/failed’ to signal failure, and exit
123 # normally. Otherwise, return the original exit code.
124- if [ -n "$succeedOnFailure" ]; then
125 echo "build failed with exit code $exitCode (ignored)"
126 mkdir -p "$out/nix-support"
127 printf "%s" "$exitCode" > "$out/nix-support/failed"
···147 local varName="$2"
148 local dir="$3"
149 if [ -d "$dir" ]; then
150- export "${varName}=${!varName}${!varName:+$delimiter}${dir}"
151 fi
152}
153···171# The function is used in multiple-outputs.sh hook,
172# so it is defined here but tried after the hook.
173_addRpathPrefix() {
174- if [ "$NIX_NO_SELF_RPATH" != 1 ]; then
175 export NIX_LDFLAGS="-rpath $1/lib $NIX_LDFLAGS"
176- if [ -n "$NIX_LIB64_IN_SELF_RPATH" ]; then
177 export NIX_LDFLAGS="-rpath $1/lib64 $NIX_LDFLAGS"
178 fi
179- if [ -n "$NIX_LIB32_IN_SELF_RPATH" ]; then
180 export NIX_LDFLAGS="-rpath $1/lib32 $NIX_LDFLAGS"
181 fi
182 fi
···242 addToSearchPath PATH "$i/bin"
243done
244245-if [ "$NIX_DEBUG" = 1 ]; then
246 echo "initial path: $PATH"
247fi
248249250# Check that the pre-hook initialised SHELL.
251-if [ -z "$SHELL" ]; then echo "SHELL not set"; exit 1; fi
252BASH="$SHELL"
253export CONFIG_SHELL="$SHELL"
254···259260261# Execute the pre-hook.
262-if [ -z "$shell" ]; then export shell="$SHELL"; fi
263runHook preHook
264265···279 # nix-shell doesn't use impure bash. This should replace the O(n)
280 # case with an O(1) hash map lookup, assuming bash is implemented
281 # well :D.
282- local varRef="$var[*]"
283-284- case "${!varRef}" in
285 *" $pkg "*) return 0 ;;
286 esac
0287288 eval "$var"'+=("$pkg")'
289···293 fi
294295 if [ -f "$pkg" ]; then
00296 source "$pkg"
0297 fi
298299 if [ -d "$pkg/bin" ]; then
···301 fi
302303 if [ -f "$pkg/nix-support/setup-hook" ]; then
00304 source "$pkg/nix-support/setup-hook"
0305 fi
306307 if [ -f "$pkg/nix-support/$propagatedBuildInputsFile" ]; then
···312 fi
313}
314315-if [ -z "$crossConfig" ]; then
0316 # Not cross-compiling - both buildInputs (and variants like propagatedBuildInputs)
317 # are handled identically to nativeBuildInputs
318- declare -a nativePkgs
319- for i in $nativeBuildInputs $buildInputs \
320- $defaultNativeBuildInputs $defaultBuildInputs \
321- $propagatedNativeBuildInputs $propagatedBuildInputs; do
322 findInputs "$i" nativePkgs propagated-native-build-inputs
323 done
324else
325- declare -a crossPkgs
326- for i in $buildInputs $defaultBuildInputs $propagatedBuildInputs; do
327 findInputs "$i" crossPkgs propagated-build-inputs
328 done
329330 declare -a nativePkgs
331- for i in $nativeBuildInputs $defaultNativeBuildInputs $propagatedNativeBuildInputs; do
332 findInputs "$i" nativePkgs propagated-native-build-inputs
333 done
334fi
···355 runHook envHook "$pkg"
356}
357358-for i in "${nativePkgs[@]}"; do
0359 _addToNativeEnv "$i"
360done
361···367 runHook crossEnvHook "$pkg"
368}
369370-for i in "${crossPkgs[@]}"; do
0371 _addToCrossEnv "$i"
372done
373···384# Set the prefix. This is generally $out, but it can be overriden,
385# for instance if we just want to perform a test build/install to a
386# temporary location and write a build report to $out.
387-if [ -z "$prefix" ]; then
388 prefix="$out";
389fi
390391-if [ "$useTempPrefix" = 1 ]; then
392 prefix="$NIX_BUILD_TOP/tmp_prefix";
393fi
394395396-PATH=$_PATH${_PATH:+:}$PATH
397-if [ "$NIX_DEBUG" = 1 ]; then
398 echo "final path: $PATH"
399fi
400···423# Prevent OpenSSL-based applications from using certificates in
424# /etc/ssl.
425# Leave it in shells for convenience.
426-if [ -z "$SSL_CERT_FILE" ] && [ -z "$IN_NIX_SHELL" ]; then
427 export SSL_CERT_FILE=/no-cert-file.crt
428fi
429···508509 # Select all environment variables that start with a lowercase character.
510 for varName in $(env | sed -e $'s/^\([a-z][^= \t]*\)=.*/\\1/; t \n d'); do
511- if [ "$NIX_DEBUG" = "1" ]; then
512 echo "@${varName}@ -> '${!varName}'"
513 fi
514 args+=("--subst-var" "$varName")
···535# then go to the build directory and source in `env-vars' to reproduce
536# the environment used for building.
537dumpVars() {
538- if [ "$noDumpEnvVars" != 1 ]; then
539 export > "$NIX_BUILD_TOP/env-vars" || true
540 fi
541}
···600unpackPhase() {
601 runHook preUnpack
602603- if [ -z "$srcs" ]; then
604- if [ -z "$src" ]; then
605 # shellcheck disable=SC2016
606 echo 'variable $src or $srcs should point to the source'
607 exit 1
···626 done
627628 # Find the source directory.
629- if [ -n "$setSourceRoot" ]; then
0000630 runOneHook setSourceRoot
631 elif [ -z "$sourceRoot" ]; then
632- sourceRoot=
633 for i in *; do
634 if [ -d "$i" ]; then
635 case $dirsBefore in
···657 # By default, add write permission to the sources. This is often
658 # necessary when sources have been copied from other store
659 # locations.
660- if [ "$dontMakeSourcesWritable" != 1 ]; then
661 chmod -R u+w "$sourceRoot"
662 fi
663···668patchPhase() {
669 runHook prePatch
670671- for i in $patches; do
672 header "applying patch $i" 3
673 local uncompress=cat
674 case "$i" in
···702configurePhase() {
703 runHook preConfigure
7040000705 if [[ -z "$configureScript" && -x ./configure ]]; then
706 configureScript=./configure
707 fi
708709- if [ -z "$dontFixLibtool" ]; then
710 local i
711 find . -iname "ltmain.sh" -print0 | while IFS='' read -r -d '' i; do
712 echo "fixing libtool script $i"
···714 done
715 fi
716717- if [[ -z "$dontAddPrefix" && -n "$prefix" ]]; then
718 configureFlags="${prefixKey:---prefix=}$prefix $configureFlags"
719 fi
720721 # Add --disable-dependency-tracking to speed up some builds.
722- if [ -z "$dontAddDisableDepTrack" ]; then
723 if [ -f "$configureScript" ] && grep -q dependency-tracking "$configureScript"; then
724 configureFlags="--disable-dependency-tracking $configureFlags"
725 fi
726 fi
727728 # By default, disable static builds.
729- if [ -z "$dontDisableStatic" ]; then
730 if [ -f "$configureScript" ] && grep -q enable-static "$configureScript"; then
731 configureFlags="--disable-static $configureFlags"
732 fi
733 fi
734735 if [ -n "$configureScript" ]; then
0736 # shellcheck disable=SC2086
737- local flagsArray=($configureFlags "${configureFlagsArray[@]}")
00738 echoCmd 'configure flags' "${flagsArray[@]}"
739 # shellcheck disable=SC2086
740 $configureScript "${flagsArray[@]}"
···750buildPhase() {
751 runHook preBuild
752753- if [[ -z "$makeFlags" && ! ( -n "$makefile" || -e Makefile || -e makefile || -e GNUmakefile ) ]]; then
000754 echo "no Makefile, doing nothing"
755 else
756 # See https://github.com/NixOS/nixpkgs/pull/1354#issuecomment-31260409
757 makeFlags="SHELL=$SHELL $makeFlags"
7580759 # shellcheck disable=SC2086
760- local flagsArray=( \
761- ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} \
762- $makeFlags "${makeFlagsArray[@]}" \
763- $buildFlags "${buildFlagsArray[@]}")
0764765 echoCmd 'build flags' "${flagsArray[@]}"
766 make ${makefile:+-f $makefile} "${flagsArray[@]}"
···774checkPhase() {
775 runHook preCheck
7760777 # shellcheck disable=SC2086
778- local flagsArray=( \
779- ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} \
780- $makeFlags "${makeFlagsArray[@]}" \
781- ${checkFlags:-VERBOSE=y} "${checkFlagsArray[@]}" ${checkTarget:-check})
00782783 echoCmd 'check flags' "${flagsArray[@]}"
784 make ${makefile:+-f $makefile} "${flagsArray[@]}"
···797798 installTargets="${installTargets:-install}"
7990800 # shellcheck disable=SC2086
801- local flagsArray=( $installTargets \
802- $makeFlags "${makeFlagsArray[@]}" \
803- $installFlags "${installFlagsArray[@]}")
00804805 echoCmd 'install flags' "${flagsArray[@]}"
806 make ${makefile:+-f $makefile} "${flagsArray[@]}"
···830831 # Propagate build inputs and setup hook into the development output.
832833- if [ -z "$crossConfig" ]; then
834 # Not cross-compiling - propagatedBuildInputs are handled identically to propagatedNativeBuildInputs
835 local propagated="$propagatedNativeBuildInputs"
836- if [ -n "$propagatedBuildInputs" ]; then
837 propagated+="${propagated:+ }$propagatedBuildInputs"
838 fi
839- if [ -n "$propagated" ]; then
840 mkdir -p "${!outputDev}/nix-support"
841 # shellcheck disable=SC2086
842 printWords $propagated > "${!outputDev}/nix-support/propagated-native-build-inputs"
843 fi
844 else
845- if [ -n "$propagatedBuildInputs" ]; then
846 mkdir -p "${!outputDev}/nix-support"
847 # shellcheck disable=SC2086
848 printWords $propagatedBuildInputs > "${!outputDev}/nix-support/propagated-build-inputs"
849 fi
850851- if [ -n "$propagatedNativeBuildInputs" ]; then
852 mkdir -p "${!outputDev}/nix-support"
853 # shellcheck disable=SC2086
854 printWords $propagatedNativeBuildInputs > "${!outputDev}/nix-support/propagated-native-build-inputs"
855 fi
856 fi
857858- if [ -n "$setupHook" ]; then
859 mkdir -p "${!outputDev}/nix-support"
860 substituteAll "$setupHook" "${!outputDev}/nix-support/setup-hook"
861 fi
862863 # Propagate user-env packages into the output with binaries, TODO?
864865- if [ -n "$propagatedUserEnvPkgs" ]; then
866 mkdir -p "${!outputBin}/nix-support"
867 # shellcheck disable=SC2086
868 printWords $propagatedUserEnvPkgs > "${!outputBin}/nix-support/propagated-user-env-packages"
···875installCheckPhase() {
876 runHook preInstallCheck
8770878 # shellcheck disable=SC2086
879- local flagsArray=( \
880- ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} \
881- $makeFlags "${makeFlagsArray[@]}" \
882- $installCheckFlags "${installCheckFlagsArray[@]}" ${installCheckTarget:-installcheck})
00883884 echoCmd 'installcheck flags' "${flagsArray[@]}"
885 make ${makefile:+-f $makefile} "${flagsArray[@]}"
···892distPhase() {
893 runHook preDist
8940895 # shellcheck disable=SC2086
896- local flagsArray=($distFlags "${distFlagsArray[@]}" ${distTarget:-dist})
00897898 echo 'dist flags: %q' "${flagsArray[@]}"
899 make ${makefile:+-f $makefile} "${flagsArray[@]}"
900901- if [ "$dontCopyDist" != 1 ]; then
902 mkdir -p "$out/tarballs"
903904 # Note: don't quote $tarballs, since we explicitly permit
···928929930genericBuild() {
931- if [ -f "$buildCommandPath" ]; then
932- . "$buildCommandPath"
000933 return
934 fi
935- if [ -n "$buildCommand" ]; then
00936 eval "$buildCommand"
0937 return
938 fi
939940- if [ -z "$phases" ]; then
941- phases="$prePhases unpackPhase patchPhase $preConfigurePhases \
942- configurePhase $preBuildPhases buildPhase checkPhase \
943- $preInstallPhases installPhase $preFixupPhases fixupPhase installCheckPhase \
944- $preDistPhases distPhase $postPhases";
945 fi
946947 for curPhase in $phases; do
948- if [[ "$curPhase" = buildPhase && -n "$dontBuild" ]]; then continue; fi
949- if [[ "$curPhase" = checkPhase && -z "$doCheck" ]]; then continue; fi
950- if [[ "$curPhase" = installPhase && -n "$dontInstall" ]]; then continue; fi
951- if [[ "$curPhase" = fixupPhase && -n "$dontFixup" ]]; then continue; fi
952- if [[ "$curPhase" = installCheckPhase && -z "$doInstallCheck" ]]; then continue; fi
953- if [[ "$curPhase" = distPhase && -z "$doDist" ]]; then continue; fi
954955- if [[ -n "$tracePhases" ]]; then
956 echo
957 echo "@ phase-started $out $curPhase"
958 fi
···962963 # Evaluate the variable named $curPhase if it exists, otherwise the
964 # function named $curPhase.
00965 eval "${!curPhase:-$curPhase}"
0966967 if [ "$curPhase" = unpackPhase ]; then
968 cd "${sourceRoot:-.}"
969 fi
970971- if [ -n "$tracePhases" ]; then
972 echo
973 echo "@ phase-succeeded $out $curPhase"
974 fi
···987988989dumpVars
000
···1+set -eu
2set -o pipefail
34: ${outputs:=out}
···13# code). The hooks for <hookName> are the shell function or variable
14# <hookName>, and the values of the shell array ‘<hookName>Hooks’.
15runHook() {
16+ local oldOpts="$(shopt -po nounset)"
17+ set -u # May be called from elsewhere, so do `set -u`.
18+19 local hookName="$1"
20 shift
21+ local hooksSlice="${hookName%Hook}Hooks[@]"
022023 local hook
24+ # Hack around old bash being bad and thinking empty arrays are
25+ # undefined.
26+ for hook in "_callImplicitHook 0 $hookName" ${!hooksSlice+"${!hooksSlice}"}; do
27 _eval "$hook" "$@"
28+ set -u # To balance `_eval`
29 done
30+31+ eval "${oldOpts}"
32 return 0
33}
34···36# Run all hooks with the specified name, until one succeeds (returns a
37# zero exit code). If none succeed, return a non-zero exit code.
38runOneHook() {
39+ local oldOpts="$(shopt -po nounset)"
40+ set -u # May be called from elsewhere, so do `set -u`.
41+42 local hookName="$1"
43 shift
44+ local hooksSlice="${hookName%Hook}Hooks[@]"
04546+ local hook ret=1
47+ # Hack around old bash like above
48+ for hook in "_callImplicitHook 1 $hookName" ${!hooksSlice+"${!hooksSlice}"}; do
49 if _eval "$hook" "$@"; then
50+ ret=0
51+ break
52 fi
53+ set -u # To balance `_eval`
54 done
55+56+ eval "${oldOpts}"
57+ return "$ret"
58}
5960···64# environment variables) and from shell scripts (as functions). If you
65# want to allow multiple hooks, use runHook instead.
66_callImplicitHook() {
67+ set -u
68 local def="$1"
69 local hookName="$2"
70 case "$(type -t "$hookName")" in
71+ (function|alias|builtin)
72+ set +u
73+ "$hookName";;
74+ (file)
75+ set +u
76+ source "$hookName";;
77 (keyword) :;;
78+ (*) if [ -z "${!hookName:-}" ]; then
79+ return "$def";
80+ else
81+ set +u
82+ eval "${!hookName}"
83+ fi;;
84 esac
85+ # `_eval` expects hook to need nounset disable and leave it
86+ # disabled anyways, so Ok to to delegate. The alternative of a
87+ # return trap is no good because it would affect nested returns.
88}
899091# A function wrapper around ‘eval’ that ensures that ‘return’ inside
92+# hooks exits the hook, not the caller. Also will only pass args if
93+# command can take them
94_eval() {
95+ if [ "$(type -t "$1")" = function ]; then
96+ set +u
97+ "$@" # including args
098 else
99+ set +u
100+ eval "$1"
101 fi
102+ # `run*Hook` reenables `set -u`
103}
104105···130 exitCode="$?"
131 set +e
132133+ if [ -n "${showBuildStats:-}" ]; then
134 times > "$NIX_BUILD_TOP/.times"
135 local -a times=($(cat "$NIX_BUILD_TOP/.times"))
136 # Print the following statistics:
···141 echo "build time elapsed: " "${times[@]}"
142 fi
143144+ if (( "$exitCode" != 0 )); then
145 runHook failureHook
146147 # If the builder had a non-zero exit code and
148 # $succeedOnFailure is set, create the file
149 # ‘$out/nix-support/failed’ to signal failure, and exit
150 # normally. Otherwise, return the original exit code.
151+ if [ -n "${succeedOnFailure:-}" ]; then
152 echo "build failed with exit code $exitCode (ignored)"
153 mkdir -p "$out/nix-support"
154 printf "%s" "$exitCode" > "$out/nix-support/failed"
···174 local varName="$2"
175 local dir="$3"
176 if [ -d "$dir" ]; then
177+ export "${varName}=${!varName:+${!varName}${delimiter}}${dir}"
178 fi
179}
180···198# The function is used in multiple-outputs.sh hook,
199# so it is defined here but tried after the hook.
200_addRpathPrefix() {
201+ if [ "${NIX_NO_SELF_RPATH:-0}" != 1 ]; then
202 export NIX_LDFLAGS="-rpath $1/lib $NIX_LDFLAGS"
203+ if [ -n "${NIX_LIB64_IN_SELF_RPATH:-}" ]; then
204 export NIX_LDFLAGS="-rpath $1/lib64 $NIX_LDFLAGS"
205 fi
206+ if [ -n "${NIX_LIB32_IN_SELF_RPATH:-}" ]; then
207 export NIX_LDFLAGS="-rpath $1/lib32 $NIX_LDFLAGS"
208 fi
209 fi
···269 addToSearchPath PATH "$i/bin"
270done
271272+if [ "${NIX_DEBUG:-}" = 1 ]; then
273 echo "initial path: $PATH"
274fi
275276277# Check that the pre-hook initialised SHELL.
278+if [ -z "${SHELL:-}" ]; then echo "SHELL not set"; exit 1; fi
279BASH="$SHELL"
280export CONFIG_SHELL="$SHELL"
281···286287288# Execute the pre-hook.
289+if [ -z "${shell:-}" ]; then export shell="$SHELL"; fi
290runHook preHook
291292···306 # nix-shell doesn't use impure bash. This should replace the O(n)
307 # case with an O(1) hash map lookup, assuming bash is implemented
308 # well :D.
309+ local varSlice="$var[*]"
310+ # ${..-} to hack around old bash empty array problem
311+ case "${!varSlice-}" in
312 *" $pkg "*) return 0 ;;
313 esac
314+ unset -v varSlice
315316 eval "$var"'+=("$pkg")'
317···321 fi
322323 if [ -f "$pkg" ]; then
324+ local oldOpts="$(shopt -po nounset)"
325+ set +u
326 source "$pkg"
327+ eval "$oldOpts"
328 fi
329330 if [ -d "$pkg/bin" ]; then
···332 fi
333334 if [ -f "$pkg/nix-support/setup-hook" ]; then
335+ local oldOpts="$(shopt -po nounset)"
336+ set +u
337 source "$pkg/nix-support/setup-hook"
338+ eval "$oldOpts"
339 fi
340341 if [ -f "$pkg/nix-support/$propagatedBuildInputsFile" ]; then
···346 fi
347}
348349+declare -a nativePkgs crossPkgs
350+if [ -z "${crossConfig:-}" ]; then
351 # Not cross-compiling - both buildInputs (and variants like propagatedBuildInputs)
352 # are handled identically to nativeBuildInputs
353+ for i in ${nativeBuildInputs:-} ${buildInputs:-} \
354+ ${defaultNativeBuildInputs:-} ${defaultBuildInputs:-} \
355+ ${propagatedNativeBuildInputs:-} ${propagatedBuildInputs:-}; do
0356 findInputs "$i" nativePkgs propagated-native-build-inputs
357 done
358else
359+ for i in ${buildInputs:-} ${defaultBuildInputs:-} ${propagatedBuildInputs:-}; do
0360 findInputs "$i" crossPkgs propagated-build-inputs
361 done
362363 declare -a nativePkgs
364+ for i in ${nativeBuildInputs:-} ${defaultNativeBuildInputs:-} ${propagatedNativeBuildInputs:-}; do
365 findInputs "$i" nativePkgs propagated-native-build-inputs
366 done
367fi
···388 runHook envHook "$pkg"
389}
390391+# Old bash empty array hack
392+for i in ${nativePkgs+"${nativePkgs[@]}"}; do
393 _addToNativeEnv "$i"
394done
395···401 runHook crossEnvHook "$pkg"
402}
403404+# Old bash empty array hack
405+for i in ${crossPkgs+"${crossPkgs[@]}"}; do
406 _addToCrossEnv "$i"
407done
408···419# Set the prefix. This is generally $out, but it can be overriden,
420# for instance if we just want to perform a test build/install to a
421# temporary location and write a build report to $out.
422+if [ -z "${prefix:-}" ]; then
423 prefix="$out";
424fi
425426+if [ "${useTempPrefix:-}" = 1 ]; then
427 prefix="$NIX_BUILD_TOP/tmp_prefix";
428fi
429430431+PATH="${_PATH-}${_PATH:+${PATH:+:}}$PATH"
432+if [ "${NIX_DEBUG:-}" = 1 ]; then
433 echo "final path: $PATH"
434fi
435···458# Prevent OpenSSL-based applications from using certificates in
459# /etc/ssl.
460# Leave it in shells for convenience.
461+if [ -z "${SSL_CERT_FILE:-}" ] && [ -z "${IN_NIX_SHELL:-}" ]; then
462 export SSL_CERT_FILE=/no-cert-file.crt
463fi
464···543544 # Select all environment variables that start with a lowercase character.
545 for varName in $(env | sed -e $'s/^\([a-z][^= \t]*\)=.*/\\1/; t \n d'); do
546+ if [ "${NIX_DEBUG:-}" = "1" ]; then
547 echo "@${varName}@ -> '${!varName}'"
548 fi
549 args+=("--subst-var" "$varName")
···570# then go to the build directory and source in `env-vars' to reproduce
571# the environment used for building.
572dumpVars() {
573+ if [ "${noDumpEnvVars:-0}" != 1 ]; then
574 export > "$NIX_BUILD_TOP/env-vars" || true
575 fi
576}
···635unpackPhase() {
636 runHook preUnpack
637638+ if [ -z "${srcs:-}" ]; then
639+ if [ -z "${src:-}" ]; then
640 # shellcheck disable=SC2016
641 echo 'variable $src or $srcs should point to the source'
642 exit 1
···661 done
662663 # Find the source directory.
664+665+ # set to empty if unset
666+ : ${sourceRoot=}
667+668+ if [ -n "${setSourceRoot:-}" ]; then
669 runOneHook setSourceRoot
670 elif [ -z "$sourceRoot" ]; then
0671 for i in *; do
672 if [ -d "$i" ]; then
673 case $dirsBefore in
···695 # By default, add write permission to the sources. This is often
696 # necessary when sources have been copied from other store
697 # locations.
698+ if [ "${dontMakeSourcesWritable:-0}" != 1 ]; then
699 chmod -R u+w "$sourceRoot"
700 fi
701···706patchPhase() {
707 runHook prePatch
708709+ for i in ${patches:-}; do
710 header "applying patch $i" 3
711 local uncompress=cat
712 case "$i" in
···740configurePhase() {
741 runHook preConfigure
742743+ # set to empty if unset
744+ : ${configureScript=}
745+ : ${configureFlags=}
746+747 if [[ -z "$configureScript" && -x ./configure ]]; then
748 configureScript=./configure
749 fi
750751+ if [ -z "${dontFixLibtool:-}" ]; then
752 local i
753 find . -iname "ltmain.sh" -print0 | while IFS='' read -r -d '' i; do
754 echo "fixing libtool script $i"
···756 done
757 fi
758759+ if [[ -z "${dontAddPrefix:-}" && -n "$prefix" ]]; then
760 configureFlags="${prefixKey:---prefix=}$prefix $configureFlags"
761 fi
762763 # Add --disable-dependency-tracking to speed up some builds.
764+ if [ -z "${dontAddDisableDepTrack:-}" ]; then
765 if [ -f "$configureScript" ] && grep -q dependency-tracking "$configureScript"; then
766 configureFlags="--disable-dependency-tracking $configureFlags"
767 fi
768 fi
769770 # By default, disable static builds.
771+ if [ -z "${dontDisableStatic:-}" ]; then
772 if [ -f "$configureScript" ] && grep -q enable-static "$configureScript"; then
773 configureFlags="--disable-static $configureFlags"
774 fi
775 fi
776777 if [ -n "$configureScript" ]; then
778+ # Old bash empty array hack
779 # shellcheck disable=SC2086
780+ local flagsArray=(
781+ $configureFlags ${configureFlagsArray+"${configureFlagsArray[@]}"}
782+ )
783 echoCmd 'configure flags' "${flagsArray[@]}"
784 # shellcheck disable=SC2086
785 $configureScript "${flagsArray[@]}"
···795buildPhase() {
796 runHook preBuild
797798+ # set to empty if unset
799+ : ${makeFlags=}
800+801+ if [[ -z "$makeFlags" && ! ( -n "${makefile:-}" || -e Makefile || -e makefile || -e GNUmakefile ) ]]; then
802 echo "no Makefile, doing nothing"
803 else
804 # See https://github.com/NixOS/nixpkgs/pull/1354#issuecomment-31260409
805 makeFlags="SHELL=$SHELL $makeFlags"
806807+ # Old bash empty array hack
808 # shellcheck disable=SC2086
809+ local flagsArray=(
810+ ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}}
811+ $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
812+ $buildFlags ${buildFlagsArray+"${buildFlagsArray[@]}"}
813+ )
814815 echoCmd 'build flags' "${flagsArray[@]}"
816 make ${makefile:+-f $makefile} "${flagsArray[@]}"
···824checkPhase() {
825 runHook preCheck
826827+ # Old bash empty array hack
828 # shellcheck disable=SC2086
829+ local flagsArray=(
830+ ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}}
831+ $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
832+ ${checkFlags:-VERBOSE=y} ${checkFlagsArray+"${checkFlagsArray[@]}"}
833+ ${checkTarget:-check}
834+ )
835836 echoCmd 'check flags' "${flagsArray[@]}"
837 make ${makefile:+-f $makefile} "${flagsArray[@]}"
···850851 installTargets="${installTargets:-install}"
852853+ # Old bash empty array hack
854 # shellcheck disable=SC2086
855+ local flagsArray=(
856+ $installTargets
857+ $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
858+ $installFlags ${installFlagsArray+"${installFlagsArray[@]}"}
859+ )
860861 echoCmd 'install flags' "${flagsArray[@]}"
862 make ${makefile:+-f $makefile} "${flagsArray[@]}"
···886887 # Propagate build inputs and setup hook into the development output.
888889+ if [ -z "${crossConfig:-}" ]; then
890 # Not cross-compiling - propagatedBuildInputs are handled identically to propagatedNativeBuildInputs
891 local propagated="$propagatedNativeBuildInputs"
892+ if [ -n "${propagatedBuildInputs:-}" ]; then
893 propagated+="${propagated:+ }$propagatedBuildInputs"
894 fi
895+ if [ -n "${propagated:-}" ]; then
896 mkdir -p "${!outputDev}/nix-support"
897 # shellcheck disable=SC2086
898 printWords $propagated > "${!outputDev}/nix-support/propagated-native-build-inputs"
899 fi
900 else
901+ if [ -n "${propagatedBuildInputs:-}" ]; then
902 mkdir -p "${!outputDev}/nix-support"
903 # shellcheck disable=SC2086
904 printWords $propagatedBuildInputs > "${!outputDev}/nix-support/propagated-build-inputs"
905 fi
906907+ if [ -n "${propagatedNativeBuildInputs:-}" ]; then
908 mkdir -p "${!outputDev}/nix-support"
909 # shellcheck disable=SC2086
910 printWords $propagatedNativeBuildInputs > "${!outputDev}/nix-support/propagated-native-build-inputs"
911 fi
912 fi
913914+ if [ -n "${setupHook:-}" ]; then
915 mkdir -p "${!outputDev}/nix-support"
916 substituteAll "$setupHook" "${!outputDev}/nix-support/setup-hook"
917 fi
918919 # Propagate user-env packages into the output with binaries, TODO?
920921+ if [ -n "${propagatedUserEnvPkgs:-}" ]; then
922 mkdir -p "${!outputBin}/nix-support"
923 # shellcheck disable=SC2086
924 printWords $propagatedUserEnvPkgs > "${!outputBin}/nix-support/propagated-user-env-packages"
···931installCheckPhase() {
932 runHook preInstallCheck
933934+ # Old bash empty array hack
935 # shellcheck disable=SC2086
936+ local flagsArray=(
937+ ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}}
938+ $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
939+ $installCheckFlags ${installCheckFlagsArray+"${installCheckFlagsArray[@]}"}
940+ ${installCheckTarget:-installcheck}
941+ )
942943 echoCmd 'installcheck flags' "${flagsArray[@]}"
944 make ${makefile:+-f $makefile} "${flagsArray[@]}"
···951distPhase() {
952 runHook preDist
953954+ # Old bash empty array hack
955 # shellcheck disable=SC2086
956+ local flagsArray=(
957+ $distFlags ${distFlagsArray+"${distFlagsArray[@]}"} ${distTarget:-dist}
958+ )
959960 echo 'dist flags: %q' "${flagsArray[@]}"
961 make ${makefile:+-f $makefile} "${flagsArray[@]}"
962963+ if [ "${dontCopyDist:-0}" != 1 ]; then
964 mkdir -p "$out/tarballs"
965966 # Note: don't quote $tarballs, since we explicitly permit
···990991992genericBuild() {
993+ if [ -f "${buildCommandPath:-}" ]; then
994+ local oldOpts="$(shopt -po nounset)"
995+ set +u
996+ source "$buildCommandPath"
997+ eval "$oldOpts"
998 return
999 fi
1000+ if [ -n "${buildCommand:-}" ]; then
1001+ local oldOpts="$(shopt -po nounset)"
1002+ set +u
1003 eval "$buildCommand"
1004+ eval "$oldOpts"
1005 return
1006 fi
10071008+ if [ -z "${phases:-}" ]; then
1009+ phases="${prePhases:-} unpackPhase patchPhase ${preConfigurePhases:-} \
1010+ configurePhase ${preBuildPhases:-} buildPhase checkPhase \
1011+ ${preInstallPhases:-} installPhase ${preFixupPhases:-} fixupPhase installCheckPhase \
1012+ ${preDistPhases:-} distPhase ${postPhases:-}";
1013 fi
10141015 for curPhase in $phases; do
1016+ if [[ "$curPhase" = buildPhase && -n "${dontBuild:-}" ]]; then continue; fi
1017+ if [[ "$curPhase" = checkPhase && -z "${doCheck:-}" ]]; then continue; fi
1018+ if [[ "$curPhase" = installPhase && -n "${dontInstall:-}" ]]; then continue; fi
1019+ if [[ "$curPhase" = fixupPhase && -n "${dontFixup:-}" ]]; then continue; fi
1020+ if [[ "$curPhase" = installCheckPhase && -z "${doInstallCheck:-}" ]]; then continue; fi
1021+ if [[ "$curPhase" = distPhase && -z "${doDist:-}" ]]; then continue; fi
10221023+ if [[ -n "${tracePhases:-}" ]]; then
1024 echo
1025 echo "@ phase-started $out $curPhase"
1026 fi
···10301031 # Evaluate the variable named $curPhase if it exists, otherwise the
1032 # function named $curPhase.
1033+ local oldOpts="$(shopt -po nounset)"
1034+ set +u
1035 eval "${!curPhase:-$curPhase}"
1036+ eval "$oldOpts"
10371038 if [ "$curPhase" = unpackPhase ]; then
1039 cd "${sourceRoot:-.}"
1040 fi
10411042+ if [ -n "${tracePhases:-}" ]; then
1043 echo
1044 echo "@ phase-succeeded $out $curPhase"
1045 fi
···105810591060dumpVars
1061+1062+# Disable nounset for nix-shell.
1063+set +u