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.

Changed files
+14 -2
doc
build-helpers
pkgs
build-support
+6 -1
doc/build-helpers/fetchers.chapter.md
···
: Whether to fetch LFS objects.
+
*`preFetch`* (String)
+
+
: Shell code to be executed before the repository has been fetched, to allow
+
changing the environment the fetcher runs in.
+
*`postFetch`* (String)
-
: Shell code executed after the file has been fetched successfully.
+
: Shell code executed after the repository has been fetched successfully.
This can do things like check or transform the file.
*`leaveDotGit`* (Boolean)
+2
pkgs/build-support/fetchgit/builder.sh
···
echo "exporting $url (rev $rev) into $out"
+
runHook preFetch
+
$SHELL $fetcher --builder --url "$url" --out "$out" --rev "$rev" --name "$name" \
${leaveDotGit:+--leave-dotGit} \
${fetchLFS:+--fetch-lfs} \
+6 -1
pkgs/build-support/fetchgit/default.nix
···
nonConeMode ? false,
name ? null,
nativeBuildInputs ? [ ],
+
# Shell code executed before the file has been fetched. This, in
+
# particular, can do things like set NIX_PREFETCH_GIT_CHECKOUT_HOOK to
+
# run operations between the checkout completing and deleting the .git
+
# directory.
+
preFetch ? "",
# Shell code executed after the file has been fetched
# successfully. This can do things like check or transform the file.
postFetch ? "",
···
server admins start using the new version?
*/
-
assert deepClone -> leaveDotGit;
assert nonConeMode -> (sparseCheckout != [ ]);
let
···
deepClone
branchName
nonConeMode
+
preFetch
postFetch
;
rev = revWithTag;