lib.customisation: uncurry 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 switch to attrset-passing form, to provide some minimal level
of sanity-checking.
This commit is contained in:
Adam Joseph 2023-07-27 20:56:11 -07:00
parent 35abc09040
commit cb13669b00
12 changed files with 62 additions and 52 deletions

View File

@ -279,7 +279,7 @@ rec {
/* 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, extra, f }:
let let
spliced0 = splicePackages { spliced0 = splicePackages {
pkgsBuildBuild = otherSplices.selfBuildBuild; pkgsBuildBuild = otherSplices.selfBuildBuild;
@ -295,13 +295,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

@ -10,11 +10,10 @@ let
extra = _spliced0: { }; extra = _spliced0: { };
in in
makeScopeWithSplicing makeScopeWithSplicing {
(generateSplicesForMkScope "xfce") otherSplices = generateSplicesForMkScope "xfce";
keep inherit keep extra;
extra f = (self:
(self:
let let
inherit (self) callPackage; inherit (self) callPackage;
in in
@ -177,4 +176,5 @@ makeScopeWithSplicing
thunar-bare = self.thunar.override { thunarPlugins = [ ]; }; # added 2019-11-04 thunar-bare = self.thunar.override { thunarPlugins = [ ]; }; # added 2019-11-04
xfce4-hardware-monitor-plugin = throw "xfce.xfce4-hardware-monitor-plugin has been removed: abandoned by upstream and does not build"; # added 2023-01-15 xfce4-hardware-monitor-plugin = throw "xfce.xfce4-hardware-monitor-plugin has been removed: abandoned by upstream and does not build"; # added 2023-01-15
}) });
}

View File

@ -46,11 +46,10 @@ let
overriddenPackages overriddenPackages
overrides overrides
]; ];
in makeScopeWithSplicing in makeScopeWithSplicing {
otherSplices inherit otherSplices keep extra;
keep f = lib.extends extensions luaPackagesFun;
extra })
(lib.extends extensions luaPackagesFun))
{ {
overrides = packageOverrides; overrides = packageOverrides;
lua = self; lua = self;

View File

@ -36,11 +36,10 @@ let
}; };
keep = self: { }; keep = self: { };
extra = spliced0: {}; extra = spliced0: {};
in makeScopeWithSplicing in makeScopeWithSplicing {
otherSplices inherit otherSplices keep extra;
keep f = perlPackagesFun;
extra })
perlPackagesFun)
{ {
perl = self; perl = self;
}; };

View File

@ -60,12 +60,10 @@
overrides overrides
]); ]);
aliases = self: super: lib.optionalAttrs config.allowAliases (import ../../../top-level/python-aliases.nix lib self super); aliases = self: super: lib.optionalAttrs config.allowAliases (import ../../../top-level/python-aliases.nix lib self super);
in makeScopeWithSplicing in makeScopeWithSplicing {
otherSplices inherit otherSplices keep extra;
keep f = lib.extends (lib.composeExtensions aliases extensions) keep;
extra }) {
(lib.extends (lib.composeExtensions aliases extensions) keep))
{
overrides = packageOverrides; overrides = packageOverrides;
python = self; python = self;
}); });

View File

@ -334,4 +334,9 @@ let
overrideScope' = lib.warn "qt5 now uses makeScopeWithSplicing which does not have \"overrideScope'\", use \"overrideScope\"." self.overrideScope; overrideScope' = lib.warn "qt5 now uses makeScopeWithSplicing which does not have \"overrideScope'\", use \"overrideScope\"." self.overrideScope;
}; };
in makeScopeWithSplicing (generateSplicesForMkScope "qt5") (_: {}) (_: {}) addPackages in makeScopeWithSplicing {
otherSplices = generateSplicesForMkScope "qt5";
keep = _: {};
extra = _: {};
f = addPackages;
}

View File

@ -34,4 +34,8 @@ let
}; };
keep = self: { }; keep = self: { };
extra = spliced0: { }; extra = spliced0: { };
in makeScopeWithSplicing (generateSplicesForMkScope "steamPackages") keep extra steamPackagesFun in makeScopeWithSplicing {
otherSplices = generateSplicesForMkScope "steamPackages";
inherit keep extra;
f = steamPackagesFun;
}

View File

@ -66,11 +66,11 @@ let
done done
''; '';
in makeScopeWithSplicing in makeScopeWithSplicing {
(generateSplicesForMkScope "freebsd") otherSplices = generateSplicesForMkScope "freebsd";
(_: {}) keep = _: {};
(_: {}) extra = _: {};
(self: let f = (self: let
inherit (self) mkDerivation; inherit (self) mkDerivation;
in { in {
inherit freebsdSrc; inherit freebsdSrc;
@ -898,4 +898,5 @@ in makeScopeWithSplicing
''; '';
}); });
}) });
}

View File

@ -26,11 +26,11 @@ let
else "no"}" else "no"}"
]; ];
in makeScopeWithSplicing in makeScopeWithSplicing {
(generateSplicesForMkScope "netbsd") otherSplices = generateSplicesForMkScope "netbsd";
(_: {}) keep = _: {};
(_: {}) extra = _: {};
(self: let f = (self: let
inherit (self) mkDerivation; inherit (self) mkDerivation;
in { in {
@ -1011,4 +1011,5 @@ in makeScopeWithSplicing
# END MISCELLANEOUS # END MISCELLANEOUS
# #
}) });
}

View File

@ -27232,11 +27232,11 @@ with pkgs;
generatedPackages = lib.callPackageWith __splicedPackages ../servers/x11/xorg/default.nix { }; generatedPackages = lib.callPackageWith __splicedPackages ../servers/x11/xorg/default.nix { };
xorgPackages = makeScopeWithSplicing xorgPackages = makeScopeWithSplicing {
(generateSplicesForMkScope "xorg") otherSplices = generateSplicesForMkScope "xorg";
keep inherit keep extra;
extra f = lib.extends overrides generatedPackages;
(lib.extends overrides generatedPackages); };
in recurseIntoAttrs xorgPackages; in recurseIntoAttrs xorgPackages;

View File

@ -15,7 +15,11 @@ let
(stdenv.targetPlatform.config + "-"); (stdenv.targetPlatform.config + "-");
in in
makeScopeWithSplicing (generateSplicesForMkScope "darwin") (_: {}) (spliced: spliced.apple_sdk.frameworks) (self: let makeScopeWithSplicing {
otherSplices = generateSplicesForMkScope "darwin";
keep = _: {};
extra = spliced: spliced.apple_sdk.frameworks;
f = (self: let
inherit (self) mkDerivation callPackage; inherit (self) mkDerivation callPackage;
# Must use pkgs.callPackage to avoid infinite recursion. # Must use pkgs.callPackage to avoid infinite recursion.
@ -251,4 +255,5 @@ impure-cmds // appleSourcePackages // chooseLibs // {
} // lib.optionalAttrs config.allowAliases { } // lib.optionalAttrs config.allowAliases {
builder = throw "'darwin.builder' has been changed and renamed to 'darwin.linux-builder'. The default ssh port is now 31022. Please update your configuration or override the port back to 22. See https://nixos.org/manual/nixpkgs/unstable/#sec-darwin-builder"; # added 2023-07-06 builder = throw "'darwin.builder' has been changed and renamed to 'darwin.linux-builder'. The default ssh port is now 31022. Please update your configuration or override the port back to 22. See https://nixos.org/manual/nixpkgs/unstable/#sec-darwin-builder"; # added 2023-07-06
}) });
}

View File

@ -144,7 +144,7 @@ in
newScope = extra: lib.callPackageWith (splicedPackagesWithXorg // extra); newScope = extra: lib.callPackageWith (splicedPackagesWithXorg // extra);
# 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 { inherit splicePackages; inherit (pkgs) newScope; };
# generate 'otherSplices' for 'makeScopeWithSplicing' # generate 'otherSplices' for 'makeScopeWithSplicing'
generateSplicesForMkScope = attr: generateSplicesForMkScope = attr: