mkDerivation: Don't pass buildInputs to stdenv builder in nativeBuildInputs

When not cross compiling, nativeBuildInputs and buildInputs have
identical behaviour. Currently that is implemented by having
mkDerivation do a concatenation of those variables in Nix code and pass
that to the builder via the nativeBuildInputs attribute.

However, that has some annoying side effects, like `foo.buildInputs`
evaluating to `[ ]` even if buildInputs were specified in the nix
expression for foo.

Instead, pass buildInputs and nativeBuildInputs in separate variables as
usual, and move the logic of cross compilation vs. native compilation to
the stdenv builder script. This is probably a tiny bit uglier but
fixes the previous problem.

Issue #4855.
This commit is contained in:
Tuomas Tynkkynen 2017-03-01 16:09:18 +02:00
parent 64d4bfd139
commit ce56c99edc
2 changed files with 41 additions and 20 deletions

View File

@ -264,18 +264,16 @@ let
__ignoreNulls = true;
# Inputs built by the cross compiler.
buildInputs = if crossConfig != null then buildInputs' else [];
propagatedBuildInputs = if crossConfig != null then propagatedBuildInputs' else [];
buildInputs = buildInputs';
propagatedBuildInputs = propagatedBuildInputs';
# Inputs built by the usual native compiler.
nativeBuildInputs = nativeBuildInputs'
++ lib.optionals (crossConfig == null) buildInputs'
++ lib.optional
(result.isCygwin
|| (crossConfig != null && lib.hasSuffix "mingw32" crossConfig))
../../build-support/setup-hooks/win-dll-link.sh
;
propagatedNativeBuildInputs = propagatedNativeBuildInputs' ++
(if crossConfig == null then propagatedBuildInputs' else []);
propagatedNativeBuildInputs = propagatedNativeBuildInputs';
} // ifDarwin {
# TODO: remove lib.unique once nix has a list canonicalization primitive
__sandboxProfile =

View File

@ -290,15 +290,26 @@ findInputs() {
fi
}
crossPkgs=""
for i in $buildInputs $defaultBuildInputs $propagatedBuildInputs; do
findInputs $i crossPkgs propagated-build-inputs
done
if [ -z "$crossConfig" ]; then
# Not cross-compiling - both buildInputs (and variants like propagatedBuildInputs)
# are handled identically to nativeBuildInputs
nativePkgs=""
for i in $nativeBuildInputs $buildInputs \
$defaultNativeBuildInputs $defaultBuildInputs \
$propagatedNativeBuildInputs $propagatedBuildInputs; do
findInputs $i nativePkgs propagated-native-build-inputs
done
else
crossPkgs=""
for i in $buildInputs $defaultBuildInputs $propagatedBuildInputs; do
findInputs $i crossPkgs propagated-build-inputs
done
nativePkgs=""
for i in $nativeBuildInputs $defaultNativeBuildInputs $propagatedNativeBuildInputs; do
findInputs $i nativePkgs propagated-native-build-inputs
done
nativePkgs=""
for i in $nativeBuildInputs $defaultNativeBuildInputs $propagatedNativeBuildInputs; do
findInputs $i nativePkgs propagated-native-build-inputs
done
fi
# Set the relevant environment variables to point to the build inputs
@ -759,14 +770,26 @@ fixupPhase() {
# Propagate build inputs and setup hook into the development output.
if [ -n "$propagatedBuildInputs" ]; then
mkdir -p "${!outputDev}/nix-support"
echo "$propagatedBuildInputs" > "${!outputDev}/nix-support/propagated-build-inputs"
fi
if [ -z "$crossConfig" ]; then
# Not cross-compiling - propagatedBuildInputs are handled identically to propagatedNativeBuildInputs
local propagated="$propagatedNativeBuildInputs"
if [ -n "$propagatedBuildInputs" ]; then
propagated+="${propagated:+ }$propagatedBuildInputs"
fi
if [ -n "$propagated" ]; then
mkdir -p "${!outputDev}/nix-support"
echo "$propagated" > "${!outputDev}/nix-support/propagated-native-build-inputs"
fi
else
if [ -n "$propagatedBuildInputs" ]; then
mkdir -p "${!outputDev}/nix-support"
echo "$propagatedBuildInputs" > "${!outputDev}/nix-support/propagated-build-inputs"
fi
if [ -n "$propagatedNativeBuildInputs" ]; then
mkdir -p "${!outputDev}/nix-support"
echo "$propagatedNativeBuildInputs" > "${!outputDev}/nix-support/propagated-native-build-inputs"
if [ -n "$propagatedNativeBuildInputs" ]; then
mkdir -p "${!outputDev}/nix-support"
echo "$propagatedNativeBuildInputs" > "${!outputDev}/nix-support/propagated-native-build-inputs"
fi
fi
if [ -n "$setupHook" ]; then