Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib.customisation: uncurry makeScopeWithSplicing #245824

Merged
2 commits merged into from Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions lib/customisation.nix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/lib/customisation.nix b/lib/customisation.nix
index a46913dc5bde..4dfe75023b96 100644
--- a/lib/customisation.nix
+++ b/lib/customisation.nix
@@ -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;
@@ -296,8 +296,7 @@ rec {
         # N.B. the other stages of the package set spliced in are *not*
         # overridden.
         overrideScope = g: (makeScopeWithSplicing
-          { inherit splicePackages newScope; }
-          { inherit otherSplices keep extra;
+          { inherit splicePackages newScope otherSplices keep extra;
             f = lib.fixedPoints.extends g f;
           });
         packages = f;
diff --git a/pkgs/top-level/splice.nix b/pkgs/top-level/splice.nix
index 57cedb12a2f5..01407c107a16 100644
--- a/pkgs/top-level/splice.nix
+++ b/pkgs/top-level/splice.nix
@@ -144,7 +144,7 @@ in
   newScope = extra: lib.callPackageWith (splicedPackagesWithXorg // extra);
 
   # prefill 2 fields of the function for convenience
-  makeScopeWithSplicing = lib.makeScopeWithSplicing { inherit splicePackages; inherit (pkgs) newScope; };
+  makeScopeWithSplicing = a: lib.makeScopeWithSplicing ({ inherit splicePackages; inherit (pkgs) newScope; } // a);
 
   # generate 'otherSplices' for 'makeScopeWithSplicing'
   generateSplicesForMkScope = attr:

Alternative which would not require 2 input sets, which looks nicer if lib.makeScopeWithSplicing is used directly, IMO.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functionArgs won't work on pkgs.makeScopeWithSplicing though

Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,15 @@ 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 ? (_self: {})
, extra ? (_spliced0: {})
, f
}:
let
spliced0 = splicePackages {
pkgsBuildBuild = otherSplices.selfBuildBuild;
Expand All @@ -295,13 +303,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;
Expand Down
16 changes: 5 additions & 11 deletions pkgs/desktops/xfce/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@
, makeScopeWithSplicing
}:

let
keep = _self: { };
extra = _spliced0: { };

in
makeScopeWithSplicing
(generateSplicesForMkScope "xfce")
keep
extra
(self:
makeScopeWithSplicing {
otherSplices = generateSplicesForMkScope "xfce";
f = (self:
let
inherit (self) callPackage;
in
Expand Down Expand Up @@ -177,4 +170,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
})
});
}
11 changes: 4 additions & 7 deletions pkgs/development/interpreters/lua-5/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,15 @@ let
selfHostHost = luaOnHostForHost.pkgs;
selfTargetTarget = luaOnTargetForTarget.pkgs or {};
};
keep = self: { };
extra = spliced0: {};
extensions = lib.composeManyExtensions [
generatedPackages
overriddenPackages
overrides
];
in makeScopeWithSplicing
otherSplices
keep
extra
(lib.extends extensions luaPackagesFun))
in makeScopeWithSplicing {
inherit otherSplices;
f = lib.extends extensions luaPackagesFun;
})
{
overrides = packageOverrides;
lua = self;
Expand Down
11 changes: 4 additions & 7 deletions pkgs/development/interpreters/perl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ let
selfHostHost = perlOnHostForHost.pkgs;
selfTargetTarget = perlOnTargetForTarget.pkgs or {};
};
keep = self: { };
extra = spliced0: {};
in makeScopeWithSplicing
otherSplices
keep
extra
perlPackagesFun)
in makeScopeWithSplicing {
inherit otherSplices;
f = perlPackagesFun;
})
{
perl = self;
};
Expand Down
11 changes: 4 additions & 7 deletions pkgs/development/interpreters/python/passthrufun.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
};
hooks = import ./hooks/default.nix;
keep = lib.extends hooks pythonPackagesFun;
extra = _: {};
optionalExtensions = cond: as: lib.optionals cond as;
pythonExtension = import ../../../top-level/python-packages.nix;
python2Extension = import ../../../top-level/python2-packages.nix;
Expand All @@ -60,12 +59,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;
f = lib.extends (lib.composeExtensions aliases extensions) keep;
}) {
overrides = packageOverrides;
python = self;
});
Expand Down
5 changes: 4 additions & 1 deletion pkgs/development/libraries/qt-5/5.15/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,7 @@ 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";
f = addPackages;
}
7 changes: 4 additions & 3 deletions pkgs/games/steam/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ let

steamcmd = callPackage ./steamcmd.nix { };
};
keep = self: { };
extra = spliced0: { };
in makeScopeWithSplicing (generateSplicesForMkScope "steamPackages") keep extra steamPackagesFun
in makeScopeWithSplicing {
otherSplices = generateSplicesForMkScope "steamPackages";
f = steamPackagesFun;
}
11 changes: 5 additions & 6 deletions pkgs/os-specific/bsd/freebsd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ let
done
'';

in makeScopeWithSplicing
(generateSplicesForMkScope "freebsd")
(_: {})
(_: {})
(self: let
in makeScopeWithSplicing {
otherSplices = generateSplicesForMkScope "freebsd";
f = (self: let
inherit (self) mkDerivation;
in {
inherit freebsdSrc;
Expand Down Expand Up @@ -898,4 +896,5 @@ in makeScopeWithSplicing
'';
});

})
});
}
11 changes: 5 additions & 6 deletions pkgs/os-specific/bsd/netbsd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ let
else "no"}"
];

in makeScopeWithSplicing
(generateSplicesForMkScope "netbsd")
(_: {})
(_: {})
(self: let
in makeScopeWithSplicing {
otherSplices = generateSplicesForMkScope "netbsd";
f = (self: let
inherit (self) mkDerivation;
in {

Expand Down Expand Up @@ -1011,4 +1009,5 @@ in makeScopeWithSplicing
# END MISCELLANEOUS
#

})
});
}
12 changes: 4 additions & 8 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27215,9 +27215,6 @@ with pkgs;
};

xorg = let
keep = _self: { };
extra = _spliced0: { };

# Use `lib.callPackageWith __splicedPackages` rather than plain `callPackage`
# so as not to have the newly bound xorg items already in scope, which would
# have created a cycle.
Expand All @@ -27232,11 +27229,10 @@ 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";
f = lib.extends overrides generatedPackages;
};

in recurseIntoAttrs xorgPackages;

Expand Down
8 changes: 6 additions & 2 deletions pkgs/top-level/darwin-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ let
(stdenv.targetPlatform.config + "-");
in

makeScopeWithSplicing (generateSplicesForMkScope "darwin") (_: {}) (spliced: spliced.apple_sdk.frameworks) (self: let
makeScopeWithSplicing {
otherSplices = generateSplicesForMkScope "darwin";
extra = spliced: spliced.apple_sdk.frameworks;
f = (self: let
inherit (self) mkDerivation callPackage;

# Must use pkgs.callPackage to avoid infinite recursion.
Expand Down Expand Up @@ -251,4 +254,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
})
});
}
2 changes: 1 addition & 1 deletion pkgs/top-level/splice.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down