git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #107322 from sternenseemann/fetch-github-leavedotgit

fetchFromGitHub: also use git if deepClone or leaveDotGit is used

commit037936b7a307c7399cf0f3d9fabe37ea5b0b8534 authorLéo Gaspard <leo@gaspard.io> dateSun 21 Feb 2021, 13:28 (6 years ago) parente3d36430096eb9
2 files changed+18−6
doc/builders/fetchers.chapter.md+4 pkgs/build-support/fetchgithub/default.nix+14−6
doc/builders/fetchers.chapter.md+4
@@ -31,6 +31,8 @@ Used with Subversion. Expects `url` to a Subversion directory, `rev`, and `sha25
3131
3232Used with Git. Expects `url` to a Git repo, `rev`, and `sha256`. `rev` in this case can be full the git commit id (SHA1 hash) or a tag name like `refs/tags/v1.0`.
3333
34+Additionally the following optional arguments can be given: `fetchSubmodules = true` makes `fetchgit` also fetch the submodules of a repository. If `deepClone` is set to true, the entire repository is cloned as opposing to just creating a shallow clone. `deepClone = true` also implies `leaveDotGit = true` which means that the `.git` directory of the clone won't be removed after checkout.
35+
3436## `fetchfossil`
3537
3638Used with Fossil. Expects `url` to a Fossil archive, `rev`, and `sha256`.
@@ -49,6 +51,8 @@ A number of fetcher functions wrap part of `fetchurl` and `fetchzip`. They are m
4951
5052`fetchFromGitHub` expects four arguments. `owner` is a string corresponding to the GitHub user or organization that controls this repository. `repo` corresponds to the name of the software repository. These are located at the top of every GitHub HTML page as `owner`/`repo`. `rev` corresponds to the Git commit hash or tag (e.g `v1.0`) that will be downloaded from Git. Finally, `sha256` corresponds to the hash of the extracted directory. Again, other hash algorithms are also available but `sha256` is currently preferred.
5153
54+`fetchFromGitHub` uses `fetchzip` to download the source archive generated by GitHub for the specified revision. If `leaveDotGit`, `deepClone` or `fetchSubmodules` are set to `true`, `fetchFromGitHub` will use `fetchgit` instead. Refer to its section for documentation of these options.
55+
5256## `fetchFromGitLab`
5357
5458This is used with GitLab repositories. The arguments expected are very similar to fetchFromGitHub above.
pkgs/build-support/fetchgithub/default.nix+14−6
@@ -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; }