fetchgit: take postCheckout to allow collecting revision without leaving .git

This commit is contained in:
Yueh-Shun Li
2025-11-27 12:41:28 +08:00
parent c68642058c
commit fc295b1e28
2 changed files with 17 additions and 0 deletions
+7
View File
@@ -83,6 +83,8 @@ lib.makeOverridable (
# run operations between the checkout completing and deleting the .git
# directory.
preFetch ? "",
# Shell code executed after `git checkout` and before .git directory removal/sanitization.
postCheckout ? "",
# Shell code executed after the file has been fetched
# successfully. This can do things like check or transform the file.
postFetch ? "",
@@ -171,6 +173,7 @@ lib.makeOverridable (
deepClone
branchName
preFetch
postCheckout
postFetch
fetchTags
rootDir
@@ -227,6 +230,10 @@ lib.makeOverridable (
inherit preferLocalBuild meta allowedRequisites;
env = {
NIX_PREFETCH_GIT_CHECKOUT_HOOK = finalAttrs.postCheckout;
};
passthru = {
gitRepoUrl = url;
}
+10
View File
@@ -17,6 +17,16 @@
sha256 = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY=";
};
collect-rev = testers.invalidateFetcherByDrvHash fetchgit {
name = "collect-rev-nix-source";
url = "https://github.com/NixOS/nix";
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
hash = "sha256-AUTX1K7J5+fojvKYJacXYVV5kio3hrWYz5MCekO6h68=";
postCheckout = ''
git -C "$out" rev-parse HEAD | tee "$out/revision.txt"
'';
};
sparseCheckout = testers.invalidateFetcherByDrvHash fetchgit {
name = "sparse-checkout-nix-source";
url = "https://github.com/NixOS/nix";