Skip to content

Comments

lib.fileset.union, lib.fileset.unions: init#255025

Merged
roberth merged 17 commits intoNixOS:masterfrom
tweag:fileset.union
Sep 21, 2023
Merged

lib.fileset.union, lib.fileset.unions: init#255025
roberth merged 17 commits intoNixOS:masterfrom
tweag:fileset.union

Conversation

@infinisil
Copy link
Member

@infinisil infinisil commented Sep 13, 2023

Description of changes

This is another split off from the file set combinators PR, based on top of the already-merged lib.fileset.toSource and fileset infrastructure.

This adds two new functions, allowing the creation of unions of file sets:

lib.fileset.toSource {
  root = ./.;
  # Includes ./Makefile and recursively all files in ./src
  fileset = lib.fileset.union
    ./Makefile
    ./src;
}

lib.fileset.toSource {
  # Needed to be able to include a file from the parent directory
  root = ./..;
  # unions takes a list instead, only the given paths are included, nothing else
  fileset = lib.fileset.unions [
    ./Makefile
    ./src
    # Also include a file from the parent directory
    ../LICENSE
  ];
}

Comparatively, doing this correctly using the existing lib.sources functions is notoriously difficult.

This work is sponsored by Antithesis

Things done

  • Implementation
    • Tested
    • Commented
    • Benchmarked
  • Added user documentation
  • Updated other relevant documentation

We can now test returned paths being equal, no need to work around it
anymore by making sure paths aren't returned (which would import them
with the previous --json)
@github-actions github-actions bot added 8.has: documentation This PR adds or changes documentation 6.topic: lib The Nixpkgs function library labels Sep 13, 2023
@infinisil infinisil mentioned this pull request Sep 13, 2023
7 tasks
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/easy-source-filtering-with-file-sets/29117/11

@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 Sep 13, 2023
Copy link
Contributor

@fricklerhandwerk fricklerhandwerk left a comment

Choose a reason for hiding this comment

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

Noice

@delroth delroth added the 12.approvals: 1 This PR was reviewed and approved by one person. label Sep 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.

Minor things and a concern about stack overflows when thunks build up in a lazy part despite foldl' (might be due to incomplete understanding of filesets, but test would be appreciated)

@delroth delroth removed the 12.approvals: 1 This PR was reviewed and approved by one person. label Sep 14, 2023
@infinisil
Copy link
Member Author

infinisil commented Sep 14, 2023

@roberth @fricklerhandwerk Thanks! I applied the suggestions

Good catch on the stack overflow potential @roberth, indeed it does stack overflow with many files! I fixed that now and included a test case with ulimit -s 100 that would break if unions was implemented recursively.

I also added a benchmark for unions and discovered that it can be sped up by a factor of 12! (The benchmark now also measures time)

I also opened two nixdoc issues:

@infinisil
Copy link
Member Author

I'm fairly happy with this now, do you want to take a closer look @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.

Two suggestions, but lgtm now!

Comment on lines 268 to 274
Copy link
Member

Choose a reason for hiding this comment

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

These bindings are only used once. Are you sure the earlier renaming is necessary?

Copy link
Member Author

@infinisil infinisil Sep 20, 2023

Choose a reason for hiding this comment

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

Not necessary yeah, though just passing the argument between functions directly was a bit unsightly, so I'm using lib.pipe instead now: https://github.com/NixOS/nixpkgs/compare/622cdf4567bc0e98a0926df7ea8ffedf89d94298..1498af4bf1ab058053ff35a4f601e02859420828

Copy link
Member

Choose a reason for hiding this comment

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

I can never remember the order of pipe, probably because I dislike it.
Whatever works, I guess.

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
# TODO: This could be supported, but requires an extra internal representation for the empty file set
# TODO: This could be supported, but requires an extra internal representation for the empty file set, which would be special for not having a root.

Copy link
Member Author

Choose a reason for hiding this comment

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

Did s/root/base path, since that's the term used throughout

infinisil and others added 4 commits September 21, 2023 00:21
    $ ./benchmark.sh HEAD
    [...]
    Mean CPU time 0.04006 (σ = 0.0040146) for 10 runs is 8.193619775953792% (σ = 0.9584251052704821%) of the old value 0.488917 (σ = 0.0294955)
    [...]
Co-authored-by: Robert Hensing <[email protected]>
Co-authored-by: Valentin Gagarin <[email protected]>
@infinisil
Copy link
Member Author

infinisil commented Sep 20, 2023

Very minor push to add a level of indentation to doc comments (diff)

Thanks for the review Robert, I'll merge this when I see it next time with CI passing!

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 8.has: documentation This PR adds or changes documentation 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants