Skip to content

Added fetchTags feature to fetchgit - #411561

Merged
philiptaron merged 2 commits into
NixOS:masterfrom
timblaktu:fetchgit-fetchtags
May 29, 2025
Merged

philiptaron merged 2 commits into
NixOS:masterfrom
timblaktu:fetchgit-fetchtags

Conversation

@timblaktu

Copy link
Copy Markdown
Contributor

This adds a fetchTags parameter to fetchgit that ensures all tags
are fetched from the remote repository. Tags are sometimes required in projects, e.g. ones that call 'git describe', and since the nix store is read-only by design, it is not possible to git fetch --tags at activation- or run-time without horrendous violations of this principle. This feature may have been possible by specifying a postFetch option including calling git fetch --tags, however doing so obfuscates the solution to this very real problem, and does nothing to improve the usability of nix.

Explicit support for fetching tags should be a first class citizen just like fetching other refs.

The parameter works by running 'git fetch origin refs/tags/:refs/tags/'
after the main fetch operation, ensuring all tags are available.

  • fetchTags defaults to false, ensuring backwards compatibility and imposing no performance on those who do not use it
  • fetchTags implies leaveDotGit, and follows the same pattern as deepClone
  • Added proper validation and error handling
  • Updated relevant documentation and test cases
  • Fixes issues with ESP-IDF and similar packages that need git tags
    for version detection during build or runtime.

Things done

Tested on x86_64, nix 25.11, and this branch of my nix config repo, which integrates and uses this PR source fork/branch in the context of this corresponding branch/fork of the nixpkgs-esp-dev repo, where I stumbled into this and other rakes trying to set up an esp32 dev env. This was my first foray this deep into nix packaging and process, and I learned a lot and hope to contribute more in the future.

@github-actions github-actions Bot added 6.topic: fetch Fetchers (e.g. fetchgit, fetchsvn, ...) 8.has: documentation This PR adds or changes documentation labels May 27, 2025
@nix-owners
nix-owners Bot requested a review from philiptaron May 27, 2025 23:14
@github-actions github-actions Bot added 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels May 27, 2025
@NixOSInfra NixOSInfra added the 12.first-time contribution This PR is the author's first one; please be gentle! label May 27, 2025

@philiptaron philiptaron left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm amenable to merge.

Two requests:

  1. Drop unrelated change to .gitignore.
  2. Follow commit conventions: fetchgit: add fetchTags parameter

Comment thread .gitignore Resolved
Tim Black and others added 2 commits May 28, 2025 16:47
Added fetchTags feature to fetchgit, explicit and clear support for
fetching all tags after the source tree fetch completes. Doing this at
build-time in the fetcher is required for packages that invoke commands
like 'git describe' which require tags, and since the nix store is
read-only by design, it is not possible to git fetch --tags at
activation- or run-time. This feature may have been possible by
specifying a postFetch option including calling git fetch --tags,
however doing so obfuscates the solution to this very real problem.
Explicit support for fetching tags should be a first class citizen just
like fetching other refs.
@timblaktu
timblaktu force-pushed the fetchgit-fetchtags branch from 807eabb to 95a780a Compare May 28, 2025 23:54
@timblaktu

Copy link
Copy Markdown
Contributor Author

@philiptaron I have rewritten the commit messages on my source branch to follow the project's documented commit convention. Let me know if there's anything else I can/should do.

@timblaktu
timblaktu requested a review from philiptaron May 28, 2025 23:56
@philiptaron

Copy link
Copy Markdown
Contributor

I plan on submitting in ~12 hours unless I got a nack from other relevant parties.

@philiptaron
philiptaron merged commit 7f8ad4f into NixOS:master May 29, 2025
@me-and me-and mentioned this pull request Jun 1, 2025
3 tasks done
nixos-cuda-channel-updater Bot pushed a commit to nixos-cuda/nixpkgs that referenced this pull request Dec 3, 2026
When the fetchTags argument was added to fetchgit in 1247031
(pkgs/build-support/fetchgit: add fetchTags parameter, 2025-05-27)
/ NixOS#411561, there was no easy way to actually use the tags it would fetch
unless leaveDotGit was true.

That changed with the addition of the postCheckout hook in fc295b1
(fetchgit: take postCheckout to allow collecting revision without
leaving .git, 2025-11-27) / NixOS#465497.  The postCheckout hook can make use
of the tags before the .git directory is removed.

To allow this, remove the assertion that prevents using fetchTags
without having leaveDotGit be true.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: fetch Fetchers (e.g. fetchgit, fetchsvn, ...) 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 12.first-time contribution This PR is the author's first one; please be gentle!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants