From a1fdbae706c846f01c31bbe02cb8246fa348b480 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 14 Aug 2023 02:47:59 +0300 Subject: 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). --- lib/customisation.nix | 29 +++++++++++++++++++++-------- lib/default.nix | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/customisation.nix b/lib/customisation.nix index a9281b1ab698a..6dbe8f472f9bb 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -277,9 +277,24 @@ rec { }; 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 hopefully it helps a little bit. */ - makeScopeWithSplicing = splicePackages: newScope: otherSplices: keep: extra: f: + makeScopeWithSplicing' = + { splicePackages + , newScope + }: + { otherSplices + , keep ? (_self: {}) + , extra ? (_spliced0: {}) + , f + }: let spliced0 = splicePackages { pkgsBuildBuild = otherSplices.selfBuildBuild; @@ -295,13 +310,11 @@ rec { callPackage = newScope spliced; # == self.newScope {}; # N.B. the other stages of the package set spliced in are *not* # overridden. - overrideScope = g: makeScopeWithSplicing - splicePackages - newScope - otherSplices - keep - extra - (lib.fixedPoints.extends g f); + overrideScope = g: (makeScopeWithSplicing' + { inherit splicePackages newScope; } + { inherit otherSplices keep extra; + f = lib.fixedPoints.extends g f; + }); packages = f; }; in self; diff --git a/lib/default.nix b/lib/default.nix index 73b8ad8715444..1958d93aaf51d 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -112,7 +112,7 @@ let noDepEntry fullDepEntry packEntry stringAfter; inherit (self.customisation) overrideDerivation makeOverridable callPackageWith callPackagesWith extendDerivation hydraJob - makeScope makeScopeWithSplicing; + makeScope makeScopeWithSplicing makeScopeWithSplicing'; inherit (self.derivations) lazyDerivation; inherit (self.meta) addMetaAttrs dontDistribute setName updateName appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio -- cgit 1.4.1