-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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.packagesFromDirectoryRecursive: init #270537
Conversation
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.
Can you split out the documentation updates into a separate PR?
Regarding packagesFromDirectory
, I'd rather make this be unified with pkgs/by-name
than a separate convention. The 2-letter prefix of pkgs/by-name
should definitely be optional, and the ability to use files or directories only could also be optional.
Split the documentation updates into #270696. |
c8d2a86
to
1331025
Compare
That makes sense, but I'd rather not lose the recursive behavior here (subdirectories are also mapped to nested package attributes). I'll see if I can prototype a version with optional two-letter shards and optional directory recursion. Where should I put tests for this? |
d6fd380
to
4620198
Compare
4620198
to
308243e
Compare
OK, I've unified I've also reimplemented |
308243e
to
3d3ad0b
Compare
Thinking about it again, this does sound distinct enough that maybe it shouldn't be shared with I'm afraid I don't have a lot of capacity to review this right now though, I hope others can help out with this. |
But this is totally compatible with |
The function seems to support a superset of Furthermore, as soon as you have a package set there's the requirement of being able to override it. If you use |
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'm filling in to review since @infinisil indicated that he doesn't have time to give this a full review.
I think this is still okay to merge with just one small change. In particular, I'm not too concerned that the pkgs/by-name
function might (hypothetically) in the future have different requirements than lib.packagesFromDirectory
. If we ever get to that point it won't be hard to split the two implementations, but as far as I'm concerned the fact that this can be reused to powerpkgs/by-name
functionality in its present state is a feature.
lib/filesystem.nix
Outdated
# `pkgs.callPackage` | ||
callPackage: | ||
# The directory to read package files from | ||
directory: |
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.
The main thing I'll suggest is to make this take an attribute set instead of position arguments:
{ callPackage, directory }:
… that way if we need to add new optional arguments (with sensible defaults) we don't have to break backwards-compatibility. This would also be consistent with how pkgs.haskell.lib.packagesFromDirectory
works (it also takes an attribute set)
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.
Oh, and also, have the attribute set ignore extra arguments (for forward compatibility), also the same as pkgs.haskell.lib.packagesFromDirectory
:
{ callPackage, directory, ... }:
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.
Done.
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.
@Gabriella439, could you clarify the forward-compatibility aspect? As-is, packagesFromDirectoryRecursive
will silently ignore any unknown parameter, which seems to me more likely to cause subtle bugs than make things work on older nixpkgs version: presumably, new (optional) parameters would only be introduced (and specified) if they change the function's behaviour.
Having (older versions of) packagesFromDirectoryRecursive
silently revert to the default behaviour, is then non-compatible (the behaviour is different) but the incompatibility is silent rather than an explicit error.
Sorry for coming rather late to the party: I only learnt of packagesFromDirectory
yesterday, and it's great! Thank you and @9999years ❤️
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'd be fine removing the ...
. I'm not too attached to it.
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 was more trying to ask if I was missing some part of the reasoning behind accepting ...
😅
If I accidentally convinced you that dropping ...
would be preferable, should I do it as part of #359984 ?
It compounds the issue, by giving a usecase for putting extra parameters (used by recurseIntoDirectory
rather than packagesFromDirectoryRecursive
itself)
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.
+1 for dropping ...
!
3d3ad0b
to
a3ed91f
Compare
cb59ca6
to
e8332f1
Compare
e8332f1
to
d3b65c4
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'm not sure this callPackage will do the right thing with packages that depend on each other. I can imagine using this via an identity function or an import and then using a standard callPackage.
That being said, this is a good addition into our standard library, often needed.
@tomberek Yeah, the documentation I was asked to remove made this clearer, but |
d3b65c4
to
074108c
Compare
I'm not a maintainer of lib per se but this seems to be a very useful addition and there's many out of tree code that reinvents the same thing all the time, it would be tidy if we could just reuse nixpkgs for that directly. |
074108c
to
7093beb
Compare
7093beb
to
8eb9280
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.
Just minor comments, looking pretty good now!
2918dab
to
b7c61e8
Compare
Co-authored-by: Gabriella Gonzalez <[email protected]>
b7c61e8
to
090b929
Compare
Not gonna bother waiting for CI, it's too slow.. I tested it locally, all good 👍 |
I really love this function. Thanks for adding it @9999years. 🙇🏻 |
Description of changes
Adds a
packagesFromDirectoryRecursive
helper, which combinesbuiltins.readDir
andcallPackage
to transform a directory of.nix
package files into a matching nested attribute set of derivations.Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Priorities
Add a 👍 reaction to pull requests you find important.