Merge pull request #201946 from Artturin/splicingstuff2

lib.overrideDerivation: override attrs in __spliced && splice.nix: start deprecating nativeDrv and crossDrv
This commit is contained in:
Artturi 2022-11-20 15:07:28 +02:00 committed by GitHub
commit 8181233059
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 32 deletions

View file

@ -250,5 +250,5 @@ Thirdly, it is because everything target-mentioning only exists to accommodate c
::: :::
::: {.note} ::: {.note}
If one explores Nixpkgs, they will see derivations with names like `gccCross`. Such `*Cross` derivations is a holdover from before we properly distinguished between the host and target platforms—the derivation with “Cross” in the name covered the `build = host != target` case, while the other covered the `host = target`, with build platform the same or not based on whether one was using its `.nativeDrv` or `.crossDrv`. This ugliness will disappear soon. If one explores Nixpkgs, they will see derivations with names like `gccCross`. Such `*Cross` derivations is a holdover from before we properly distinguished between the host and target platforms—the derivation with “Cross” in the name covered the `build = host != target` case, while the other covered the `host = target`, with build platform the same or not based on whether one was using its `.__spliced.buildHost` or `.__spliced.hostTarget`.
::: :::

View file

@ -38,12 +38,15 @@ rec {
// //
(drv.passthru or {}) (drv.passthru or {})
// //
(if (drv ? crossDrv && drv ? nativeDrv) # TODO(@Artturin): remove before release 23.05 and only have __spliced.
then { (lib.optionalAttrs (drv ? crossDrv && drv ? nativeDrv) {
crossDrv = overrideDerivation drv.crossDrv f; crossDrv = overrideDerivation drv.crossDrv f;
nativeDrv = overrideDerivation drv.nativeDrv f; nativeDrv = overrideDerivation drv.nativeDrv f;
} })
else { })); //
lib.optionalAttrs (drv ? __spliced) {
__spliced = {} // (lib.mapAttrs (_: sDrv: overrideDerivation sDrv f) drv.__spliced);
});
/* `makeOverridable` takes a function from attribute set to attribute set and /* `makeOverridable` takes a function from attribute set to attribute set and

View file

@ -76,7 +76,7 @@ in
nativeBuildInputs = [makeInitrdNGTool cpio] ++ lib.optional makeUInitrd ubootTools ++ lib.optional strip binutils; nativeBuildInputs = [makeInitrdNGTool cpio] ++ lib.optional makeUInitrd ubootTools ++ lib.optional strip binutils;
STRIP = if strip then "${(binutils.nativeDrv or binutils).targetPrefix}strip" else null; STRIP = if strip then "${pkgsBuildHost.binutils.targetPrefix}strip" else null;
}) '' }) ''
mkdir ./root mkdir ./root
make-initrd-ng "$contentsPath" ./root make-initrd-ng "$contentsPath" ./root

View file

@ -1,4 +1,4 @@
{ lib, makeSetupHook, nodejs, srcOnly, diffutils, jq, makeWrapper }: { lib, makeSetupHook, nodejs, srcOnly, buildPackages, makeWrapper }:
{ {
npmConfigHook = makeSetupHook npmConfigHook = makeSetupHook
@ -9,9 +9,8 @@
# Specify the stdenv's `diff` and `jq` by abspath to ensure that the user's build # Specify the stdenv's `diff` and `jq` by abspath to ensure that the user's build
# inputs do not cause us to find the wrong binaries. # inputs do not cause us to find the wrong binaries.
# The `.nativeDrv` stanza works like nativeBuildInputs and ensures cross-compiling has the right version available. diff = "${buildPackages.diffutils}/bin/diff";
diff = "${diffutils.nativeDrv or diffutils}/bin/diff"; jq = "${buildPackages.jq}/bin/jq";
jq = "${jq.nativeDrv or jq}/bin/jq";
nodeVersion = nodejs.version; nodeVersion = nodejs.version;
nodeVersionMajor = lib.versions.major nodejs.version; nodeVersionMajor = lib.versions.major nodejs.version;
@ -29,7 +28,7 @@
deps = [ makeWrapper ]; deps = [ makeWrapper ];
substitutions = { substitutions = {
hostNode = "${nodejs}/bin/node"; hostNode = "${nodejs}/bin/node";
jq = "${jq.nativeDrv or jq}/bin/jq"; jq = "${buildPackages.jq}/bin/jq";
}; };
} ./npm-install-hook.sh; } ./npm-install-hook.sh;
} }

View file

@ -2,7 +2,6 @@
, callPackage , callPackage
, cargo , cargo
, clang , clang
, diffutils
, lib , lib
, makeSetupHook , makeSetupHook
, maturin , maturin
@ -65,8 +64,7 @@ in {
# Specify the stdenv's `diff` by abspath to ensure that the user's build # Specify the stdenv's `diff` by abspath to ensure that the user's build
# inputs do not cause us to find the wrong `diff`. # inputs do not cause us to find the wrong `diff`.
# The `.nativeDrv` stanza works like nativeBuildInputs and ensures cross-compiling has the right version available. diff = "${lib.getBin buildPackages.diffutils}/bin/diff";
diff = "${diffutils.nativeDrv or diffutils}/bin/diff";
# We want to specify the correct crt-static flag for both # We want to specify the correct crt-static flag for both
# the build and host platforms. This is important when the wanted # the build and host platforms. This is important when the wanted

View file

@ -107,6 +107,8 @@ let
} ./hooks/qmake-hook.sh; } ./hooks/qmake-hook.sh;
}; };
# TODO(@Artturin): convert to makeScopeWithSplicing
# simple example of how to do that in 5568a4d25ca406809530420996d57e0876ca1a01
self = lib.makeScope newScope addPackages; self = lib.makeScope newScope addPackages;
in in
self self

View file

@ -61,7 +61,7 @@ stdenv.mkDerivation (args // {
if [[ -z "$dontSyncQt" && -f sync.profile ]]; then if [[ -z "$dontSyncQt" && -f sync.profile ]]; then
# FIXME: this probably breaks crosscompiling as it's not from nativeBuildInputs # FIXME: this probably breaks crosscompiling as it's not from nativeBuildInputs
# I don't know how to get /libexec from nativeBuildInputs to work, it's not under /bin # I don't know how to get /libexec from nativeBuildInputs to work, it's not under /bin
${self.qtbase.dev.nativeDrv or self.qtbase.dev}/libexec/syncqt.pl -version "''${version%%-*}" ${lib.getDev self.qtbase}/libexec/syncqt.pl -version "''${version%%-*}"
fi fi
''; '';

View file

@ -209,7 +209,7 @@ else let
dependencies = map (map lib.chooseDevOutputs) [ dependencies = map (map lib.chooseDevOutputs) [
[ [
(map (drv: drv.__spliced.buildBuild or drv) (checkDependencyList "depsBuildBuild" depsBuildBuild)) (map (drv: drv.__spliced.buildBuild or drv) (checkDependencyList "depsBuildBuild" depsBuildBuild))
(map (drv: drv.nativeDrv or drv) (checkDependencyList "nativeBuildInputs" nativeBuildInputs (map (drv: drv.__spliced.buildHost or drv) (checkDependencyList "nativeBuildInputs" nativeBuildInputs
++ lib.optional separateDebugInfo' ../../build-support/setup-hooks/separate-debug-info.sh ++ lib.optional separateDebugInfo' ../../build-support/setup-hooks/separate-debug-info.sh
++ lib.optional stdenv.hostPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh ++ lib.optional stdenv.hostPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh
++ lib.optionals doCheck checkInputs ++ lib.optionals doCheck checkInputs
@ -218,7 +218,7 @@ else let
] ]
[ [
(map (drv: drv.__spliced.hostHost or drv) (checkDependencyList "depsHostHost" depsHostHost)) (map (drv: drv.__spliced.hostHost or drv) (checkDependencyList "depsHostHost" depsHostHost))
(map (drv: drv.crossDrv or drv) (checkDependencyList "buildInputs" buildInputs)) (map (drv: drv.__spliced.hostTarget or drv) (checkDependencyList "buildInputs" buildInputs))
] ]
[ [
(map (drv: drv.__spliced.targetTarget or drv) (checkDependencyList "depsTargetTarget" depsTargetTarget)) (map (drv: drv.__spliced.targetTarget or drv) (checkDependencyList "depsTargetTarget" depsTargetTarget))
@ -227,12 +227,12 @@ else let
propagatedDependencies = map (map lib.chooseDevOutputs) [ propagatedDependencies = map (map lib.chooseDevOutputs) [
[ [
(map (drv: drv.__spliced.buildBuild or drv) (checkDependencyList "depsBuildBuildPropagated" depsBuildBuildPropagated)) (map (drv: drv.__spliced.buildBuild or drv) (checkDependencyList "depsBuildBuildPropagated" depsBuildBuildPropagated))
(map (drv: drv.nativeDrv or drv) (checkDependencyList "propagatedNativeBuildInputs" propagatedNativeBuildInputs)) (map (drv: drv.__spliced.buildHost or drv) (checkDependencyList "propagatedNativeBuildInputs" propagatedNativeBuildInputs))
(map (drv: drv.__spliced.buildTarget or drv) (checkDependencyList "depsBuildTargetPropagated" depsBuildTargetPropagated)) (map (drv: drv.__spliced.buildTarget or drv) (checkDependencyList "depsBuildTargetPropagated" depsBuildTargetPropagated))
] ]
[ [
(map (drv: drv.__spliced.hostHost or drv) (checkDependencyList "depsHostHostPropagated" depsHostHostPropagated)) (map (drv: drv.__spliced.hostHost or drv) (checkDependencyList "depsHostHostPropagated" depsHostHostPropagated))
(map (drv: drv.crossDrv or drv) (checkDependencyList "propagatedBuildInputs" propagatedBuildInputs)) (map (drv: drv.__spliced.hostTarget or drv) (checkDependencyList "propagatedBuildInputs" propagatedBuildInputs))
] ]
[ [
(map (drv: drv.__spliced.targetTarget or drv) (checkDependencyList "depsTargetTargetPropagated" depsTargetTargetPropagated)) (map (drv: drv.__spliced.targetTarget or drv) (checkDependencyList "depsTargetTargetPropagated" depsTargetTargetPropagated))

View file

@ -8,16 +8,9 @@
# The solution is to splice the package sets together as we do below, so every # The solution is to splice the package sets together as we do below, so every
# `callPackage`d expression in fact gets both versions. Each# derivation (and # `callPackage`d expression in fact gets both versions. Each# derivation (and
# each derivation's outputs) consists of the run-time version, augmented with a # each derivation's outputs) consists of the run-time version, augmented with a
# `nativeDrv` field for the build-time version, and `crossDrv` field for the # `__spliced.buildHost` field for the build-time version, and `__spliced.hostTarget` field for the
# run-time version. # run-time version.
# #
# We could have used any names we want for the disambiguated versions, but
# `crossDrv` and `nativeDrv` were somewhat similarly used for the old
# cross-compiling infrastructure. The names are mostly invisible as
# `mkDerivation` knows how to pull out the right ones for `buildDepends` and
# friends, but a few packages use them directly, so it seemed efficient (to
# @Ericson2314) to reuse those names, at least initially, to minimize breakage.
#
# For performance reasons, rather than uniformally splice in all cases, we only # For performance reasons, rather than uniformally splice in all cases, we only
# do so when `pkgs` and `buildPackages` are distinct. The `actuallySplice` # do so when `pkgs` and `buildPackages` are distinct. The `actuallySplice`
# parameter there the boolean value of that equality check. # parameter there the boolean value of that equality check.
@ -46,14 +39,16 @@ let
valueHostTarget = pkgsHostTarget.${name} or {}; valueHostTarget = pkgsHostTarget.${name} or {};
valueTargetTarget = pkgsTargetTarget.${name} or {}; valueTargetTarget = pkgsTargetTarget.${name} or {};
augmentedValue = defaultValue augmentedValue = defaultValue
# TODO(@Ericson2314): Stop using old names after transition period # TODO(@Artturin): remove before release 23.05 and only have __spliced.
// (lib.optionalAttrs (pkgsBuildHost ? ${name}) { nativeDrv = valueBuildHost; }) // (lib.optionalAttrs (pkgsBuildHost ? ${name}) { nativeDrv = lib.warn "use ${name}.__spliced.buildHost instead of ${name}.nativeDrv" valueBuildHost; })
// (lib.optionalAttrs (pkgsHostTarget ? ${name}) { crossDrv = valueHostTarget; }) // (lib.optionalAttrs (pkgsHostTarget ? ${name}) { crossDrv = lib.warn "use ${name}.__spliced.hostTarget instead of ${name}.crossDrv" valueHostTarget; })
// { // {
__spliced = __spliced =
(lib.optionalAttrs (pkgsBuildBuild ? ${name}) { buildBuild = valueBuildBuild; }) (lib.optionalAttrs (pkgsBuildBuild ? ${name}) { buildBuild = valueBuildBuild; })
// (lib.optionalAttrs (pkgsBuildHost ? ${name}) { buildHost = valueBuildHost; })
// (lib.optionalAttrs (pkgsBuildTarget ? ${name}) { buildTarget = valueBuildTarget; }) // (lib.optionalAttrs (pkgsBuildTarget ? ${name}) { buildTarget = valueBuildTarget; })
// (lib.optionalAttrs (pkgsHostHost ? ${name}) { hostHost = valueHostHost; }) // (lib.optionalAttrs (pkgsHostHost ? ${name}) { hostHost = valueHostHost; })
// (lib.optionalAttrs (pkgsHostTarget ? ${name}) { hostTarget = valueHostTarget; })
// (lib.optionalAttrs (pkgsTargetTarget ? ${name}) { targetTarget = valueTargetTarget; // (lib.optionalAttrs (pkgsTargetTarget ? ${name}) { targetTarget = valueTargetTarget;
}); });
}; };