about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorLéo Gaspard <leo@gaspard.io>2021-02-21 13:28:00 +0100
committerGitHub <noreply@github.com>2021-02-21 13:28:00 +0100
commit037936b7a307c7399cf0f3d9fabe37ea5b0b8534 (patch)
tree70bcc3737d673b785a808856939bf0042dd9b71c /pkgs
parente3d3643f1b26db3bb9892d7b6e433889ce8c5e60 (diff)
parent0096eb9274b430c8cf1a699c68054972c1845291 (diff)
downloadnixlib-037936b7a307c7399cf0f3d9fabe37ea5b0b8534.tar
nixlib-037936b7a307c7399cf0f3d9fabe37ea5b0b8534.tar.gz
nixlib-037936b7a307c7399cf0f3d9fabe37ea5b0b8534.tar.bz2
nixlib-037936b7a307c7399cf0f3d9fabe37ea5b0b8534.tar.lz
nixlib-037936b7a307c7399cf0f3d9fabe37ea5b0b8534.tar.xz
nixlib-037936b7a307c7399cf0f3d9fabe37ea5b0b8534.tar.zst
nixlib-037936b7a307c7399cf0f3d9fabe37ea5b0b8534.zip
Merge pull request #107322 from sternenseemann/fetch-github-leavedotgit
fetchFromGitHub: also use git if deepClone or leaveDotGit is used
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/build-support/fetchgithub/default.nix20
1 files changed, 14 insertions, 6 deletions
diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix
index 66671dd0a6ae..3f355d10f8a1 100644
--- a/pkgs/build-support/fetchgithub/default.nix
+++ b/pkgs/build-support/fetchgithub/default.nix
@@ -1,17 +1,19 @@
 { lib, fetchgit, fetchzip }:
 
 { owner, repo, rev, name ? "source"
-, fetchSubmodules ? false, private ? false
+, fetchSubmodules ? false, leaveDotGit ? null
+, deepClone ? false, private ? false
 , githubBase ? "github.com", varPrefix ? null
 , ... # For hash agility
-}@args: assert private -> !fetchSubmodules;
+}@args:
 let
   baseUrl = "https://${githubBase}/${owner}/${repo}";
   passthruAttrs = removeAttrs args [ "owner" "repo" "rev" "fetchSubmodules" "private" "githubBase" "varPrefix" ];
   varBase = "NIX${if varPrefix == null then "" else "_${varPrefix}"}_GITHUB_PRIVATE_";
+  useFetchGit = fetchSubmodules || (leaveDotGit == true) || deepClone;
   # We prefer fetchzip in cases we don't need submodules as the hash
   # is more stable in that case.
-  fetcher = if fetchSubmodules then fetchgit else fetchzip;
+  fetcher = if useFetchGit then fetchgit else fetchzip;
   privateAttrs = lib.optionalAttrs private {
     netrcPhase = ''
       if [ -z "''$${varBase}USERNAME" -o -z "''$${varBase}PASSWORD" ]; then
@@ -26,8 +28,14 @@ let
     '';
     netrcImpureEnvVars = [ "${varBase}USERNAME" "${varBase}PASSWORD" ];
   };
-  fetcherArgs = (if fetchSubmodules
-    then { inherit rev fetchSubmodules; url = "${baseUrl}.git"; }
+  fetcherArgs = (if useFetchGit
+    then {
+      inherit rev deepClone fetchSubmodules; url = "${baseUrl}.git";
+    } // lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; }
     else ({ url = "${baseUrl}/archive/${rev}.tar.gz"; } // privateAttrs)
   ) // passthruAttrs // { inherit name; };
-in fetcher fetcherArgs // { meta.homepage = baseUrl; inherit rev; }
+in
+
+assert private -> !useFetchGit;
+
+fetcher fetcherArgs // { meta.homepage = baseUrl; inherit rev; }