-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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
Enforce that package argument defaults are applied, cleans up optional dependency convention #131271
base: master
Are you sure you want to change the base?
Conversation
e2ee076
to
c088470
Compare
3e4401b
to
20b417e
Compare
@@ -1,6 +1,6 @@ | |||
{ mkDerivation, lib, fetchFromGitHub, fetchpatch, cmake, extra-cmake-modules | |||
, kauth, krunner | |||
, pass, pass-otp ? null }: | |||
, pass }: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one case where this PR actually finds a bug in nixpkgs: This expression was previously called with both pass
and pass-otp
, however the latter of which is just an alias of the former with an extension:
nixpkgs/pkgs/top-level/aliases.nix
Line 556 in b27f145
pass-otp = pass.withExtensions (ext: [ext.pass-otp]); # added 2018-05-04 |
CI however checks that aliases aren't used by not including them in the scope. The fact that this expression used ? null
allowed it to get around the CI check, because then just the default of null
was used!
This is notably the only package that is getting rebuilt, and possibly this change breaks the package, depending on which pass
took priority beforehand.
CI is finally green. While fixing the eval failures I found a couple of potential bugs that showed themselves via this change, one of which is the above for As somewhat expected, this increases eval time by a bit, @GrahamcOfBorg shows
We'd have to do more evaluations to get a good statistical estimate of it though. This is really the only problem with this PR imo. Could be fixed by:
|
@@ -2772,6 +2772,8 @@ in { | |||
|
|||
future = callPackage ../development/python-modules/future { }; | |||
|
|||
futures = throw "futures is only available for Python 2"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these throws should be moved to python2-packages.nix
. You can then write futures = disabled super.futures;
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Downside is this still evaluates super.futures
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I move them to python2-packages.nix
they won't be available for Python 3 right? The point of these definitions is that they define these attributes for Python 3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I mixed up 2 and 3.
It's a pity this is needed. The idea is to get rid of all mention of Python 2 from python-packages.nix
. Contributors should not need to think about Python 2. If we now need to start adding throw
when a package is not available for Python 3, the whole splitting into python-packages.nix
and python2-packages.nix
has been for nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could introduce a mechanism that automatically mirrors all attributes to Python 3 with such a throw
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/tweag-nix-dev-update-16/14379/1 |
Anything blocking this? |
@Artturin The only thing that prevents me from merging this is that there's an overhead to it. I measured it again, and it turns out to be about an 1.8% increase in evaluation time for
Considering this, I'm not sure if this is worth it. 1.8% is not a lot, but it adds up. |
I have also experienced this I believe and it was not easy to find the problem. |
@infinisil maybe hide this codepath between a nixpkgs config flag and set it to true in some ofborg check? |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2024-01-09-nixpkgs-architecture-team-meeting-47/38037/1 |
Could you provide how did you generate that graph? |
@Aleksanaa Iirc I pretty much copied what I did here: NixOS/nix#4154 (comment) |
Motivation for this change
Nixpkgs features this pattern a lot for declaring optional dependencies in package definitions:
One problem with this is that the
bar ? null
has no effect, becausepkgs.bar
exists (it actually does!), meaning that when this file getscallPackage
'd,pkgs.bar
will override the default value. The fact that? null
is specified can be very confusing.This is in contrast to
enableBar ? true
, which uses the default oftrue
, becausepkgs.enableBar
doesn't exist. However here there's also a problem, because what if at some point in the futureenableBar
does exist? This can mess up the result of this expression, giving errors or wrong results.This PR implements a very simple fix for these problems: If an argument has a default, the default has to be used, it can't be overridden by an implicit attribute in the scope. Specifically above example will throw this warning:
This means you'll have to update above example to be
And when someone at some point defines
pkgs.enableBar
, a warning will be thrown for that too.Doing this also has the nice side effects that arguments with defaults are now only used for package configuration and not dependencies. This allows people to easily identify what's configuration and what's a dependency.
The main problem with this change is that it might slow down evaluation too much, since this extra checking is not free, and necessary for every package expression. This could be mitigated by introducing a Nix builtin to handle this (#79877 could also benefit from a Nix-native
callPackageWith
implementation)Ping @adrianparvino @pstn because you recently ran into such a problem
Things done
nix-env -qaf .
to see all the current warnings and fix themnix-env -qaf .
for warnings/errors