-
-
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
lib.fileset.maybeMissing
: init
#265964
lib.fileset.maybeMissing
: init
#265964
Conversation
The name suggests a parallel with OT: I would quite like to have mkDerivation(finalAttrs: {
src = fileset.unions [
./src
(fileset.optional finalAttrs.doCheck ./tests)
];
}) |
Hmm good point, not a fan of Some other ideas:
I think I like
Oh that sounds nice, should be fairly easy to add too. |
Is this actually required? You can already use lib.optional(s) and have the result coerced to a fileset. |
So I wouldn't be too concerned about this name in general, but I don't think it's specific enough.
Still doesn't say what's tried. My favorite from your list is What about |
Also doesn't indicate what happens when it exists. I'll just go for |
80eef12
to
54f292f
Compare
I'm used to Haskell's
Correct, but I predict 50% will mistype. |
I'm worried the interface is growing faster than adoption of the library warrants. This issue could be stop-gapped with an example in the documentation, because the use case can be implemented with what's already there. If it turns out to be a heavily used pattern one can still add a convenience layer. Right now I'd prefer efforts being directed to making good use of existing facilities, evolving some usage patterns, and adding more practical examples to the docs. |
This particular use case I also encountered while working on the original WIP, and @alyssais being one of the first users and immediately running into it too gives me the feeling we should support this. The alternative without this function is too verbose: unions (lib.optional (builtins.pathExists ./generated.o) ./generated.o))
# With this PR:
maybeMissing ./generated.o Even just the fact that the path needs to be repeated will make anybody needing this want to write a function for it! I think |
54f292f
to
4e31015
Compare
FWIW: all I'm trying to do is replace this very simple use of cleanSource(With), and then add some additional filtering on top for individual components. I'd consider this a fairly basic use case. |
@infinisil how would you feel about having |
Hmm that doesn't always make sense though, because you can also do Maybe the check for files existing could be pushed further down generally though, I'll look into that. |
Right! That reminds me of the function type operator, which also have a binary property that flips in one of the operands, and flips back when the operator is nested: covariance/contravariance aka positive/negative. Seems to reinforce the idea that you can negate a contextual boolean (ie argument to some internal function) whenever you process a |
Unfortunately the |
4e31015
to
23a68fc
Compare
Since we decided against doing #267091, we should have I rebased on top of master, this would be ready from my side. |
23a68fc
to
bf9a068
Compare
Rebased again, still good from my side :) |
lib/fileset/default.nix
Outdated
if ! isPath path then | ||
if isStringLike path then | ||
throw '' | ||
lib.fileset.maybeMissing: Argument ("${toString path}") is a string-like value, but it should be a path instead.'' |
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.fileset.maybeMissing: Argument ("${toString path}") is a string-like value, but it should be a path instead.'' | |
lib.fileset.maybeMissing: Argument ("${toString path}") is a string-like value, but it should be a path instead. See https://nixos.org/manual/nix/stable/language/values#type-path'' |
I don't think the word "path" is enough for novices.
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 in 701cff3!
lib/fileset/default.nix
Outdated
lib.fileset.maybeMissing: Argument ("${toString path}") is a string-like value, but it should be a path instead.'' | ||
else | ||
throw '' | ||
lib.fileset.maybeMissing: Argument is of type ${typeOf path}, but it should be a path instead.'' |
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.
Same here.
Might be helpful to have a function that generates an explanation or something. Or just a let binding with the url?
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 for the sake of consistency I'd prefer just copying it to all the error messages for now. We could consider having a dedicated lib/fileset/errors.nix
in the future to collect and abstract over all error messages together.
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.
Could you document the rationale for maybeMissing
here, as opposed to non-strict by default?
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 in 4594aa0!
4594aa0
to
9748413
Compare
Ready to be merged again from my side |
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 implementation is good, but I suggest cutting down on the other diff noise.
lib/fileset/default.nix
Outdated
lib.fileset.maybeMissing: Argument ("${toString path}") is a string-like value, but it should be a path instead, see https://nixos.org/manual/nix/stable/language/values#type-path.'' | ||
else | ||
throw '' | ||
lib.fileset.maybeMissing: Argument is of type ${typeOf path}, but it should be a path instead, see https://nixos.org/manual/nix/stable/language/values#type-path.'' |
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 don't think we need links to the manual. It's spammy and doesn't exactly make things easier with maintaining that web stuff in the long run.
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.
Fair enough, removed them again!
9748413
to
cbaa880
Compare
I'll soon merge this myself so we can unblock NixOS/nix.dev#802 :) |
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.
One suggestion, then lgtm.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
a775c6c
to
827232d
Compare
Successfully created backport PR for |
Description of changes
Another split-off from #222981, motivated by @alyssais comment describing a use case. This PR adds a new function to
lib.fileset
:lib.fileset.maybeMissing :: Path -> FileSet
: Create a file set from a path that may or may not exist.An alternative is #267091, but we decided against that
This work is sponsored by Antithesis ✨
Things done