@@ -1,17 +1,19 @@
11{ lib, fetchgit, fetchzip }:
22
33{ owner, repo, rev, name ? "source"
4−, fetchSubmodules ? false, private ? false
4+, fetchSubmodules ? false, leaveDotGit ? null
5+, deepClone ? false, private ? false
56, githubBase ? "github.com", varPrefix ? null
67, ... # For hash agility
7−}@args: assert private -> !fetchSubmodules;
8+}@args:
89let
910 baseUrl = "https://${githubBase}/${owner}/${repo}";
1011 passthruAttrs = removeAttrs args [ "owner" "repo" "rev" "fetchSubmodules" "private" "githubBase" "varPrefix" ];
1112 varBase = "NIX${if varPrefix == null then "" else "_${varPrefix}"}_GITHUB_PRIVATE_";
13+ useFetchGit = fetchSubmodules || (leaveDotGit == true) || deepClone;
1214 # We prefer fetchzip in cases we don't need submodules as the hash
1315 # is more stable in that case.
14− fetcher = if fetchSubmodules then fetchgit else fetchzip;
16+ fetcher = if useFetchGit then fetchgit else fetchzip;
1517 privateAttrs = lib.optionalAttrs private {
1618 netrcPhase = ''
1719 if [ -z "''$${varBase}USERNAME" -o -z "''$${varBase}PASSWORD" ]; then
@@ -26,8 +28,14 @@ let
2628 '';
2729 netrcImpureEnvVars = [ "${varBase}USERNAME" "${varBase}PASSWORD" ];
2830 };
29− fetcherArgs = (if fetchSubmodules
30− then { inherit rev fetchSubmodules; url = "${baseUrl}.git"; }
31+ fetcherArgs = (if useFetchGit
32+ then {
33+ inherit rev deepClone fetchSubmodules; url = "${baseUrl}.git";
34+ } // lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; }
3135 else ({ url = "${baseUrl}/archive/${rev}.tar.gz"; } // privateAttrs)
3236 ) // passthruAttrs // { inherit name; };
33−in fetcher fetcherArgs // { meta.homepage = baseUrl; inherit rev; }
37+in
38+
39+assert private -> !useFetchGit;
40+
41+fetcher fetcherArgs // { meta.homepage = baseUrl; inherit rev; }