stdenv: Simplify dependency code
This is a bit simpler now, but more importantly it scales better when I double the number of sorts of dependencies as part of my cross compilation work.
This commit is contained in:
parent
b0ada07f36
commit
ad8d8fb2f5
@ -126,10 +126,12 @@ let
|
|||||||
# * https://nixos.org/nix/manual/#ssec-derivation
|
# * https://nixos.org/nix/manual/#ssec-derivation
|
||||||
# Explanation about derivations in general
|
# Explanation about derivations in general
|
||||||
mkDerivation =
|
mkDerivation =
|
||||||
{ buildInputs ? []
|
{ nativeBuildInputs ? []
|
||||||
, nativeBuildInputs ? []
|
, buildInputs ? []
|
||||||
, propagatedBuildInputs ? []
|
|
||||||
, propagatedNativeBuildInputs ? []
|
, propagatedNativeBuildInputs ? []
|
||||||
|
, propagatedBuildInputs ? []
|
||||||
|
|
||||||
, crossConfig ? null
|
, crossConfig ? null
|
||||||
, meta ? {}
|
, meta ? {}
|
||||||
, passthru ? {}
|
, passthru ? {}
|
||||||
@ -141,18 +143,15 @@ let
|
|||||||
, sandboxProfile ? ""
|
, sandboxProfile ? ""
|
||||||
, propagatedSandboxProfile ? ""
|
, propagatedSandboxProfile ? ""
|
||||||
, ... } @ attrs:
|
, ... } @ attrs:
|
||||||
let # Rename argumemnts to avoid cycles
|
let
|
||||||
buildInputs__ = buildInputs;
|
dependencies = [
|
||||||
nativeBuildInputs__ = nativeBuildInputs;
|
(map (drv: drv.nativeDrv or drv) nativeBuildInputs)
|
||||||
propagatedBuildInputs__ = propagatedBuildInputs;
|
(map (drv: drv.crossDrv or drv) buildInputs)
|
||||||
propagatedNativeBuildInputs__ = propagatedNativeBuildInputs;
|
];
|
||||||
in let
|
propagatedDependencies = [
|
||||||
getNativeDrv = drv: drv.nativeDrv or drv;
|
(map (drv: drv.nativeDrv or drv) propagatedNativeBuildInputs)
|
||||||
getCrossDrv = drv: drv.crossDrv or drv;
|
(map (drv: drv.crossDrv or drv) propagatedBuildInputs)
|
||||||
nativeBuildInputs = map getNativeDrv nativeBuildInputs__;
|
];
|
||||||
buildInputs = map getCrossDrv buildInputs__;
|
|
||||||
propagatedBuildInputs = map getCrossDrv propagatedBuildInputs__;
|
|
||||||
propagatedNativeBuildInputs = map getNativeDrv propagatedNativeBuildInputs__;
|
|
||||||
in let
|
in let
|
||||||
pos' =
|
pos' =
|
||||||
if pos != null then
|
if pos != null then
|
||||||
@ -281,13 +280,16 @@ let
|
|||||||
outputs ++
|
outputs ++
|
||||||
(if separateDebugInfo then assert targetPlatform.isLinux; [ "debug" ] else []);
|
(if separateDebugInfo then assert targetPlatform.isLinux; [ "debug" ] else []);
|
||||||
|
|
||||||
buildInputs' = lib.chooseDevOutputs buildInputs ++
|
dependencies' = let
|
||||||
(if separateDebugInfo then [ ../../build-support/setup-hooks/separate-debug-info.sh ] else []);
|
justMap = map lib.chooseDevOutputs dependencies;
|
||||||
|
nativeBuildInputs = lib.elemAt justMap 0
|
||||||
nativeBuildInputs' = lib.chooseDevOutputs nativeBuildInputs;
|
++ lib.optional targetPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh;
|
||||||
propagatedBuildInputs' = lib.chooseDevOutputs propagatedBuildInputs;
|
buildInputs = lib.elemAt justMap 1
|
||||||
propagatedNativeBuildInputs' = lib.chooseDevOutputs propagatedNativeBuildInputs;
|
# TODO(@Ericson2314): Should instead also be appended to `nativeBuildInputs`.
|
||||||
|
++ lib.optional separateDebugInfo ../../build-support/setup-hooks/separate-debug-info.sh;
|
||||||
|
in [ nativeBuildInputs buildInputs ];
|
||||||
|
|
||||||
|
propagatedDependencies' = map lib.chooseDevOutputs propagatedDependencies;
|
||||||
in
|
in
|
||||||
|
|
||||||
# Throw an error if trying to evaluate an non-valid derivation
|
# Throw an error if trying to evaluate an non-valid derivation
|
||||||
@ -302,14 +304,15 @@ let
|
|||||||
"__impureHostDeps" "__propagatedImpureHostDeps"
|
"__impureHostDeps" "__propagatedImpureHostDeps"
|
||||||
"sandboxProfile" "propagatedSandboxProfile"])
|
"sandboxProfile" "propagatedSandboxProfile"])
|
||||||
// (let
|
// (let
|
||||||
|
# TODO(@Ericson2314): Reversing of dep lists is just temporary to avoid Darwin mass rebuild.
|
||||||
computedSandboxProfile =
|
computedSandboxProfile =
|
||||||
lib.concatMap (input: input.__propagatedSandboxProfile or []) (extraBuildInputs ++ buildInputs' ++ nativeBuildInputs');
|
lib.concatMap (input: input.__propagatedSandboxProfile or []) (extraBuildInputs ++ lib.concatLists (lib.reverseList dependencies'));
|
||||||
computedPropagatedSandboxProfile =
|
computedPropagatedSandboxProfile =
|
||||||
lib.concatMap (input: input.__propagatedSandboxProfile or []) (propagatedBuildInputs' ++ propagatedNativeBuildInputs');
|
lib.concatMap (input: input.__propagatedSandboxProfile or []) (lib.concatLists (lib.reverseList propagatedDependencies'));
|
||||||
computedImpureHostDeps =
|
computedImpureHostDeps =
|
||||||
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or []) (extraBuildInputs ++ buildInputs' ++ nativeBuildInputs'));
|
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or []) (extraBuildInputs ++ lib.concatLists (lib.reverseList dependencies')));
|
||||||
computedPropagatedImpureHostDeps =
|
computedPropagatedImpureHostDeps =
|
||||||
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or []) (propagatedBuildInputs' ++ propagatedNativeBuildInputs'));
|
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or []) (lib.concatLists (lib.reverseList propagatedDependencies')));
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
builder = attrs.realBuilder or shell;
|
builder = attrs.realBuilder or shell;
|
||||||
@ -319,17 +322,11 @@ let
|
|||||||
userHook = config.stdenv.userHook or null;
|
userHook = config.stdenv.userHook or null;
|
||||||
__ignoreNulls = true;
|
__ignoreNulls = true;
|
||||||
|
|
||||||
# Inputs built by the cross compiler.
|
nativeBuildInputs = lib.elemAt dependencies' 0;
|
||||||
buildInputs = buildInputs';
|
buildInputs = lib.elemAt dependencies' 1;
|
||||||
propagatedBuildInputs = propagatedBuildInputs';
|
|
||||||
# Inputs built by the usual native compiler.
|
propagatedNativeBuildInputs = lib.elemAt propagatedDependencies' 0;
|
||||||
nativeBuildInputs = nativeBuildInputs'
|
propagatedBuildInputs = lib.elemAt propagatedDependencies' 1;
|
||||||
++ lib.optional
|
|
||||||
(hostPlatform.isCygwin
|
|
||||||
|| (crossConfig != null && lib.hasSuffix "mingw32" crossConfig))
|
|
||||||
../../build-support/setup-hooks/win-dll-link.sh
|
|
||||||
;
|
|
||||||
propagatedNativeBuildInputs = propagatedNativeBuildInputs';
|
|
||||||
} // ifDarwin {
|
} // ifDarwin {
|
||||||
# TODO: remove lib.unique once nix has a list canonicalization primitive
|
# TODO: remove lib.unique once nix has a list canonicalization primitive
|
||||||
__sandboxProfile =
|
__sandboxProfile =
|
||||||
|
Loading…
Reference in New Issue
Block a user