From cb13669b0049e795c3421987fe9367d82a0525b1 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Thu, 27 Jul 2023 20:56:11 -0700 Subject: [PATCH 1/2] 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. --- lib/customisation.nix | 14 ++++++-------- pkgs/desktops/xfce/default.nix | 12 ++++++------ pkgs/development/interpreters/lua-5/default.nix | 9 ++++----- pkgs/development/interpreters/perl/default.nix | 9 ++++----- .../interpreters/python/passthrufun.nix | 10 ++++------ pkgs/development/libraries/qt-5/5.15/default.nix | 7 ++++++- pkgs/games/steam/default.nix | 6 +++++- pkgs/os-specific/bsd/freebsd/default.nix | 13 +++++++------ pkgs/os-specific/bsd/netbsd/default.nix | 13 +++++++------ pkgs/top-level/all-packages.nix | 10 +++++----- pkgs/top-level/darwin-packages.nix | 9 +++++++-- pkgs/top-level/splice.nix | 2 +- 12 files changed, 62 insertions(+), 52 deletions(-) diff --git a/lib/customisation.nix b/lib/customisation.nix index a9281b1ab698a..a46913dc5bde7 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; @@ -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; diff --git a/pkgs/desktops/xfce/default.nix b/pkgs/desktops/xfce/default.nix index 5dc21338a72cb..41de05a41de30 100644 --- a/pkgs/desktops/xfce/default.nix +++ b/pkgs/desktops/xfce/default.nix @@ -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 - }) + }); +} diff --git a/pkgs/development/interpreters/lua-5/default.nix b/pkgs/development/interpreters/lua-5/default.nix index f4c622515d7d9..b0c6182caddd2 100644 --- a/pkgs/development/interpreters/lua-5/default.nix +++ b/pkgs/development/interpreters/lua-5/default.nix @@ -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; diff --git a/pkgs/development/interpreters/perl/default.nix b/pkgs/development/interpreters/perl/default.nix index 3c57d8a2b6900..6eb439ea4a9e2 100644 --- a/pkgs/development/interpreters/perl/default.nix +++ b/pkgs/development/interpreters/perl/default.nix @@ -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; }; diff --git a/pkgs/development/interpreters/python/passthrufun.nix b/pkgs/development/interpreters/python/passthrufun.nix index aa63f354e085d..a4a04164ef314 100644 --- a/pkgs/development/interpreters/python/passthrufun.nix +++ b/pkgs/development/interpreters/python/passthrufun.nix @@ -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; }); diff --git a/pkgs/development/libraries/qt-5/5.15/default.nix b/pkgs/development/libraries/qt-5/5.15/default.nix index 5f82900903835..4531066438375 100644 --- a/pkgs/development/libraries/qt-5/5.15/default.nix +++ b/pkgs/development/libraries/qt-5/5.15/default.nix @@ -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; +} diff --git a/pkgs/games/steam/default.nix b/pkgs/games/steam/default.nix index 370f22268a9ab..ebd0570d351a0 100644 --- a/pkgs/games/steam/default.nix +++ b/pkgs/games/steam/default.nix @@ -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; +} diff --git a/pkgs/os-specific/bsd/freebsd/default.nix b/pkgs/os-specific/bsd/freebsd/default.nix index 136c9721c6bbb..e68b4ef87b3d2 100644 --- a/pkgs/os-specific/bsd/freebsd/default.nix +++ b/pkgs/os-specific/bsd/freebsd/default.nix @@ -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 ''; }); -}) +}); +} diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix index 6bf884d382840..6782bbf9df616 100644 --- a/pkgs/os-specific/bsd/netbsd/default.nix +++ b/pkgs/os-specific/bsd/netbsd/default.nix @@ -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 # -}) +}); +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f396085da5adb..6047098baed07 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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; diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index ef4240955b9c6..55f908db9806f 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -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 -}) +}); +} diff --git a/pkgs/top-level/splice.nix b/pkgs/top-level/splice.nix index 0a138947e8da1..57cedb12a2f54 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 splicePackages pkgs.newScope; + makeScopeWithSplicing = lib.makeScopeWithSplicing { inherit splicePackages; inherit (pkgs) newScope; }; # generate 'otherSplices' for 'makeScopeWithSplicing' generateSplicesForMkScope = attr: From 3716ef19d837998c35cc102c80ad800d26517d7e Mon Sep 17 00:00:00 2001 From: Artturin Date: Fri, 28 Jul 2023 17:06:35 +0300 Subject: [PATCH 2/2] lib.makeScopeWithSplicing: provide default for keep,extra These are often unneeded by the user. --- lib/customisation.nix | 10 +++++++++- pkgs/desktops/xfce/default.nix | 6 ------ pkgs/development/interpreters/lua-5/default.nix | 4 +--- pkgs/development/interpreters/perl/default.nix | 4 +--- pkgs/development/interpreters/python/passthrufun.nix | 3 +-- pkgs/development/libraries/qt-5/5.15/default.nix | 2 -- pkgs/games/steam/default.nix | 3 --- pkgs/os-specific/bsd/freebsd/default.nix | 2 -- pkgs/os-specific/bsd/netbsd/default.nix | 2 -- pkgs/top-level/all-packages.nix | 4 ---- pkgs/top-level/darwin-packages.nix | 1 - 11 files changed, 12 insertions(+), 29 deletions(-) diff --git a/lib/customisation.nix b/lib/customisation.nix index a46913dc5bde7..5c66169f215f6 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -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; diff --git a/pkgs/desktops/xfce/default.nix b/pkgs/desktops/xfce/default.nix index 41de05a41de30..1593deca9c358 100644 --- a/pkgs/desktops/xfce/default.nix +++ b/pkgs/desktops/xfce/default.nix @@ -5,14 +5,8 @@ , makeScopeWithSplicing }: -let - keep = _self: { }; - extra = _spliced0: { }; - -in makeScopeWithSplicing { otherSplices = generateSplicesForMkScope "xfce"; - inherit keep extra; f = (self: let inherit (self) callPackage; diff --git a/pkgs/development/interpreters/lua-5/default.nix b/pkgs/development/interpreters/lua-5/default.nix index b0c6182caddd2..918c3375b0d46 100644 --- a/pkgs/development/interpreters/lua-5/default.nix +++ b/pkgs/development/interpreters/lua-5/default.nix @@ -39,15 +39,13 @@ let selfHostHost = luaOnHostForHost.pkgs; selfTargetTarget = luaOnTargetForTarget.pkgs or {}; }; - keep = self: { }; - extra = spliced0: {}; extensions = lib.composeManyExtensions [ generatedPackages overriddenPackages overrides ]; in makeScopeWithSplicing { - inherit otherSplices keep extra; + inherit otherSplices; f = lib.extends extensions luaPackagesFun; }) { diff --git a/pkgs/development/interpreters/perl/default.nix b/pkgs/development/interpreters/perl/default.nix index 6eb439ea4a9e2..faf9e26cff7f0 100644 --- a/pkgs/development/interpreters/perl/default.nix +++ b/pkgs/development/interpreters/perl/default.nix @@ -34,10 +34,8 @@ let selfHostHost = perlOnHostForHost.pkgs; selfTargetTarget = perlOnTargetForTarget.pkgs or {}; }; - keep = self: { }; - extra = spliced0: {}; in makeScopeWithSplicing { - inherit otherSplices keep extra; + inherit otherSplices; f = perlPackagesFun; }) { diff --git a/pkgs/development/interpreters/python/passthrufun.nix b/pkgs/development/interpreters/python/passthrufun.nix index a4a04164ef314..91ff48d957194 100644 --- a/pkgs/development/interpreters/python/passthrufun.nix +++ b/pkgs/development/interpreters/python/passthrufun.nix @@ -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; @@ -61,7 +60,7 @@ ]); aliases = self: super: lib.optionalAttrs config.allowAliases (import ../../../top-level/python-aliases.nix lib self super); in makeScopeWithSplicing { - inherit otherSplices keep extra; + inherit otherSplices keep; f = lib.extends (lib.composeExtensions aliases extensions) keep; }) { overrides = packageOverrides; diff --git a/pkgs/development/libraries/qt-5/5.15/default.nix b/pkgs/development/libraries/qt-5/5.15/default.nix index 4531066438375..289af985e04b1 100644 --- a/pkgs/development/libraries/qt-5/5.15/default.nix +++ b/pkgs/development/libraries/qt-5/5.15/default.nix @@ -336,7 +336,5 @@ let in makeScopeWithSplicing { otherSplices = generateSplicesForMkScope "qt5"; - keep = _: {}; - extra = _: {}; f = addPackages; } diff --git a/pkgs/games/steam/default.nix b/pkgs/games/steam/default.nix index ebd0570d351a0..487175970cd5d 100644 --- a/pkgs/games/steam/default.nix +++ b/pkgs/games/steam/default.nix @@ -32,10 +32,7 @@ let steamcmd = callPackage ./steamcmd.nix { }; }; - keep = self: { }; - extra = spliced0: { }; in makeScopeWithSplicing { otherSplices = generateSplicesForMkScope "steamPackages"; - inherit keep extra; f = steamPackagesFun; } diff --git a/pkgs/os-specific/bsd/freebsd/default.nix b/pkgs/os-specific/bsd/freebsd/default.nix index e68b4ef87b3d2..e7541125436a3 100644 --- a/pkgs/os-specific/bsd/freebsd/default.nix +++ b/pkgs/os-specific/bsd/freebsd/default.nix @@ -68,8 +68,6 @@ let in makeScopeWithSplicing { otherSplices = generateSplicesForMkScope "freebsd"; - keep = _: {}; - extra = _: {}; f = (self: let inherit (self) mkDerivation; in { diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix index 6782bbf9df616..f12f5d2b18eb1 100644 --- a/pkgs/os-specific/bsd/netbsd/default.nix +++ b/pkgs/os-specific/bsd/netbsd/default.nix @@ -28,8 +28,6 @@ let in makeScopeWithSplicing { otherSplices = generateSplicesForMkScope "netbsd"; - keep = _: {}; - extra = _: {}; f = (self: let inherit (self) mkDerivation; in { diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6047098baed07..601955b0ac8f2 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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. @@ -27234,7 +27231,6 @@ with pkgs; xorgPackages = makeScopeWithSplicing { otherSplices = generateSplicesForMkScope "xorg"; - inherit keep extra; f = lib.extends overrides generatedPackages; }; diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index 55f908db9806f..c30d1c1c19206 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -17,7 +17,6 @@ in makeScopeWithSplicing { otherSplices = generateSplicesForMkScope "darwin"; - keep = _: {}; extra = spliced: spliced.apple_sdk.frameworks; f = (self: let inherit (self) mkDerivation callPackage;