From a1fdbae706c846f01c31bbe02cb8246fa348b480 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 14 Aug 2023 02:47:59 +0300 Subject: [PATCH 1/2] 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 +- pkgs/top-level/splice.nix | 1 + 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/customisation.nix b/lib/customisation.nix index a9281b1ab698..6dbe8f472f9b 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 73b8ad871544..1958d93aaf51 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 diff --git a/pkgs/top-level/splice.nix b/pkgs/top-level/splice.nix index 51fd6f420e80..9ac0fe2200f9 100644 --- a/pkgs/top-level/splice.nix +++ b/pkgs/top-level/splice.nix @@ -145,6 +145,7 @@ in # 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 cbc8aa437c44c510b54c664364dbfbcd98ac5f18 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 14 Aug 2023 02:49:53 +0300 Subject: [PATCH 2/2] treewide: use uncurried version of makeScopeWithSplicing --- pkgs/desktops/xfce/default.nix | 18 ++++++------------ .../development/interpreters/lua-5/default.nix | 13 +++++-------- pkgs/development/interpreters/perl/default.nix | 13 +++++-------- .../interpreters/python/default.nix | 2 +- .../interpreters/python/passthrufun.nix | 13 +++++-------- .../libraries/qt-5/5.15/default.nix | 7 +++++-- pkgs/development/libraries/qt-6/default.nix | 2 +- pkgs/games/steam/default.nix | 9 +++++---- pkgs/os-specific/bsd/freebsd/default.nix | 13 ++++++------- pkgs/os-specific/bsd/netbsd/default.nix | 15 +++++++-------- pkgs/top-level/all-packages.nix | 14 +++++--------- pkgs/top-level/darwin-packages.nix | 10 +++++++--- 12 files changed, 58 insertions(+), 71 deletions(-) diff --git a/pkgs/desktops/xfce/default.nix b/pkgs/desktops/xfce/default.nix index 5dc21338a72c..4aec72ea334b 100644 --- a/pkgs/desktops/xfce/default.nix +++ b/pkgs/desktops/xfce/default.nix @@ -2,19 +2,12 @@ , lib , pkgs , generateSplicesForMkScope -, makeScopeWithSplicing +, makeScopeWithSplicing' }: -let - keep = _self: { }; - extra = _spliced0: { }; - -in -makeScopeWithSplicing - (generateSplicesForMkScope "xfce") - keep - extra - (self: +makeScopeWithSplicing' { + otherSplices = generateSplicesForMkScope "xfce"; + f = (self: let inherit (self) callPackage; in @@ -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 - }) + }); +} diff --git a/pkgs/development/interpreters/lua-5/default.nix b/pkgs/development/interpreters/lua-5/default.nix index f4c622515d7d..51d44e7f1e0f 100644 --- a/pkgs/development/interpreters/lua-5/default.nix +++ b/pkgs/development/interpreters/lua-5/default.nix @@ -23,7 +23,7 @@ let # - imports lua-packages.nix # - adds spliced package sets to the package set # - applies overrides from `packageOverrides` - ({ lua, overrides, callPackage, makeScopeWithSplicing }: let + ({ lua, overrides, callPackage, makeScopeWithSplicing' }: let luaPackagesFun = callPackage ../../../top-level/lua-packages.nix { lua = self; }; @@ -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; diff --git a/pkgs/development/interpreters/perl/default.nix b/pkgs/development/interpreters/perl/default.nix index a2f9862083c9..201a080309d7 100644 --- a/pkgs/development/interpreters/perl/default.nix +++ b/pkgs/development/interpreters/perl/default.nix @@ -17,7 +17,7 @@ let # Function that when called # - imports perl-packages.nix # - adds spliced package sets to the package set - ({ stdenv, pkgs, perl, callPackage, makeScopeWithSplicing }: let + ({ stdenv, pkgs, perl, callPackage, makeScopeWithSplicing' }: let perlPackagesFun = callPackage ../../../top-level/perl-packages.nix { # allow 'perlPackages.override { pkgs = pkgs // { imagemagick = imagemagickBig; }; }' like in python3Packages # most perl packages aren't called with callPackage so it's not possible to override their arguments individually @@ -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; }; diff --git a/pkgs/development/interpreters/python/default.nix b/pkgs/development/interpreters/python/default.nix index 8ea1c14c7111..fb504c5043c8 100644 --- a/pkgs/development/interpreters/python/default.nix +++ b/pkgs/development/interpreters/python/default.nix @@ -5,7 +5,7 @@ , db , lib , libffiBoot -, makeScopeWithSplicing +, makeScopeWithSplicing' , pythonPackagesExtensions , stdenv }@args: diff --git a/pkgs/development/interpreters/python/passthrufun.nix b/pkgs/development/interpreters/python/passthrufun.nix index aa63f354e085..f0654a91c75a 100644 --- a/pkgs/development/interpreters/python/passthrufun.nix +++ b/pkgs/development/interpreters/python/passthrufun.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, callPackage, pythonPackagesExtensions, config, makeScopeWithSplicing, ... }: +{ lib, stdenv, callPackage, pythonPackagesExtensions, config, makeScopeWithSplicing', ... }: { implementation , libPrefix @@ -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; @@ -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; }); diff --git a/pkgs/development/libraries/qt-5/5.15/default.nix b/pkgs/development/libraries/qt-5/5.15/default.nix index 5ae5102abeee..f1cbe96d11a7 100644 --- a/pkgs/development/libraries/qt-5/5.15/default.nix +++ b/pkgs/development/libraries/qt-5/5.15/default.nix @@ -7,7 +7,7 @@ Check for any minor version changes. */ -{ makeScopeWithSplicing, generateSplicesForMkScope +{ makeScopeWithSplicing', generateSplicesForMkScope , lib, stdenv, fetchurl, fetchgit, fetchpatch, fetchFromGitHub, makeSetupHook, makeWrapper , bison, cups ? null, harfbuzz, libGL, perl, python3 , gstreamer, gst-plugins-base, gtk3, dconf @@ -331,4 +331,7 @@ let } ../hooks/wrap-qt-apps-hook.sh; }; -in makeScopeWithSplicing (generateSplicesForMkScope "qt5") (_: {}) (_: {}) addPackages +in makeScopeWithSplicing' { + otherSplices = generateSplicesForMkScope "qt5"; + f = addPackages; +} diff --git a/pkgs/development/libraries/qt-6/default.nix b/pkgs/development/libraries/qt-6/default.nix index d9bc6ae15e1f..66d29196378f 100644 --- a/pkgs/development/libraries/qt-6/default.nix +++ b/pkgs/development/libraries/qt-6/default.nix @@ -166,7 +166,7 @@ let } ./hooks/qmake-hook.sh; }; - # TODO(@Artturin): convert to makeScopeWithSplicing + # TODO(@Artturin): convert to makeScopeWithSplicing' # simple example of how to do that in 5568a4d25ca406809530420996d57e0876ca1a01 self = lib.makeScope newScope addPackages; in diff --git a/pkgs/games/steam/default.nix b/pkgs/games/steam/default.nix index 370f22268a9a..651c20491844 100644 --- a/pkgs/games/steam/default.nix +++ b/pkgs/games/steam/default.nix @@ -1,4 +1,4 @@ -{ makeScopeWithSplicing, generateSplicesForMkScope +{ makeScopeWithSplicing', generateSplicesForMkScope , stdenv, buildFHSEnv, pkgsi686Linux, glxinfo }: @@ -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; +} diff --git a/pkgs/os-specific/bsd/freebsd/default.nix b/pkgs/os-specific/bsd/freebsd/default.nix index 136c9721c6bb..ff9f4d911f03 100644 --- a/pkgs/os-specific/bsd/freebsd/default.nix +++ b/pkgs/os-specific/bsd/freebsd/default.nix @@ -1,5 +1,5 @@ { stdenv, lib, stdenvNoCC -, makeScopeWithSplicing, generateSplicesForMkScope +, makeScopeWithSplicing', generateSplicesForMkScope , buildPackages , bsdSetupHook, makeSetupHook , fetchgit, fetchzip, coreutils, groff, mandoc, byacc, flex, which, m4, gawk, substituteAll, runtimeShell @@ -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; @@ -898,4 +896,5 @@ in makeScopeWithSplicing ''; }); -}) +}); +} diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix index 11d8aa2ec3b0..5012a0c7d3c7 100644 --- a/pkgs/os-specific/bsd/netbsd/default.nix +++ b/pkgs/os-specific/bsd/netbsd/default.nix @@ -1,5 +1,5 @@ { stdenv, lib, stdenvNoCC -, makeScopeWithSplicing, generateSplicesForMkScope +, makeScopeWithSplicing', generateSplicesForMkScope , buildPackages , bsdSetupHook, makeSetupHook, fetchcvs, groff, mandoc, byacc, flex , zlib @@ -26,17 +26,15 @@ let else "no"}" ]; -in makeScopeWithSplicing - (generateSplicesForMkScope "netbsd") - (_: {}) - (_: {}) - (self: let +in makeScopeWithSplicing' { + otherSplices = generateSplicesForMkScope "netbsd"; + f = (self: let inherit (self) mkDerivation; in { # Why do we have splicing and yet do `nativeBuildInputs = with self; ...`? # - # We use `makeScopeWithSplicing` because this should be used for all + # We use `makeScopeWithSplicing'` because this should be used for all # nested package sets which support cross, so the inner `callPackage` works # correctly. But for the inline packages we don't bother to use # `callPackage`. @@ -1011,4 +1009,5 @@ in makeScopeWithSplicing # END MISCELLANEOUS # -}) +}); +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 4f4fb0027463..0477715bc550 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -24479,7 +24479,7 @@ with pkgs; qt5 = recurseIntoAttrs (makeOverridable (import ../development/libraries/qt-5/5.15) { inherit (__splicedPackages) - makeScopeWithSplicing generateSplicesForMkScope lib fetchurl fetchpatch fetchgit fetchFromGitHub makeSetupHook makeWrapper + makeScopeWithSplicing' generateSplicesForMkScope lib fetchurl fetchpatch fetchgit fetchFromGitHub makeSetupHook makeWrapper bison cups dconf harfbuzz libGL perl gtk3 python3 darwin buildPackages; inherit (__splicedPackages.gst_all_1) gstreamer gst-plugins-base; @@ -27317,9 +27317,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. @@ -27334,11 +27331,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; diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index ef4240955b9c..79764a8133ab 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -1,6 +1,6 @@ { lib , buildPackages, pkgs, targetPackages -, generateSplicesForMkScope, makeScopeWithSplicing +, generateSplicesForMkScope, makeScopeWithSplicing' , stdenv , preLibcCrossHeaders , config @@ -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. @@ -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 -}) +}); +}