Skip to content

lib.types: introduce a fileset type#428293

Merged
roberth merged 4 commits intoNixOS:masterfrom
tweag:fileset-type
Nov 4, 2025
Merged

lib.types: introduce a fileset type#428293
roberth merged 4 commits intoNixOS:masterfrom
tweag:fileset-type

Conversation

@Niols
Copy link
Contributor

@Niols Niols commented Jul 25, 2025

During some work on the Fediversity project, I came with the need for a programmatic FileSet type. I used a bit of an ugly workaround, and this PR is here to introduce a clean alternative.

  • Update the _coerce internal function to expose a pure variant, _coerceResult.
  • Expose isFileset (using the new _coerceResult) and empty
  • Introduce the “FileSet” type.

IMO, what will deserve most attention is:

  • My choice for isFileset, namely anything that can be passed to lib.fileset functions, not just something with _type == "fileset'. I could have called it “filesetable” or something, but this is how “FileSet” is used in the documentation.

  • My choices for check and merge, namely lib.fileset.isFileset and lib.fileset.unions. This is the first time I contribute to lib.types, so I am probably not seeing some interactions they might have.

  • Whether we even want that change in nixpkgs or whether we feel it belongs downstream where it is actually used.

Closes #266366
Related to #266356

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@nix-owners nix-owners bot requested review from hsjobeki, infinisil and roberth July 25, 2025 11:43
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 6.topic: module system About "NixOS" module system internals 6.topic: lib The Nixpkgs function library labels Jul 25, 2025
Copy link
Member

Choose a reason for hiding this comment

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

A non-allocating version of this might be preferable for performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hum, I'm unsure what would be the way to achieve this. I'm thinking of reworking _coerceResult to _coerceGeneric or something that gets the ok and error functions as arguments, and instantiate _coerce where ok = id and error = throw and isFileset where ok = _: true and error = _: false. Is that what you had in mind? Am I missing a cleaner solution?

Copy link
Member

Choose a reason for hiding this comment

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

Don't think it's worth it tbh, the fileset library is not that performant anyways (it's not a primary goal either)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The change I describe above is pretty easy to implement, though. So if it makes it a bit better, I'm happy to oblige.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure then.

fileset library is not that performant anyways

Ok. As an evaluation-time thing, they do need to be evaluated over and over. That could be problem if a project has many files.
Do you think the library could be improved in this regard? Or should we develop primops, like a native fileset type?

Anyway, let's not block on this and keep it simple for now.

@Niols
Copy link
Contributor Author

Niols commented Jul 30, 2025

I think the current CI failure has nothing to do with this PR, but rather is about CI hitting rate limiting from GitHub.

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jul 30, 2025
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 23, 2025
@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 28, 2025
@roberth
Copy link
Member

roberth commented Aug 28, 2025

LGTM, but could you squash/amend the commits so that the lib.fileset commits have the right formatting from the get go, and lib.types.fileset is in one commit?
(If that's a hassle, I guess re-committing with git add --patch might be an option, as they seem not to overlap?)

@Niols
Copy link
Contributor Author

Niols commented Aug 29, 2025

LGTM, but could you squash/amend the commits so that the lib.fileset commits have the right formatting from the get go, and lib.types.fileset is in one commit?

Thank you for taking the time to review all this! I have almost done what you asked, because of one uncertainty: to be clear, I should also merge the commit that adds the fileset type and the commit that add tests for that type?

@roberth roberth moved this to Backlog in Nixpkgs Lib Oct 30, 2025
@anna328p
Copy link
Member

anna328p commented Nov 2, 2025

@roberth ?

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.

Thank you!

@roberth roberth added this pull request to the merge queue Nov 4, 2025
Merged via the queue into NixOS:master with commit 49f0cbd Nov 4, 2025
32 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in Nixpkgs Lib Nov 4, 2025
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 6.topic: module system About "NixOS" module system internals 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package 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

Status: Done

Development

Successfully merging this pull request may close these issues.

lib.fileset.empty feature request

5 participants