Skip to content

Commit d95d372

Browse files
committed
fetchgit: add preFetch hook
This allows running code to change the environment before the nix-prefetch-git script is run. In particular, it allows setting things like NIX_PREFETCH_GIT_CHECKOUT_HOOK, which allows additional code to be run before deleting the .git directory. This also means there's potentially value in performing a deep clone then removing the .git directory, so remove the assertion that prevents doing so.
1 parent ed30f8a commit d95d372

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

doc/build-helpers/fetchers.chapter.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,14 @@ Additionally, the following optional arguments can be given:
773773

774774
: Whether to fetch LFS objects.
775775

776+
*`preFetch`* (String)
777+
778+
: Shell code to be executed before the repository has been fetched, to allow
779+
changing the environment the fetcher runs in.
780+
776781
*`postFetch`* (String)
777782

778-
: Shell code executed after the file has been fetched successfully.
783+
: Shell code executed after the repository has been fetched successfully.
779784
This can do things like check or transform the file.
780785

781786
*`leaveDotGit`* (Boolean)

pkgs/build-support/fetchgit/builder.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
echo "exporting $url (rev $rev) into $out"
88

9+
runHook preFetch
10+
911
$SHELL $fetcher --builder --url "$url" --out "$out" --rev "$rev" --name "$name" \
1012
${leaveDotGit:+--leave-dotGit} \
1113
${fetchLFS:+--fetch-lfs} \

pkgs/build-support/fetchgit/default.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ lib.makeOverridable (
3838
nonConeMode ? false,
3939
name ? null,
4040
nativeBuildInputs ? [ ],
41+
# Shell code executed before the file has been fetched. This, in
42+
# particular, can do things like set NIX_PREFETCH_GIT_CHECKOUT_HOOK to
43+
# run operations between the checkout completing and deleting the .git
44+
# directory.
45+
preFetch ? "",
4146
# Shell code executed after the file has been fetched
4247
# successfully. This can do things like check or transform the file.
4348
postFetch ? "",
@@ -75,7 +80,6 @@ lib.makeOverridable (
7580
server admins start using the new version?
7681
*/
7782

78-
assert deepClone -> leaveDotGit;
7983
assert nonConeMode -> (sparseCheckout != [ ]);
8084

8185
let
@@ -130,6 +134,7 @@ lib.makeOverridable (
130134
deepClone
131135
branchName
132136
nonConeMode
137+
preFetch
133138
postFetch
134139
;
135140
rev = revWithTag;

0 commit comments

Comments
 (0)