Skip to content

fileset.fileFilter: Restrict second argument to paths#267384

Merged
roberth merged 1 commit intoNixOS:masterfrom
tweag:fileset.fileFilter-path2
Nov 15, 2023
Merged

fileset.fileFilter: Restrict second argument to paths#267384
roberth merged 1 commit intoNixOS:masterfrom
tweag:fileset.fileFilter-path2

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
@infinisil infinisil force-pushed the fileset.fileFilter-path2 branch from c7ba94e to 1f72f51 Compare November 14, 2023 07:31
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 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.

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 force-pushed the fileset.fileFilter-path2 branch from 1f72f51 to 1c3eb9e Compare November 15, 2023 00:21
@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 person. label Nov 15, 2023
@roberth roberth merged commit 060c4ad into NixOS:master Nov 15, 2023
@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 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants