pkgs/splice.nix: Refactor, use cross index helpers

This commit is contained in:
Robert Hensing
2025-09-06 16:59:20 +02:00
parent 7ba464154f
commit f8566d22c1

View File

@@ -17,48 +17,30 @@
lib: pkgs: actuallySplice: lib: pkgs: actuallySplice:
let let
inherit (lib.customisation) mapCrossIndex renameCrossIndexFrom;
spliceReal = spliceReal =
{ inputs:
pkgsBuildBuild,
pkgsBuildHost,
pkgsBuildTarget,
pkgsHostHost,
pkgsHostTarget,
pkgsTargetTarget,
}:
let let
mash = mash =
# Other pkgs sets # Other pkgs sets
pkgsBuildBuild inputs.buildBuild
// pkgsBuildTarget // inputs.buildTarget
// pkgsHostHost // inputs.hostHost
// pkgsTargetTarget // inputs.targetTarget
# The same pkgs sets one probably intends # The same pkgs sets one probably intends
// pkgsBuildHost // inputs.buildHost
// pkgsHostTarget; // inputs.hostTarget;
merge = name: { merge = name: {
inherit name; inherit name;
value = value =
let let
defaultValue = mash.${name}; defaultValue = mash.${name};
# `or {}` is for the non-derivation attsert splicing case, where `{}` is the identity. # `or {}` is for the non-derivation attsert splicing case, where `{}` is the identity.
valueBuildBuild = pkgsBuildBuild.${name} or { }; value' = mapCrossIndex (x: x.${name} or { }) inputs;
valueBuildHost = pkgsBuildHost.${name} or { };
valueBuildTarget = pkgsBuildTarget.${name} or { };
valueHostHost = pkgsHostHost.${name} or { };
valueHostTarget = pkgsHostTarget.${name} or { };
valueTargetTarget = pkgsTargetTarget.${name} or { };
augmentedValue = defaultValue // { augmentedValue = defaultValue // {
__spliced = __spliced = lib.filterAttrs (k: v: inputs.${k} ? ${name}) value';
(lib.optionalAttrs (pkgsBuildBuild ? ${name}) { buildBuild = valueBuildBuild; })
// (lib.optionalAttrs (pkgsBuildHost ? ${name}) { buildHost = valueBuildHost; })
// (lib.optionalAttrs (pkgsBuildTarget ? ${name}) { buildTarget = valueBuildTarget; })
// (lib.optionalAttrs (pkgsHostHost ? ${name}) { hostHost = valueHostHost; })
// (lib.optionalAttrs (pkgsHostTarget ? ${name}) { hostTarget = valueHostTarget; })
// (lib.optionalAttrs (pkgsTargetTarget ? ${name}) {
targetTarget = valueTargetTarget;
});
}; };
# Get the set of outputs of a derivation. If one derivation fails to # Get the set of outputs of a derivation. If one derivation fails to
# evaluate we don't want to diverge the entire splice, so we fall back # evaluate we don't want to diverge the entire splice, so we fall back
@@ -76,27 +58,12 @@ let
# on to splice them together. # on to splice them together.
if lib.isDerivation defaultValue then if lib.isDerivation defaultValue then
augmentedValue augmentedValue
// spliceReal { // spliceReal (mapCrossIndex tryGetOutputs value' // { hostTarget = getOutputs value'.hostTarget; })
pkgsBuildBuild = tryGetOutputs valueBuildBuild;
pkgsBuildHost = tryGetOutputs valueBuildHost;
pkgsBuildTarget = tryGetOutputs valueBuildTarget;
pkgsHostHost = tryGetOutputs valueHostHost;
pkgsHostTarget = getOutputs valueHostTarget;
pkgsTargetTarget = tryGetOutputs valueTargetTarget;
# Just recur on plain attrsets
}
else if lib.isAttrs defaultValue then else if lib.isAttrs defaultValue then
spliceReal { spliceReal value'
pkgsBuildBuild = valueBuildBuild;
pkgsBuildHost = valueBuildHost;
pkgsBuildTarget = valueBuildTarget;
pkgsHostHost = valueHostHost;
pkgsHostTarget = valueHostTarget;
pkgsTargetTarget = valueTargetTarget;
# Don't be fancy about non-derivations. But we could have used used
# `__functor__` for functions instead.
}
else else
# Don't be fancy about non-derivations. But we could have used used
# `__functor__` for functions instead.
defaultValue; defaultValue;
}; };
in in
@@ -111,7 +78,7 @@ let
pkgsHostTarget, pkgsHostTarget,
pkgsTargetTarget, pkgsTargetTarget,
}@args: }@args:
if actuallySplice then spliceReal args else pkgsHostTarget; if actuallySplice then spliceReal (renameCrossIndexFrom "pkgs" args) else pkgsHostTarget;
splicedPackages = splicedPackages =
splicePackages { splicePackages {