diff --git a/doc/build-helpers/fetchers.chapter.md b/doc/build-helpers/fetchers.chapter.md index cfd0730d031c..997f97f81bdb 100644 --- a/doc/build-helpers/fetchers.chapter.md +++ b/doc/build-helpers/fetchers.chapter.md @@ -773,9 +773,14 @@ Additionally, the following optional arguments can be given: : 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) diff --git a/pkgs/build-support/fetchgit/builder.sh b/pkgs/build-support/fetchgit/builder.sh index 0398121aca90..569a67182844 100644 --- a/pkgs/build-support/fetchgit/builder.sh +++ b/pkgs/build-support/fetchgit/builder.sh @@ -6,6 +6,8 @@ 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} \ diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 5145aa83116f..1da8d2591c5b 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -38,6 +38,11 @@ lib.makeOverridable ( 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 ? "", @@ -75,7 +80,6 @@ lib.makeOverridable ( server admins start using the new version? */ - assert deepClone -> leaveDotGit; assert nonConeMode -> (sparseCheckout != [ ]); let @@ -130,6 +134,7 @@ lib.makeOverridable ( deepClone branchName nonConeMode + preFetch postFetch ; rev = revWithTag;