Skip to content

lib.customisation: uncurry makeScopeWithSplicing#245824

Merged
2 commits merged intomasterfrom
unknown repository
Jul 28, 2023
Merged

lib.customisation: uncurry makeScopeWithSplicing#245824
2 commits merged intomasterfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Jul 28, 2023

Description of changes

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.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: qt/kde Object-oriented framework for GUI creation 6.topic: xfce The Xfce Desktop Environment 6.topic: steam Steam game store/launcher (store.steampowered.com) 6.topic: lua Lua is a powerful, efficient, lightweight, embeddable scripting language. 6.topic: lib The Nixpkgs function library labels Jul 28, 2023
@ghost ghost marked this pull request as draft July 28, 2023 03:58
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.
@ghost ghost requested a review from Artturin July 28, 2023 04:49
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Jul 28, 2023
@ghost ghost marked this pull request as ready for review July 28, 2023 06:18
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

These are often unneeded by the user.
Copy link
Author

@ghost ghost left a comment

Choose a reason for hiding this comment

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

I guess I can't "approve" my own PR, but I approve of the commit @Artturin pushed onto it.

@ghost ghost merged commit 12cb207 into NixOS:master Jul 28, 2023
@infinisil
Copy link
Member

This is not okay, this is a breaking change to lib which breaks all third-party uses of it

@ghost
Copy link
Author

ghost commented Jul 28, 2023

This is not okay, this is a breaking change to lib which breaks all third-party uses of it

You're right. For some reason I thought makeScopeWithSplicing was added recently, but I was wrong about that.

Will revert and reintroduce with a new name for the uncurried version.

@ghost
Copy link
Author

ghost commented Jul 28, 2023

I have merged #245955

@infinisil
Copy link
Member

Thanks!

@ghost ghost deleted the pr/lib/customization/makeScopeWithSplicing branch July 28, 2023 21:11
@ghost
Copy link
Author

ghost commented Jul 28, 2023

Reimplemented with a different name and a backward-compatible shim: #245957

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: lib The Nixpkgs function library 6.topic: lua Lua is a powerful, efficient, lightweight, embeddable scripting language. 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: qt/kde Object-oriented framework for GUI creation 6.topic: steam Steam game store/launcher (store.steampowered.com) 6.topic: xfce The Xfce Desktop Environment 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants