Skip to content
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

fileset.fileFilter: Restrict second argument to paths #267384

Merged
merged 1 commit into from
Nov 15, 2023

Conversation

infinisil
Copy link
Member

@infinisil infinisil commented Nov 14, 2023

Note
This PR was dependent on #267381

Description of changes

Currently fileFilter has the type

(Attrs -> Bool) -> Fileset -> Fileset

The predicate function currently supports properties name and type of the file. However, it might be really useful to allow filtering files by their path. But for the sake of reproducibility, we shouln't allow the absolute path. So instead it should be a subpath instead. But then the question is, what should it be relative to?

So I propose to change the type signature of fileFilter to

(Attrs -> Bool) -> Path -> Fileset

instead, because it allows us to use the Path as the base for the subpath, allowing a future interface like this:

fileFilter (file: elem "target" file.components) ./.

While this change is backwards-incompatible, I think it's okay because:

  • The fileFilter function is not yet in a stable NixOS release, it was only merged about a month ago.
    • All public uses of the function on GitHub only pass a path
  • Any fileFilter pred fileset can also be expressed as intersection fileset (fileFilter pred path) without loss of functionality.
    • This is furthermore pointed out in the new error message when a file set is passed
  • Once fully stable, we can still relax the restriction, but it's harder to add new restrictions.

Ping @roberth @fricklerhandwerk

This work is sponsored by Antithesis

Things done

  • Added tests
  • Updated docs
  • Updated design document

@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Nov 14, 2023
@infinisil infinisil changed the title Fileset.file filter path2 fileset.fileFilter: Restrict second argument to paths Nov 14, 2023
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Nov 14, 2023
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

Good idea, and I'm ok with the breaking change. It's for a good reason and low negative impact.

if path._type or "" == "fileset" then
throw ''
lib.fileset.fileFilter: Second argument is a file set, but it should be a path instead.
If you need to filter files in a file set, use `intersection fileset (fileFilter pred ./.)` instead.''
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
If you need to filter files in a file set, use `intersection fileset (fileFilter pred ./.)` instead.''
If you need to filter files in a file set, use `intersection fileset (fileFilter pred ./.)` instead.''

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd like to keep this for now because it's consistent with other error messages in the library.

While this change is backwards-incompatible, I think it's okay because:
- The `fileFilter` function is not yet in a stable NixOS release, it was only merged about [a month ago](NixOS#257356).
  - All public uses of the function on GitHub only pass a path
- Any `fileFilter pred fileset` can also be expressed as `intersection fileset (fileFilter pred path)` without loss of functionality.
  - This is furthermore pointed out in the new error message when a file set is passed
@infinisil infinisil marked this pull request as ready for review November 15, 2023 00:22
@infinisil
Copy link
Member Author

Just merged #267381 and rebased this PR on top

@delroth delroth added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Nov 15, 2023
@roberth roberth merged commit 060c4ad into NixOS:master Nov 15, 2023
22 checks passed
@infinisil infinisil deleted the fileset.fileFilter-path2 branch November 15, 2023 23:52
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 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 12.approvals: 1 This PR was reviewed and approved by one reputable person
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants