Revert #127736: stdenv changes towards an alternative shell

At least for now.  Such changes are risky (we have very many packages),
and apparently it needs more testing/review without blocking other
changes.

This reverts the whole range 4d0e3984918^..8752c327377,
except for one commit that got reverted in 6f239d7309 already.
(that MR didn't even get its merge commit)
This commit is contained in:
Vladimír Čunát 2021-07-17 20:27:52 +02:00
parent d6b748b2b3
commit 4bd38c330f
No known key found for this signature in database
GPG key ID: E747DF1F9575A3AA
9 changed files with 128 additions and 179 deletions

View file

@ -1,4 +1,3 @@
# shellcheck shell=bash
# Binutils Wrapper hygiene # Binutils Wrapper hygiene
# #
# See comments in cc-wrapper's setup hook. This works exactly the same way. # See comments in cc-wrapper's setup hook. This works exactly the same way.
@ -15,9 +14,7 @@ bintoolsWrapper_addLDVars () {
getHostRoleEnvHook getHostRoleEnvHook
if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then
varName=NIX_LDFLAGS${role_post} export NIX_LDFLAGS${role_post}+=" -L$1/lib64"
eval "$varName=\"${!varName:-} -L$1/lib64\""
export "${varName?}"
fi fi
if [[ -d "$1/lib" ]]; then if [[ -d "$1/lib" ]]; then
@ -27,9 +24,7 @@ bintoolsWrapper_addLDVars () {
# directories and bloats the size of the environment variable space. # directories and bloats the size of the environment variable space.
local -a glob=( $1/lib/lib* ) local -a glob=( $1/lib/lib* )
if [ "${#glob[*]}" -gt 0 ]; then if [ "${#glob[*]}" -gt 0 ]; then
varName=NIX_LDFLAGS${role_post} export NIX_LDFLAGS${role_post}+=" -L$1/lib"
eval "$varName=\"${!varName:-} -L$1/lib\""
export "${varName?}"
fi fi
fi fi
} }

View file

@ -29,7 +29,6 @@ isExecutable() {
isExeResult="$(LANG=C $READELF -h -l "$1" 2> /dev/null \ isExeResult="$(LANG=C $READELF -h -l "$1" 2> /dev/null \
| grep '^ *Type: *EXEC\>\|^ *INTERP\>')" | grep '^ *Type: *EXEC\>\|^ *INTERP\>')"
# not using grep -q, because it can cause Broken pipe # not using grep -q, because it can cause Broken pipe
# https://unix.stackexchange.com/questions/305547/broken-pipe-when-grepping-output-but-only-with-i-flag
[ -n "$isExeResult" ] [ -n "$isExeResult" ]
} }

View file

@ -1,5 +1,4 @@
# shellcheck shell=bash preConfigurePhases+=" autoreconfPhase"
preConfigurePhases="${preConfigurePhases:-} autoreconfPhase"
autoreconfPhase() { autoreconfPhase() {
runHook preAutoreconf runHook preAutoreconf

View file

@ -1,4 +1,3 @@
# shellcheck shell=bash
fixupOutputHooks+=(_makeSymlinksRelative) fixupOutputHooks+=(_makeSymlinksRelative)
# For every symlink in $output that refers to another file in $output # For every symlink in $output that refers to another file in $output

View file

@ -6,7 +6,7 @@ preFixupHooks+=(_moveToShare)
_moveToShare() { _moveToShare() {
forceShare=${forceShare:=man doc info} forceShare=${forceShare:=man doc info}
if [[ -z $forceShare || -z $out ]]; then return; fi if [ -z "$forceShare" -o -z "$out" ]; then return; fi
for d in $forceShare; do for d in $forceShare; do
if [ -d "$out/$d" ]; then if [ -d "$out/$d" ]; then
@ -14,9 +14,10 @@ _moveToShare() {
echo "both $d/ and share/$d/ exist!" echo "both $d/ and share/$d/ exist!"
else else
echo "moving $out/$d to $out/share/$d" echo "moving $out/$d to $out/share/$d"
mkdir -p "$out/share" mkdir -p $out/share
mv "$out/$d" "$out/share/" mv $out/$d $out/share/
fi fi
fi fi
done done
} }

View file

@ -1,4 +1,3 @@
# shellcheck shell=bash
# The base package for automatic multiple-output splitting. Used in stdenv as well. # The base package for automatic multiple-output splitting. Used in stdenv as well.
preConfigureHooks+=(_multioutConfig) preConfigureHooks+=(_multioutConfig)
preFixupHooks+=(_multioutDocs) preFixupHooks+=(_multioutDocs)
@ -48,25 +47,22 @@ _overrideFirst outputInfo "info" "$outputBin"
# Add standard flags to put files into the desired outputs. # Add standard flags to put files into the desired outputs.
_multioutConfig() { _multioutConfig() {
if [[ "$outputs" = "out" || -z "${setOutputFlags-1}" ]]; then if [ "$outputs" = "out" ] || [ -z "${setOutputFlags-1}" ]; then return; fi;
return
fi
# try to detect share/doc/${shareDocName} # try to detect share/doc/${shareDocName}
# Note: sadly, $configureScript detection comes later in configurePhase, # Note: sadly, $configureScript detection comes later in configurePhase,
# and reordering would cause more trouble than worth. # and reordering would cause more trouble than worth.
if [ -z "$shareDocName" ]; then if [ -z "$shareDocName" ]; then
local confScript="$configureScript" local confScript="$configureScript"
if [[ -z "$confScript" && -x ./configure ]]; then if [ -z "$confScript" ] && [ -x ./configure ]; then
confScript=./configure confScript=./configure
fi fi
if [ -f "$confScript" ]; then if [ -f "$confScript" ]; then
local shareDocName="$(sed -n "s/^PACKAGE_TARNAME='\(.*\)'$/\1/p" < "$confScript")" local shareDocName="$(sed -n "s/^PACKAGE_TARNAME='\(.*\)'$/\1/p" < "$confScript")"
# PACKAGE_TARNAME sometimes contains garbage. fi
# verify that shareDocName contains only valid characters # PACKAGE_TARNAME sometimes contains garbage.
if ! [[ $shareDocName =~ ^[a-zA-Z0f9_-]+$ ]]; then if [ -z "$shareDocName" ] || echo "$shareDocName" | grep -q '[^a-zA-Z0-9_-]'; then
shareDocName="$(echo "$name" | sed 's/-[^a-zA-Z].*//')" shareDocName="$(echo "$name" | sed 's/-[^a-zA-Z].*//')"
fi
fi fi
fi fi

View file

@ -1,13 +1,9 @@
# shellcheck disable=SC2148
# Use the last part of the out path as hash input for the build. # Use the last part of the out path as hash input for the build.
# This should ensure that it is deterministic across rebuilds of the same # This should ensure that it is deterministic across rebuilds of the same
# derivation and not easily collide with other builds. # derivation and not easily collide with other builds.
# We also truncate the hash so that it cannot cause reference cycles. # We also truncate the hash so that it cannot cause reference cycles.
# NIX_CFLAGS_COMPILE might not have been defined before export NIX_CFLAGS_COMPILE+=" -frandom-seed=$(
NIX_CFLAGS_COMPILE="${NIX_CFLAGS_COMPILE:-} -frandom-seed=$(
# shellcheck disable=SC2154
outbase="${out##*/}" outbase="${out##*/}"
randomseed="${outbase:0:10}" randomseed="${outbase:0:10}"
echo "$randomseed" echo $randomseed
)" )"
export NIX_CFLAGS_COMPILE

View file

@ -4,20 +4,18 @@ for i in $initialPath; do
PATH=$PATH${PATH:+:}$i/bin PATH=$PATH${PATH:+:}$i/bin
done done
mkdir "$out" mkdir $out
{ echo "export SHELL=$shell" > $out/setup
echo "export SHELL=$shell" echo "initialPath=\"$initialPath\"" >> $out/setup
echo "initialPath=\"$initialPath\"" echo "defaultNativeBuildInputs=\"$defaultNativeBuildInputs\"" >> $out/setup
echo "defaultNativeBuildInputs=\"$defaultNativeBuildInputs\"" echo "defaultBuildInputs=\"$defaultBuildInputs\"" >> $out/setup
echo "defaultBuildInputs=\"$defaultBuildInputs\"" echo "$preHook" >> $out/setup
echo "$preHook" cat "$setup" >> $out/setup
cat "$setup"
} > "$out/setup"
# Allow the user to install stdenv using nix-env and get the packages # Allow the user to install stdenv using nix-env and get the packages
# in stdenv. # in stdenv.
mkdir $out/nix-support mkdir $out/nix-support
if [ -n "${propagatedUserEnvPkgs:-}" ]; then if [ "$propagatedUserEnvPkgs" ]; then
printf '%s ' $propagatedUserEnvPkgs > $out/nix-support/propagated-user-env-packages printf '%s ' $propagatedUserEnvPkgs > $out/nix-support/propagated-user-env-packages
fi fi

View file

@ -1,4 +1,3 @@
# shellcheck shell=bash
set -eu set -eu
set -o pipefail set -o pipefail
@ -12,7 +11,7 @@ if (( "${NIX_DEBUG:-0}" >= 6 )); then
set -x set -x
fi fi
: "${outputs:=out}" : ${outputs:=out}
###################################################################### ######################################################################
@ -69,8 +68,7 @@ _callImplicitHook() {
local hookName="$2" local hookName="$2"
if declare -F "$hookName" > /dev/null; then if declare -F "$hookName" > /dev/null; then
"$hookName" "$hookName"
elif test -e "$hookName" ; then elif type -p "$hookName" > /dev/null; then
# shellcheck disable=SC1090
source "$hookName" source "$hookName"
elif [ -n "${!hookName:-}" ]; then elif [ -n "${!hookName:-}" ]; then
eval "${!hookName}" eval "${!hookName}"
@ -124,14 +122,13 @@ exitHandler() {
if [ -n "${showBuildStats:-}" ]; then if [ -n "${showBuildStats:-}" ]; then
times > "$NIX_BUILD_TOP/.times" times > "$NIX_BUILD_TOP/.times"
local -a buildTimesArray local -a times=($(cat "$NIX_BUILD_TOP/.times"))
IFS=" " read -r -a buildTimesArray < "$NIX_BUILD_TOP/.times"
# Print the following statistics: # Print the following statistics:
# - user time for the shell # - user time for the shell
# - system time for the shell # - system time for the shell
# - user time for all child processes # - user time for all child processes
# - system time for all child processes # - system time for all child processes
echo "build time elapsed: " "${buildTimesArray[@]}" echo "build time elapsed: " "${times[@]}"
fi fi
if (( "$exitCode" != 0 )); then if (( "$exitCode" != 0 )); then
@ -143,7 +140,6 @@ exitHandler() {
# normally. Otherwise, return the original exit code. # normally. Otherwise, return the original exit code.
if [ -n "${succeedOnFailure:-}" ]; then if [ -n "${succeedOnFailure:-}" ]; then
echo "build failed with exit code $exitCode (ignored)" echo "build failed with exit code $exitCode (ignored)"
# shellcheck disable=SC2154
mkdir -p "$out/nix-support" mkdir -p "$out/nix-support"
printf "%s" "$exitCode" > "$out/nix-support/failed" printf "%s" "$exitCode" > "$out/nix-support/failed"
exit 0 exit 0
@ -236,7 +232,7 @@ printWords() {
# implementation uses zip archive and zip does not support dates going back to # implementation uses zip archive and zip does not support dates going back to
# 1970. # 1970.
export SOURCE_DATE_EPOCH export SOURCE_DATE_EPOCH
: "${SOURCE_DATE_EPOCH:=315532800}" : ${SOURCE_DATE_EPOCH:=315532800}
# Wildcard expansions that don't match should expand to an empty list. # Wildcard expansions that don't match should expand to an empty list.
@ -246,10 +242,8 @@ shopt -s nullglob
# Set up the initial path. # Set up the initial path.
# shellcheck disable=SC2123
PATH= PATH=
HOST_PATH= HOST_PATH=
# shellcheck disable=SC2154
for i in $initialPath; do for i in $initialPath; do
if [ "$i" = / ]; then i=; fi if [ "$i" = / ]; then i=; fi
addToSearchPath PATH "$i/bin" addToSearchPath PATH "$i/bin"
@ -312,10 +306,6 @@ declare -a pkgTargetHookVars=(envTargetTargetHook)
declare -a pkgHookVarVars=(pkgBuildHookVars pkgHostHookVars pkgTargetHookVars) declare -a pkgHookVarVars=(pkgBuildHookVars pkgHostHookVars pkgTargetHookVars)
# those variables are declared here, since where and if they are used varies
# shellcheck disable=SC2034
declare -a preFixupHooks fixupOutputHooks preConfigureHooks postFixupHooks postUnpackHooks unpackCmdHooks
# Add env hooks for all sorts of deps with the specified host offset. # Add env hooks for all sorts of deps with the specified host offset.
addEnvHooks() { addEnvHooks() {
local depHostOffset="$1" local depHostOffset="$1"
@ -357,14 +347,14 @@ declare -a allPlatOffsets=(-1 0 1)
# implements. # implements.
findInputs() { findInputs() {
local -r pkg="$1" local -r pkg="$1"
local -r hostOffset="$2" local -ri hostOffset="$2"
local -r targetOffset="$3" local -ri targetOffset="$3"
# Sanity check # Sanity check
(( "$hostOffset" <= "$targetOffset" )) || exit 1 (( "$hostOffset" <= "$targetOffset" )) || exit -1
local varVar="${pkgAccumVarVars[$(( hostOffset + 1 ))]}" local varVar="${pkgAccumVarVars[$hostOffset + 1]}"
local varRef="${varVar}[$(( targetOffset - hostOffset ))]" local varRef="$varVar[\$targetOffset - \$hostOffset]"
local var="${!varRef}" local var="${!varRef}"
unset -v varVar varRef unset -v varVar varRef
@ -372,7 +362,7 @@ findInputs() {
# nix-shell doesn't use impure bash. This should replace the O(n) # nix-shell doesn't use impure bash. This should replace the O(n)
# case with an O(1) hash map lookup, assuming bash is implemented # case with an O(1) hash map lookup, assuming bash is implemented
# well :D. # well :D.
local varSlice="${var}[*]" local varSlice="$var[*]"
# ${..-} to hack around old bash empty array problem # ${..-} to hack around old bash empty array problem
case "${!varSlice-}" in case "${!varSlice-}" in
*" $pkg "*) return 0 ;; *" $pkg "*) return 0 ;;
@ -389,28 +379,28 @@ findInputs() {
# The current package's host and target offset together # The current package's host and target offset together
# provide a <=-preserving homomorphism from the relative # provide a <=-preserving homomorphism from the relative
# offsets to current offset # offsets to current offset
local mapOffsetResult local -i mapOffsetResult
function mapOffset() { function mapOffset() {
local -r inputOffset="$1" local -ri inputOffset="$1"
if (( "$inputOffset" <= 0 )); then if (( "$inputOffset" <= 0 )); then
local -r outputOffset=$(( inputOffset + hostOffset )) local -ri outputOffset="$inputOffset + $hostOffset"
else else
local -r outputOffset=$(( inputOffset - 1 + targetOffset )) local -ri outputOffset="$inputOffset - 1 + $targetOffset"
fi fi
mapOffsetResult="$outputOffset" mapOffsetResult="$outputOffset"
} }
# Host offset relative to that of the package whose immediate # Host offset relative to that of the package whose immediate
# dependencies we are currently exploring. # dependencies we are currently exploring.
local relHostOffset local -i relHostOffset
for relHostOffset in "${allPlatOffsets[@]}"; do for relHostOffset in "${allPlatOffsets[@]}"; do
# `+ 1` so we start at 0 for valid index # `+ 1` so we start at 0 for valid index
local files="${propagatedDepFilesVars[$(( relHostOffset + 1 ))]}" local files="${propagatedDepFilesVars[$relHostOffset + 1]}"
# Host offset relative to the package currently being # Host offset relative to the package currently being
# built---as absolute an offset as will be used. # built---as absolute an offset as will be used.
mapOffset "$relHostOffset" mapOffset relHostOffset
local hostOffsetNext="$mapOffsetResult" local -i hostOffsetNext="$mapOffsetResult"
# Ensure we're in bounds relative to the package currently # Ensure we're in bounds relative to the package currently
# being built. # being built.
@ -418,18 +408,18 @@ findInputs() {
# Target offset relative to the *host* offset of the package # Target offset relative to the *host* offset of the package
# whose immediate dependencies we are currently exploring. # whose immediate dependencies we are currently exploring.
local relTargetOffset local -i relTargetOffset
for relTargetOffset in "${allPlatOffsets[@]}"; do for relTargetOffset in "${allPlatOffsets[@]}"; do
(( "$relHostOffset" <= "$relTargetOffset" )) || continue (( "$relHostOffset" <= "$relTargetOffset" )) || continue
local fileRef="${files}[$(( relTargetOffset - relHostOffset ))]" local fileRef="${files}[$relTargetOffset - $relHostOffset]"
local file="${!fileRef}" local file="${!fileRef}"
unset -v fileRef unset -v fileRef
# Target offset relative to the package currently being # Target offset relative to the package currently being
# built. # built.
mapOffset "$relTargetOffset" mapOffset relTargetOffset
local targetOffsetNext="$mapOffsetResult" local -i targetOffsetNext="$mapOffsetResult"
# Once again, ensure we're in bounds relative to the # Once again, ensure we're in bounds relative to the
# package currently being built. # package currently being built.
@ -447,12 +437,12 @@ findInputs() {
} }
# Make sure all are at least defined as empty # Make sure all are at least defined as empty
: "${depsBuildBuild=}" "${depsBuildBuildPropagated=}" : ${depsBuildBuild=} ${depsBuildBuildPropagated=}
: "${nativeBuildInputs=}" "${propagatedNativeBuildInputs=}" "${defaultNativeBuildInputs=}" : ${nativeBuildInputs=} ${propagatedNativeBuildInputs=} ${defaultNativeBuildInputs=}
: "${depsBuildTarget=}" "${depsBuildTargetPropagated=}" : ${depsBuildTarget=} ${depsBuildTargetPropagated=}
: "${depsHostHost=}" "${depsHostHostPropagated=}" : ${depsHostHost=} ${depsHostHostPropagated=}
: "${buildInputs=}" "${propagatedBuildInputs=}" "${defaultBuildInputs=}" : ${buildInputs=} ${propagatedBuildInputs=} ${defaultBuildInputs=}
: "${depsTargetTarget=}" "${depsTargetTargetPropagated=}" : ${depsTargetTarget=} ${depsTargetTargetPropagated=}
for pkg in $depsBuildBuild $depsBuildBuildPropagated; do for pkg in $depsBuildBuild $depsBuildBuildPropagated; do
findInputs "$pkg" -1 -1 findInputs "$pkg" -1 -1
@ -483,14 +473,13 @@ done
# Add package to the future PATH and run setup hooks # Add package to the future PATH and run setup hooks
activatePackage() { activatePackage() {
local pkg="$1" local pkg="$1"
local -r hostOffset="$2" local -ri hostOffset="$2"
local -r targetOffset="$3" local -ri targetOffset="$3"
# Sanity check # Sanity check
(( "$hostOffset" <= "$targetOffset" )) || exit 1 (( "$hostOffset" <= "$targetOffset" )) || exit -1
if [ -f "$pkg" ]; then if [ -f "$pkg" ]; then
# shellcheck disable=SC1090
source "$pkg" source "$pkg"
fi fi
@ -498,7 +487,7 @@ activatePackage() {
# build platform are included here. That would be `depsBuild*`, # build platform are included here. That would be `depsBuild*`,
# and legacy `nativeBuildInputs`, in general. If we aren't cross # and legacy `nativeBuildInputs`, in general. If we aren't cross
# compiling, however, everything can be put on the PATH. To ease # compiling, however, everything can be put on the PATH. To ease
# the transition, we do include everything in that case. # the transition, we do include everything in thatcase.
# #
# TODO(@Ericson2314): Don't special-case native compilation # TODO(@Ericson2314): Don't special-case native compilation
if [[ -z "${strictDeps-}" || "$hostOffset" -le -1 ]]; then if [[ -z "${strictDeps-}" || "$hostOffset" -le -1 ]]; then
@ -514,19 +503,19 @@ activatePackage() {
fi fi
if [[ -f "$pkg/nix-support/setup-hook" ]]; then if [[ -f "$pkg/nix-support/setup-hook" ]]; then
# shellcheck disable=SC1091
source "$pkg/nix-support/setup-hook" source "$pkg/nix-support/setup-hook"
fi fi
} }
_activatePkgs() { _activatePkgs() {
local hostOffset targetOffset pkg local -i hostOffset targetOffset
local pkg
for hostOffset in "${allPlatOffsets[@]}"; do for hostOffset in "${allPlatOffsets[@]}"; do
local pkgsVar="${pkgAccumVarVars[$(( hostOffset + 1 ))]}" local pkgsVar="${pkgAccumVarVars[$hostOffset + 1]}"
for targetOffset in "${allPlatOffsets[@]}"; do for targetOffset in "${allPlatOffsets[@]}"; do
(( "$hostOffset" <= "$targetOffset" )) || continue (( "$hostOffset" <= "$targetOffset" )) || continue
local pkgsRef="${pkgsVar}[$(( targetOffset - hostOffset ))]" local pkgsRef="${pkgsVar}[$targetOffset - $hostOffset]"
local pkgsSlice="${!pkgsRef}[@]" local pkgsSlice="${!pkgsRef}[@]"
for pkg in ${!pkgsSlice+"${!pkgsSlice}"}; do for pkg in ${!pkgsSlice+"${!pkgsSlice}"}; do
activatePackage "$pkg" "$hostOffset" "$targetOffset" activatePackage "$pkg" "$hostOffset" "$targetOffset"
@ -547,14 +536,15 @@ _activatePkgs
# with this information to the relevant env hook array, but bash # with this information to the relevant env hook array, but bash
# doesn't have closures, so it's easier to just pass this in. # doesn't have closures, so it's easier to just pass this in.
_addToEnv() { _addToEnv() {
local depHostOffset depTargetOffset pkg local -i depHostOffset depTargetOffset
local pkg
for depHostOffset in "${allPlatOffsets[@]}"; do for depHostOffset in "${allPlatOffsets[@]}"; do
local hookVar="${pkgHookVarVars[$(( depHostOffset + 1 ))]}" local hookVar="${pkgHookVarVars[$depHostOffset + 1]}"
local pkgsVar="${pkgAccumVarVars[$(( depHostOffset + 1 ))]}" local pkgsVar="${pkgAccumVarVars[$depHostOffset + 1]}"
for depTargetOffset in "${allPlatOffsets[@]}"; do for depTargetOffset in "${allPlatOffsets[@]}"; do
(( "$depHostOffset" <= "$depTargetOffset" )) || continue (( "$depHostOffset" <= "$depTargetOffset" )) || continue
local hookRef="${hookVar}[$(( depTargetOffset - depHostOffset ))]" local hookRef="${hookVar}[$depTargetOffset - $depHostOffset]"
if [[ -z "${strictDeps-}" ]]; then if [[ -z "${strictDeps-}" ]]; then
# Keep track of which packages we have visited before. # Keep track of which packages we have visited before.
@ -565,12 +555,12 @@ _addToEnv() {
# #
# TODO(@Ericson2314): Don't special-case native compilation # TODO(@Ericson2314): Don't special-case native compilation
for pkg in \ for pkg in \
"${pkgsBuildBuild[@]}" \ ${pkgsBuildBuild+"${pkgsBuildBuild[@]}"} \
"${pkgsBuildHost[@]}" \ ${pkgsBuildHost+"${pkgsBuildHost[@]}"} \
"${pkgsBuildTarget[@]}" \ ${pkgsBuildTarget+"${pkgsBuildTarget[@]}"} \
"${pkgsHostHost[@]}" \ ${pkgsHostHost+"${pkgsHostHost[@]}"} \
"${pkgsHostTarget[@]}" \ ${pkgsHostTarget+"${pkgsHostTarget[@]}"} \
"${pkgsTargetTarget[@]}" ${pkgsTargetTarget+"${pkgsTargetTarget[@]}"}
do do
if [[ "$visitedPkgs" = *"$pkg"* ]]; then if [[ "$visitedPkgs" = *"$pkg"* ]]; then
continue continue
@ -579,7 +569,7 @@ _addToEnv() {
visitedPkgs+=" $pkg" visitedPkgs+=" $pkg"
done done
else else
local pkgsRef="${pkgsVar}[$(( depTargetOffset - depHostOffset ))]" local pkgsRef="${pkgsVar}[$depTargetOffset - $depHostOffset]"
local pkgsSlice="${!pkgsRef}[@]" local pkgsSlice="${!pkgsRef}[@]"
for pkg in ${!pkgsSlice+"${!pkgsSlice}"}; do for pkg in ${!pkgsSlice+"${!pkgsSlice}"}; do
runHook "${!hookRef}" "$pkg" runHook "${!hookRef}" "$pkg"
@ -645,7 +635,7 @@ export NIX_INDENT_MAKE=1
if [ -z "${NIX_BUILD_CORES:-}" ]; then if [ -z "${NIX_BUILD_CORES:-}" ]; then
NIX_BUILD_CORES="1" NIX_BUILD_CORES="1"
elif (( "$NIX_BUILD_CORES" <= 0 )); then elif [ "$NIX_BUILD_CORES" -le 0 ]; then
NIX_BUILD_CORES=$(nproc 2>/dev/null || true) NIX_BUILD_CORES=$(nproc 2>/dev/null || true)
if expr >/dev/null 2>&1 "$NIX_BUILD_CORES" : "^[0-9][0-9]*$"; then if expr >/dev/null 2>&1 "$NIX_BUILD_CORES" : "^[0-9][0-9]*$"; then
: :
@ -658,11 +648,11 @@ export NIX_BUILD_CORES
# Prevent SSL libraries from using certificates in /etc/ssl, unless set explicitly. # Prevent SSL libraries from using certificates in /etc/ssl, unless set explicitly.
# Leave it in impure shells for convenience. # Leave it in impure shells for convenience.
if [[ -z "${NIX_SSL_CERT_FILE:-}" && "${IN_NIX_SHELL:-}" != "impure" ]]; then if [ -z "${NIX_SSL_CERT_FILE:-}" ] && [ "${IN_NIX_SHELL:-}" != "impure" ]; then
export NIX_SSL_CERT_FILE=/no-cert-file.crt export NIX_SSL_CERT_FILE=/no-cert-file.crt
fi fi
# Another variant left for compatibility. # Another variant left for compatibility.
if [[ -z "${SSL_CERT_FILE:-}" && "${IN_NIX_SHELL:-}" != "impure" ]]; then if [ -z "${SSL_CERT_FILE:-}" ] && [ "${IN_NIX_SHELL:-}" != "impure" ]; then
export SSL_CERT_FILE=/no-cert-file.crt export SSL_CERT_FILE=/no-cert-file.crt
fi fi
@ -728,7 +718,6 @@ substituteStream() {
consumeEntire() { consumeEntire() {
# read returns non-0 on EOF, so we want read to fail # read returns non-0 on EOF, so we want read to fail
# shellcheck disable=SC2086
if IFS='' read -r -N 0 $1; then if IFS='' read -r -N 0 $1; then
echo "consumeEntire(): ERROR: Input null bytes, won't process" >&2 echo "consumeEntire(): ERROR: Input null bytes, won't process" >&2
return 1 return 1
@ -900,7 +889,7 @@ unpackPhase() {
# Find the source directory. # Find the source directory.
# set to empty if unset # set to empty if unset
: "${sourceRoot=}" : ${sourceRoot=}
if [ -n "${setSourceRoot:-}" ]; then if [ -n "${setSourceRoot:-}" ]; then
runOneHook setSourceRoot runOneHook setSourceRoot
@ -978,8 +967,8 @@ configurePhase() {
runHook preConfigure runHook preConfigure
# set to empty if unset # set to empty if unset
: "${configureScript=}" : ${configureScript=}
: "${configureFlags=}" : ${configureFlags=}
if [[ -z "$configureScript" && -x ./configure ]]; then if [[ -z "$configureScript" && -x ./configure ]]; then
configureScript=./configure configureScript=./configure
@ -997,27 +986,25 @@ configurePhase() {
configureFlags="${prefixKey:---prefix=}$prefix $configureFlags" configureFlags="${prefixKey:---prefix=}$prefix $configureFlags"
fi fi
if [ -f "$configureScript" ]; then # Add --disable-dependency-tracking to speed up some builds.
# Add --disable-dependency-tracking to speed up some builds. if [ -z "${dontAddDisableDepTrack:-}" ]; then
if [[ -z ${dontAddDisableDepTrack:-} ]]; then if [ -f "$configureScript" ] && grep -q dependency-tracking "$configureScript"; then
if grep -q dependency-tracking "$configureScript"; then configureFlags="--disable-dependency-tracking $configureFlags"
configureFlags="--disable-dependency-tracking $configureFlags"
fi
fi fi
fi
# By default, disable static builds. # By default, disable static builds.
if [[ -z ${dontDisableStatic:-} ]]; then if [ -z "${dontDisableStatic:-}" ]; then
if grep -q enable-static "$configureScript"; then if [ -f "$configureScript" ] && grep -q enable-static "$configureScript"; then
configureFlags="--disable-static $configureFlags" configureFlags="--disable-static $configureFlags"
fi
fi fi
fi fi
if [ -n "$configureScript" ]; then if [ -n "$configureScript" ]; then
IFS=" " read -r -a configureFlagsTemp <<< "$configureFlags" # Old bash empty array hack
local -a flagsArray=( # shellcheck disable=SC2086
"${configureFlagsTemp[@]}" local flagsArray=(
"${configureFlagsArray[@]}" $configureFlags ${configureFlagsArray+"${configureFlagsArray[@]}"}
) )
echoCmd 'configure flags' "${flagsArray[@]}" echoCmd 'configure flags' "${flagsArray[@]}"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
@ -1035,22 +1022,20 @@ buildPhase() {
runHook preBuild runHook preBuild
# set to empty if unset # set to empty if unset
: "${makeFlags=}" : ${makeFlags=}
if [[ -z "$makeFlags" && -z "${makefile:-}" && ! ( -e Makefile || -e makefile || -e GNUmakefile ) ]]; then if [[ -z "$makeFlags" && -z "${makefile:-}" && ! ( -e Makefile || -e makefile || -e GNUmakefile ) ]]; then
echo "no Makefile, doing nothing" echo "no Makefile, doing nothing"
else else
foundMakefile=1 foundMakefile=1
IFS=" " read -r -a makeFlagsTemp <<< "$makeFlags"
# shellcheck disable=SC2154 # Old bash empty array hack
IFS=" " read -r -a buildFlagsTemp <<< "$buildFlags" # shellcheck disable=SC2086
local -a flagsArray=( local flagsArray=(
${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}}
SHELL="$SHELL" SHELL=$SHELL
"${makeFlagsTemp[@]}" $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
"${makeFlagsArray[@]}" $buildFlags ${buildFlagsArray+"${buildFlagsArray[@]}"}
"${buildFlagsTemp[@]}"
"${buildFlagsArray[@]}"
) )
echoCmd 'build flags' "${flagsArray[@]}" echoCmd 'build flags' "${flagsArray[@]}"
@ -1074,26 +1059,23 @@ checkPhase() {
if [[ -z "${checkTarget:-}" ]]; then if [[ -z "${checkTarget:-}" ]]; then
#TODO(@oxij): should flagsArray influence make -n? #TODO(@oxij): should flagsArray influence make -n?
if make -n ${makefile:+-f $makefile} check >/dev/null 2>&1; then if make -n ${makefile:+-f $makefile} check >/dev/null 2>&1; then
checkTarget="check" checkTarget=check
elif make -n ${makefile:+-f $makefile} test >/dev/null 2>&1; then elif make -n ${makefile:+-f $makefile} test >/dev/null 2>&1; then
checkTarget="test" checkTarget=test
fi fi
fi fi
if [[ -z "${checkTarget:-}" ]]; then if [[ -z "${checkTarget:-}" ]]; then
echo "no check/test target in ${makefile:-Makefile}, doing nothing" echo "no check/test target in ${makefile:-Makefile}, doing nothing"
else else
IFS=" " read -r -a makeFlagsTemp <<< "$makeFlags" # Old bash empty array hack
IFS=" " read -r -a checkFlagsTemp <<< "${checkFlags:-VERBOSE=y}" # shellcheck disable=SC2086
IFS=" " read -r -a checkTargetTemp <<< "${checkTarget}" local flagsArray=(
local -a flagsArray=(
${enableParallelChecking:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} ${enableParallelChecking:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}}
SHELL="$SHELL" SHELL=$SHELL
"${makeFlagsTemp[@]}" $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
"${makeFlagsArray[@]}" ${checkFlags:-VERBOSE=y} ${checkFlagsArray+"${checkFlagsArray[@]}"}
"${checkFlagsTemp[@]}" ${checkTarget}
"${checkFlagsArray[@]}"
"${checkTargetTemp[@]}"
) )
echoCmd 'check flags' "${flagsArray[@]}" echoCmd 'check flags' "${flagsArray[@]}"
@ -1112,18 +1094,14 @@ installPhase() {
if [ -n "$prefix" ]; then if [ -n "$prefix" ]; then
mkdir -p "$prefix" mkdir -p "$prefix"
fi fi
IFS=" " read -r -a makeFlagsTemp <<< "$makeFlags"
# shellcheck disable=SC2154 # Old bash empty array hack
IFS=" " read -r -a installFlagsTemp <<< "$installFlags" # shellcheck disable=SC2086
# shellcheck disable=SC2154 local flagsArray=(
IFS=" " read -r -a installTargetsTemp <<< "${installTargets:-install}" SHELL=$SHELL
local -a flagsArray=( $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
SHELL="$SHELL" $installFlags ${installFlagsArray+"${installFlagsArray[@]}"}
"${makeFlagsTemp[@]}" ${installTargets:-install}
"${makeFlagsArray[@]}"
"${installFlagsTemp[@]}"
"${installFlagsArray[@]}"
"${installTargetsTemp[@]}"
) )
echoCmd 'install flags' "${flagsArray[@]}" echoCmd 'install flags' "${flagsArray[@]}"
@ -1178,7 +1156,6 @@ fixupPhase() {
[[ "${!propagatedInputsSlice}" ]] || continue [[ "${!propagatedInputsSlice}" ]] || continue
# shellcheck disable=SC2154
mkdir -p "${!outputDev}/nix-support" mkdir -p "${!outputDev}/nix-support"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
printWords ${!propagatedInputsSlice} > "${!outputDev}/nix-support/$propagatedInputsFile" printWords ${!propagatedInputsSlice} > "${!outputDev}/nix-support/$propagatedInputsFile"
@ -1195,8 +1172,6 @@ fixupPhase() {
mkdir -p "${!outputDev}/nix-support" mkdir -p "${!outputDev}/nix-support"
local hook local hook
for hook in $setupHooks; do for hook in $setupHooks; do
# content is being assigned to in the following lines
# shellcheck disable=SC2034
local content local content
consumeEntire content < "$hook" consumeEntire content < "$hook"
substituteAllStream content "file '$hook'" >> "${!outputDev}/nix-support/setup-hook" substituteAllStream content "file '$hook'" >> "${!outputDev}/nix-support/setup-hook"
@ -1208,7 +1183,6 @@ fixupPhase() {
# Propagate user-env packages into the output with binaries, TODO? # Propagate user-env packages into the output with binaries, TODO?
if [ -n "${propagatedUserEnvPkgs:-}" ]; then if [ -n "${propagatedUserEnvPkgs:-}" ]; then
# shellcheck disable=SC2154
mkdir -p "${!outputBin}/nix-support" mkdir -p "${!outputBin}/nix-support"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
printWords $propagatedUserEnvPkgs > "${!outputBin}/nix-support/propagated-user-env-packages" printWords $propagatedUserEnvPkgs > "${!outputBin}/nix-support/propagated-user-env-packages"
@ -1225,21 +1199,17 @@ installCheckPhase() {
echo "no Makefile or custom installCheckPhase, doing nothing" echo "no Makefile or custom installCheckPhase, doing nothing"
#TODO(@oxij): should flagsArray influence make -n? #TODO(@oxij): should flagsArray influence make -n?
elif [[ -z "${installCheckTarget:-}" ]] \ elif [[ -z "${installCheckTarget:-}" ]] \
&& ! make -n ${makefile:+-f $makefile} "${installCheckTarget:-installcheck}" >/dev/null 2>&1; then && ! make -n ${makefile:+-f $makefile} ${installCheckTarget:-installcheck} >/dev/null 2>&1; then
echo "no installcheck target in ${makefile:-Makefile}, doing nothing" echo "no installcheck target in ${makefile:-Makefile}, doing nothing"
else else
IFS=" " read -r -a makeFlagsTemp <<< "$makeFlags" # Old bash empty array hack
# shellcheck disable=SC2154 # shellcheck disable=SC2086
IFS=" " read -r -a installCheckFlagsTemp <<< "$installCheckFlags" local flagsArray=(
IFS=" " read -r -a installCheckTargetTemp <<< "${installCheckTarget:-installcheck}"
local -a flagsArray=(
${enableParallelChecking:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} ${enableParallelChecking:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}}
SHELL="$SHELL" SHELL=$SHELL
"${makeFlagsTemp[@]}" $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
"${makeFlagsArray[@]}" $installCheckFlags ${installCheckFlagsArray+"${installCheckFlagsArray[@]}"}
"${installCheckFlagsTemp[@]}" ${installCheckTarget:-installcheck}
"${installCheckFlagsArray[@]}"
"${installCheckTargetTemp[@]}"
) )
echoCmd 'installcheck flags' "${flagsArray[@]}" echoCmd 'installcheck flags' "${flagsArray[@]}"
@ -1254,13 +1224,10 @@ installCheckPhase() {
distPhase() { distPhase() {
runHook preDist runHook preDist
# shellcheck disable=SC2154 # Old bash empty array hack
IFS=" " read -r -a distFlagsTemp <<< "$distFlags" # shellcheck disable=SC2086
local flagsArray=( local flagsArray=(
"${distFlagsTemp[@]}" $distFlags ${distFlagsArray+"${distFlagsArray[@]}"} ${distTarget:-dist}
${distFlagsArray+"${distFlagsArray[@]}"}
"${distTarget:-dist}"
) )
echo 'dist flags: %q' "${flagsArray[@]}" echo 'dist flags: %q' "${flagsArray[@]}"
@ -1297,7 +1264,6 @@ showPhaseHeader() {
genericBuild() { genericBuild() {
if [ -f "${buildCommandPath:-}" ]; then if [ -f "${buildCommandPath:-}" ]; then
# shellcheck disable=SC1090
source "$buildCommandPath" source "$buildCommandPath"
return return
fi fi
@ -1325,7 +1291,7 @@ genericBuild() {
if [[ "$curPhase" = distPhase && -z "${doDist:-}" ]]; then continue; fi if [[ "$curPhase" = distPhase && -z "${doDist:-}" ]]; then continue; fi
if [[ -n $NIX_LOG_FD ]]; then if [[ -n $NIX_LOG_FD ]]; then
echo "@nix { \"action\": \"setPhase\", \"phase\": \"$curPhase\" }" >&"$NIX_LOG_FD" echo "@nix { \"action\": \"setPhase\", \"phase\": \"$curPhase\" }" >&$NIX_LOG_FD
fi fi
showPhaseHeader "$curPhase" showPhaseHeader "$curPhase"