-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
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.extendMkDerivation: init #234651
lib.extendMkDerivation: init #234651
Conversation
a2bd999
to
301bd5b
Compare
I should have checked more carefully. There's a function called Updat: fixed, see below. |
301bd5b
to
4f7af7a
Compare
Fix |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/avoid-rec-expresions-in-nixpkgs/8293/18 |
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.
A mix of incremental and fundamental suggestions, because I can't decide for the nixpkgs-python maintainers.
I'm concerned about the increasing complexity, while the goal can be achieved through simplification instead: removing the python-specific level of overriding and turning it into an "overlay" on the mkDerivation
arguments instead.
The alternative strategy is to
- Provide this python layer, which contains the relevant
mkPyton*
logic in a way that works with overlay-style overriding. This can be done by reading the existing code, attribute for attribute, and adding the logic to the python layer. - Change the python packages to use that layer in combination with
mkDerivation
, instead of the currentmkPython*
functions. - Perhaps make the
mkPython
functions reuse the overlay so that they don't literally reimplement the same logic. I don't know if this would be worthwhile. - Eventually deprecate the
mkPython*
functions.
I have played around with step 1 of the alternative strategy. It is feasible, but it requires a bit of migration for each package. I'm not a nixpkgs-python maintainer, so I don't feel like I should be the one to make the decision whether to accept the complexity of this PR, or refactor to actually simplify the python logic by fitting it into a mkDerivation
layer.
doc/builders/builders.chapter.md
Outdated
}: | ||
|
||
lib.extendRecursiveBuilder stdenv.mkDerivation [ ] (finalAttrs: | ||
|
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.
It's worth noting that finalAttrs
contains the final arguments to mkDerivation
attrs, and not the final arguments to the function you're constructing.
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.
Now the arguments after applying the modifier
function is also considered.
IMO, the finalAttrs
is meant to be the final state of the attributes passing to the base builder (mkDerivation
). That's how user could access finalAttrs.finalPackage
and other goodies. If we just want to get the input argument set manually, the user could just lib.fix
the function themselves.
Input arguments that doesn't mean to be passed to the base builder are subject to special care, and should never enter the recursion. Those not-to-pass arguments are also the reason why builder overlays are not drop-in replacement of current builders.
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.
I tried to add those special arguments to finalAttrs
, but that greatly increase the complexity of the code and makes behavior surprising (the specified result will be different from what is got through finalAttrs
by design).
A better way would be to encourage passing all the arguments. When all the arguments are passed, they will all be available inside finalAttrs
, and we could then switch to the overlay-based workflow specification (from the current, build-helper-based one).
in | ||
if builtins.isAttrs result then result | ||
else if builtins.isFunction result then { | ||
overridePythonAttrs = newArgs: makeOverridablePythonPackage f (overrideWith newArgs); | ||
__functor = self: result; | ||
} | ||
else result; | ||
else result); |
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 feels too custom or repeated (not sure yet which). Does this add mkDerivation
-like fixpoint logic at the python attrs level?
I believe we should merge the python attrs level into the mkDerivation attrs, so that the interface and implementation become simpler. Having multiple levels of overriding has a huge complexity cost, so getting rid of an unnecessary level would be a huge win. We'd get rid of overridePythonAttrs
and all the user facing complexity, implementation complexity and bugs that come with it.
The python-specific attrs can almost be implemented as an "overlay" on the mkDerivation
arguments. When I tried this, I think only like 3 attributes had the same name but a slightly different meaning. That made it a breaking change, but migrating those attributes is feasible and would vastly simplify the python/mkDerivation wiring.
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.
With same names that is generally speaking because the Python builder will extend the lists with some "defaults". That's really the only value of the custom builder over just plain hooks.
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 feels too custom or repeated (not sure yet which). Does this add
mkDerivation
-like fixpoint logic at the python attrs level?
I personally prefer passing most of the attributes into mkDerivation
, encourage the use of overrideAttrs
and gradually deprecates overridePythonAttrs
as well as other builder-specific override methods.
That will be a mass rebuild, so I just work around the makeOverridablePythonPackage
obstacle in order to demonstrate the possibility to add the recursive attributes support without rebuild.
Recently the Packages Modules Working Group started investigating whether something like the module system could be used to evaluate packages. We're tracking all work in this repository, meeting weekly, but working mostly asynchronously. It would be great if you could join the Matrix room of the WG and chat with us, or even join the team yourself to work on such issues! |
Thank you for taking time reviewing this!
The idea to shift workflow-specific overlays sounds neat, and that could also be friendlier when packaging multi-language projects. Nevertheless, there are some issue on the way to the switch:
Overall, the goal of the proposed function is to add |
doc/builders/builders.chapter.md
Outdated
} | ||
``` | ||
|
||
A list of functions to modify the resulting derivation can be specified after the base builder. Modifications such as overriding and `extendDerivation` can be applied there. |
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.
Where do we find information about extendDerivation
?
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.
lib.customisation
is currently not presented in the Nixpkgs manual. We'll need to add the documentation for those functions before referring to them.
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.
Besides, the Nixpkgs Library Functions documentation automatically generated from the comment don't have anchors. So there's no way to link against them so far.
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.
My fault. The anchor in the form function-library-<long attribute path>
is also automatically generated. E. g. function-library-lib.customisation.extendMkDerivation
.
This usage is very hard to discover, as the documentation is missing, and the manual provides no hyperlink in the title of each function document.
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.
I addressed this review in the changes to add a new section about using lib.extendMkDerivatien
to define build helpers. Please take a look.
Just reviewing your change to input-remapper, I like how much this cleaned up its definition. :) |
954f48e
to
2ee39a7
Compare
f3c34fb
to
d868837
Compare
@philiptaron, how do you think about leaving only If people prefer the current implementation, I could still revert. |
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.
Couple curious questions.
I like adding the |
09d0d08
to
f26ee78
Compare
f26ee78
to
83c0e00
Compare
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.
I think this is now as simple as it needs to be. I'm approving, trusting that you'll finish dotting the i's and crossing the t's before merge.
I found your worked example of a |
requested change ("make as simple as possible, one function") completed
83c0e00
to
3d2084a
Compare
Add functions extendMkDerivation to lib.customisation. Co-authored-by: Robert Hensing <[email protected]> Co-authored-by: Valentin Gagarin <[email protected]> Co-authored-by: Lin Jian <[email protected]> Co-authored-by: Philip Taron <[email protected]>
0bd67a4
to
1e06a3f
Compare
I addressed @philiptaron's naming suggestions and simplified the documentation. As the transition process to reduce excluded/removed arguments and limit custom overriders like |
Add "Fixed-point arguments of build helpers" chapter in "Builde helpers" part. Co-authored-by: nicoo <[email protected]> Co-authored-by: Silvan Mosberger <[email protected]> Co-authored-by: Valentin Gagarin <[email protected]> Co-authored-by: Lin Jian <[email protected]> Co-authored-by: Philip Taron <[email protected]>
1e06a3f
to
bbdf860
Compare
@fricklerhandwerk, IIRC, the changes you requested concern mainly the documentation. If you are available, could you kindly review the (now greatly simplified) documentation? |
I'm going to give this a final review then merge today, barring any late objections. Thanks for your two years of work on this, @ShamrockLee. |
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.
A few thoughts on the implementation. The most important one is about the resulting attrset, since that'd be hard to roll back.
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/21 |
So this does not do anything that would replace |
This PR alone does not. Replacing |
@PerchunPak The transition from #375921 helps shorten the diffs of the above two PRs. Reviews and feedback are welcome! |
Description of changes
This PR introduces a unified approach to implementing build helpers that support fixed-point arguments and bring such support to existing build helpers.
The fixed-point arguments support in
stdenv.mkDerivation
is introduced in #119942, and there are ongoing attempts to make other build helpers support such syntax (buildRustPackage
refactor #194475,buildGoModule
refactor #225051). The overlay styleoverrideAttrs
brought by thestdenv.mkDerivation
change can be used to implement the functionality, which is adopted by thebuildRustPackage
refactor and the previous version of thebuildGoModule
refactor. The challenge of such an approach is that the whole set pattern matching the input arguments are degenerated into a single identifier, making it hard to see from the source code which attributes to the build helper accepts.The new Nixpkgs Library function,
lib.extendMkDerivation
accepts a base build helper and an attribute overlay (an overlay in the formfinalAttrs: args: <attrsToUpdate>
), and returns a new build helper by extending the base build helper with the attribute overlay via its<pkg>.overrideAttrs
.The following is the definition of an example build helper,
mkLocalDerivation
:For existing build helpers with arguments that cannot be passed to the base build helper,
lib.extendMkDerivation
provides an attributeremovedAttrNames
to specify arguments not to pass down to the base build helper.Aside from
removedAttrNames
lib.extendMkDerivation
, other optional arguments are used to manipulate their behaviors. For example,lib.adaptMkDerivation { transformDrv = toPythonModule; }
applies the functiontoPythonModule
to the derivation produced by the derived build helper.Cc:
Python maintainers: @FRidh @mweinelt @jonringer
Author of the
buildRustPackage
refactor PR @amesgenReviewer of the
buildGoModule
refactor PR @zowoqAuthor of the merged recursive
stdenv.mkDerivation
PR @roberthPeople who mention 119942 in Python application definition: @LunNova
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)