lib.customisation: add uncurried form of makeScopeWithSplicing

Deeply-curried functions are pretty error-prone in untyped languages
like Nix.  This is a particularly bad case because
`top-level/splice.nix` *also* declares a makeScopeWithSplicing, but
it takes *two fewer arguments*.

Let's add a version that uses attrset-passing form, to provide some
minimal level of sanity-checking.

This also provides defaults for keep and extra (these are often
unneeded by the user).
This commit is contained in:
Adam Joseph 2023-08-14 02:47:59 +03:00 committed by Artturin
parent b5f77af42c
commit a1fdbae706
3 changed files with 23 additions and 9 deletions

View file

@ -277,9 +277,24 @@ rec {
}; };
in self; in self;
/* backward compatibility with old uncurried form; deprecated */
makeScopeWithSplicing =
splicePackages: newScope: otherSplices: keep: extra: f:
makeScopeWithSplicing' {
inherit splicePackages newScope otherSplices keep extra f;
};
/* Like the above, but aims to support cross compilation. It's still ugly, but /* Like the above, but aims to support cross compilation. It's still ugly, but
hopefully it helps a little bit. */ hopefully it helps a little bit. */
makeScopeWithSplicing = splicePackages: newScope: otherSplices: keep: extra: f: makeScopeWithSplicing' =
{ splicePackages
, newScope
}:
{ otherSplices
, keep ? (_self: {})
, extra ? (_spliced0: {})
, f
}:
let let
spliced0 = splicePackages { spliced0 = splicePackages {
pkgsBuildBuild = otherSplices.selfBuildBuild; pkgsBuildBuild = otherSplices.selfBuildBuild;
@ -295,13 +310,11 @@ rec {
callPackage = newScope spliced; # == self.newScope {}; callPackage = newScope spliced; # == self.newScope {};
# N.B. the other stages of the package set spliced in are *not* # N.B. the other stages of the package set spliced in are *not*
# overridden. # overridden.
overrideScope = g: makeScopeWithSplicing overrideScope = g: (makeScopeWithSplicing'
splicePackages { inherit splicePackages newScope; }
newScope { inherit otherSplices keep extra;
otherSplices f = lib.fixedPoints.extends g f;
keep });
extra
(lib.fixedPoints.extends g f);
packages = f; packages = f;
}; };
in self; in self;

View file

@ -112,7 +112,7 @@ let
noDepEntry fullDepEntry packEntry stringAfter; noDepEntry fullDepEntry packEntry stringAfter;
inherit (self.customisation) overrideDerivation makeOverridable inherit (self.customisation) overrideDerivation makeOverridable
callPackageWith callPackagesWith extendDerivation hydraJob callPackageWith callPackagesWith extendDerivation hydraJob
makeScope makeScopeWithSplicing; makeScope makeScopeWithSplicing makeScopeWithSplicing';
inherit (self.derivations) lazyDerivation; inherit (self.derivations) lazyDerivation;
inherit (self.meta) addMetaAttrs dontDistribute setName updateName inherit (self.meta) addMetaAttrs dontDistribute setName updateName
appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio

View file

@ -145,6 +145,7 @@ in
# prefill 2 fields of the function for convenience # prefill 2 fields of the function for convenience
makeScopeWithSplicing = lib.makeScopeWithSplicing splicePackages pkgs.newScope; makeScopeWithSplicing = lib.makeScopeWithSplicing splicePackages pkgs.newScope;
makeScopeWithSplicing' = lib.makeScopeWithSplicing' { inherit splicePackages; inherit (pkgs) newScope; };
# generate 'otherSplices' for 'makeScopeWithSplicing' # generate 'otherSplices' for 'makeScopeWithSplicing'
generateSplicesForMkScope = attr: generateSplicesForMkScope = attr: