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
hopefully it helps a little bit. */
makeScopeWithSplicing = splicePackages: newScope: otherSplices: keep: extra: f:
makeScopeWithSplicing = { splicePackages, newScope }: { otherSplices, keep, extra, f }:
let
spliced0 = splicePackages {
pkgsBuildBuild = otherSplices.selfBuildBuild;
@ -295,13 +295,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;

View File

@ -10,11 +10,10 @@ let
extra = _spliced0: { };
in
makeScopeWithSplicing
(generateSplicesForMkScope "xfce")
keep
extra
(self:
makeScopeWithSplicing {
otherSplices = generateSplicesForMkScope "xfce";
inherit keep extra;
f = (self:
let
inherit (self) callPackage;
in
@ -177,4 +176,5 @@ makeScopeWithSplicing
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
})
});
}

View File

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

View File

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

View File

@ -60,12 +60,10 @@
overrides
]);
aliases = self: super: lib.optionalAttrs config.allowAliases (import ../../../top-level/python-aliases.nix lib self super);
in makeScopeWithSplicing
otherSplices
keep
extra
(lib.extends (lib.composeExtensions aliases extensions) keep))
{
in makeScopeWithSplicing {
inherit otherSplices keep extra;
f = lib.extends (lib.composeExtensions aliases extensions) keep;
}) {
overrides = packageOverrides;
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;
};
in makeScopeWithSplicing (generateSplicesForMkScope "qt5") (_: {}) (_: {}) addPackages
in makeScopeWithSplicing {
otherSplices = generateSplicesForMkScope "qt5";
keep = _: {};
extra = _: {};
f = addPackages;
}

View File

@ -34,4 +34,8 @@ let
};
keep = self: { };
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
'';
in makeScopeWithSplicing
(generateSplicesForMkScope "freebsd")
(_: {})
(_: {})
(self: let
in makeScopeWithSplicing {
otherSplices = generateSplicesForMkScope "freebsd";
keep = _: {};
extra = _: {};
f = (self: let
inherit (self) mkDerivation;
in {
inherit freebsdSrc;
@ -898,4 +898,5 @@ in makeScopeWithSplicing
'';
});
})
});
}

View File

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

View File

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

View File

@ -15,7 +15,11 @@ let
(stdenv.targetPlatform.config + "-");
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;
# Must use pkgs.callPackage to avoid infinite recursion.
@ -251,4 +255,5 @@ impure-cmds // appleSourcePackages // chooseLibs // {
} // 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
})
});
}

View File

@ -144,7 +144,7 @@ in
newScope = extra: lib.callPackageWith (splicedPackagesWithXorg // extra);
# 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'
generateSplicesForMkScope = attr: