From d4dd261ab5c38431db0b45daa425b0d01a82168e Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Sun, 30 Nov 2025 15:13:43 +0800 Subject: [PATCH] nix-prefetch-git: fetch the fetching tag for NIX_PREFETCH_GIT_CHECKOUT_HOOK Co-authored-by: Adam Dinwoodie --- pkgs/build-support/fetchgit/nix-prefetch-git | 7 +++++++ pkgs/build-support/fetchgit/tests.nix | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git index f9c8af8428fe..c3df5fc502b1 100755 --- a/pkgs/build-support/fetchgit/nix-prefetch-git +++ b/pkgs/build-support/fetchgit/nix-prefetch-git @@ -258,6 +258,13 @@ clone(){ clean_git fetch origin 'refs/tags/*:refs/tags/*' || echo "warning: failed to fetch some tags" >&2 fi + # Name "$ref" to make `git describe` work reproducibly in `NIX_PREFETCH_GIT_CHECKOUT_HOOK`. + # Name only when not leaving `.git` for compatibility purposes. + if [[ -n "$ref" ]] && [[ -z "$leaveDotGit" ]]; then + echo "refer to FETCH_HEAD as its original name $ref" + clean_git update-ref "$ref" FETCH_HEAD + fi + # Checkout linked sources. if test -n "$fetchSubmodules"; then init_submodules diff --git a/pkgs/build-support/fetchgit/tests.nix b/pkgs/build-support/fetchgit/tests.nix index e1d2ad2c2bed..92e3c4e06e8a 100644 --- a/pkgs/build-support/fetchgit/tests.nix +++ b/pkgs/build-support/fetchgit/tests.nix @@ -34,6 +34,16 @@ hash = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY="; }; + describe-tag = testers.invalidateFetcherByDrvHash fetchgit { + name = "describe-tag-nix-source"; + url = "https://github.com/NixOS/nix"; + tag = "2.3.15"; + hash = "sha256-y7l+46lVP2pzJwGON5qEV0EoxWofRoWAym5q9VXvpc8="; + postCheckout = '' + { git -C "$out" describe || echo "git describe failed"; } | tee "$out"/describe-output.txt + ''; + }; + sparseCheckout = testers.invalidateFetcherByDrvHash fetchgit { name = "sparse-checkout-nix-source"; url = "https://github.com/NixOS/nix";