Skip to content

Comments

lib.fileset.gitTracked: Support out-of-tree builds#273893

Merged
infinisil merged 3 commits intoNixOS:masterfrom
tweag:fileset.gitTracked-storeDir
Dec 19, 2023
Merged

lib.fileset.gitTracked: Support out-of-tree builds#273893
infinisil merged 3 commits intoNixOS:masterfrom
tweag:fileset.gitTracked-storeDir

Conversation

@infinisil
Copy link
Member

@infinisil infinisil commented Dec 13, 2023

Note

This PR depended on #273883, now merged.
Originally it also depended on #273884, but not anymore.

Description of changes

This adds out-of-tree support for lib.fileset.gitTracked, where the repository is fetched using a method that already removes files not tracked by Git, such as builtins.fetchGit, pkgs.fetchgit or GitHub tarballs.

It works by falling back to importing the entire path if:

  • The path is in a nix store path
  • There's no .git directory

This fixes #269283.

This work is sponsored by Antithesis

Things done

  • Tidy code
  • Design/contributor documentation
  • User documentation
  • Tests

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Dec 13, 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 This PR causes between 1 and 10 packages to rebuild on Linux. labels Dec 13, 2023
@infinisil infinisil force-pushed the fileset.gitTracked-storeDir branch from 19dc2b3 to 1f5b475 Compare December 19, 2023 00:46
@infinisil infinisil marked this pull request as ready for review December 19, 2023 00:48
@infinisil
Copy link
Member Author

infinisil commented Dec 19, 2023

This is now ready! As always, comes with docs, tests and comments. Best reviewed commit-by-commit :)

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 change.

Copy link
Member

Choose a reason for hiding this comment

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

Even then, it'd be inefficient to copy at least a whole .git into the store every time. Those can be quite big.

Suggested change
See https://github.com/NixOS/nix/issues/9292.''
You could make this work by using a fetcher such as `fetchGit` instead of copying the whole repository.
If you can't avoid copying the repo to the store, see https://github.com/NixOS/nix/issues/9292.''

It would be great to link a more useful resource that explains what to do instead, because I don't think anyone should rely on that issue to be fixed, because copying a repo into the store is just not good for performance.

Perhaps sometimes even security, if it actually happened to be local and it has unencrypted un-added secrets, although that's a vaguely recognizable condition, that does not originate from fileset, and isn't fixable by fileset.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, for now I think your suggestion is good. This is such a rare case that I don't think it's worthwhile writing more about it for the time being.

Comment on lines 767 to 772
Copy link
Member

Choose a reason for hiding this comment

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

This paragraph doesn't feel relatable to someone who's writing a source filter for their project, because they're not using fetchGit. I think what we're trying to explain here is that gitTracked tries to do the right thing if what's a repo for them is filtered away by someone else. gitTracked can only assume that this someone else fetched it the right way, and that's relevant, because gitTracked would seem involved in potential problems that are beyond its power.
(Sorry, no time for a suggestion rn)

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
Git repositories can also be fetched as a [Nix store path](https://nixos.org/manual/nix/stable/store/store-path.html#store-path)
using a Git tree fetcher like `builtins.fetchGit` or `pkgs.fetchgit` (without `leaveDotGit`),
for the purposes of so-called out-of-tree building.
If such a fetched Git repository uses `gitTrackedWith` on a local path and is evaluated using `import`,
the function returns the Git-tracked files even in such a case.
So this function doesn't interfere with out-of-tree building.
`gitTrackedWith` does not perform any filtering when the path is a [Nix store path](https://nixos.org/manual/nix/stable/store/store-path.html#store-path) and not a repository.
In this way, it accommodates the use case where the expression that makes the `gitTracked` call does not reside in an actual git repository anymore, and has presumably already been fetched in a way that excludes untracked files.
Fetchers that are expected to implement such equivalent behavior include `builtins.fetchGit`, `builtins.fetchTree` (experimental), and `pkgs.fetchgit` when used without `leaveDotGit`.

so-called

Can do without the jargon.

Copy link
Member Author

@infinisil infinisil Dec 19, 2023

Choose a reason for hiding this comment

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

The last sentence feels a bit like fetchers need to implement support for this explicitly, how about just:

Fetchers with such behavior include builtins.fetchGit, builtins.fetchTree (experimental), and pkgs.fetchgit when used without leaveDotGit.

Otherwise this sounds good to me

Copy link
Member

Choose a reason for hiding this comment

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

Yeah sgtm.

I wish we could just claim equivalence, but for example fetchGit implements export-ignore by default for historic reasons.

Copy link
Member

Choose a reason for hiding this comment

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

Oh the "default" part is WIP actually...

@infinisil infinisil force-pushed the fileset.gitTracked-storeDir branch from 1f5b475 to 201be69 Compare December 19, 2023 14:33
@infinisil
Copy link
Member Author

@roberth Applied the suggestions with my suggestion-suggestion :)

@delroth delroth added the 12.approvals: 1 This PR was reviewed and approved by one person. label Dec 19, 2023
@infinisil infinisil force-pushed the fileset.gitTracked-storeDir branch from 201be69 to 38cf6ff Compare December 19, 2023 21:09
@infinisil
Copy link
Member Author

Ugh CI failed because I forgot to update the tests after updating the throw message.

I won't bother waiting another 3h just for CI to finish.. I tested it locally, it works now

@infinisil infinisil merged commit 1816242 into NixOS:master Dec 19, 2023
@infinisil infinisil deleted the fileset.gitTracked-storeDir branch December 19, 2023 21:14
@github-actions
Copy link
Contributor

Successfully created backport PR for release-23.11:

infinisil added a commit to NixOS/nix.dev that referenced this pull request Dec 21, 2023
Now that NixOS/nixpkgs#273893 is merged, the
previous note isn't accurate anymore.
infinisil added a commit to NixOS/nix.dev that referenced this pull request Dec 21, 2023
Now that NixOS/nixpkgs#273893 is merged, the
previous note isn't accurate anymore.
infinisil added a commit to NixOS/nix.dev that referenced this pull request Dec 22, 2023
Now that NixOS/nixpkgs#273893 is merged, the
previous note isn't accurate anymore.
infinisil added a commit to NixOS/nix.dev that referenced this pull request Dec 22, 2023
Now that NixOS/nixpkgs#273893 is merged, the
previous note isn't accurate anymore.
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.

lib.fileset.gitTracked should support out-of-tree builds

3 participants