1{
2 lib,
3 repoRevToNameMaybe,
4 fetchgit,
5 fetchzip,
6}:
7
8lib.makeOverridable (
9 # gitlab example
10 {
11 owner,
12 repo,
13 rev ? null,
14 tag ? null,
15 name ? repoRevToNameMaybe repo (lib.revOrTag rev tag) "gitlab",
16 protocol ? "https",
17 domain ? "gitlab.com",
18 group ? null,
19 fetchSubmodules ? false,
20 leaveDotGit ? false,
21 deepClone ? false,
22 forceFetchGit ? false,
23 sparseCheckout ? [ ],
24 ... # For hash agility
25 }@args:
26
27 assert (
28 lib.assertMsg (lib.xor (tag == null) (
29 rev == null
30 )) "fetchFromGitLab requires one of either `rev` or `tag` to be provided (not both)."
31 );
32
33 let
34 slug = lib.concatStringsSep "/" (
35 (lib.optional (group != null) group)
36 ++ [
37 owner
38 repo
39 ]
40 );
41 revWithTag = if tag != null then "refs/tags/" + tag else rev;
42 escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug;
43 escapedRevWithTag = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] revWithTag;
44 passthruAttrs = removeAttrs args [
45 "protocol"
46 "domain"
47 "owner"
48 "group"
49 "repo"
50 "rev"
51 "tag"
52 "fetchSubmodules"
53 "forceFetchGit"
54 "leaveDotGit"
55 "deepClone"
56 ];
57
58 useFetchGit =
59 fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || (sparseCheckout != [ ]);
60 fetcher = if useFetchGit then fetchgit else fetchzip;
61
62 gitRepoUrl = "${protocol}://${domain}/${slug}.git";
63
64 fetcherArgs =
65 (
66 if useFetchGit then
67 {
68 inherit
69 rev
70 deepClone
71 tag
72 fetchSubmodules
73 sparseCheckout
74 leaveDotGit
75 ;
76 url = gitRepoUrl;
77 }
78 else
79 {
80 url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRevWithTag}";
81
82 passthru = {
83 inherit gitRepoUrl;
84 };
85 }
86 )
87 // passthruAttrs
88 // {
89 inherit name;
90 };
91 in
92
93 fetcher fetcherArgs
94 // {
95 meta.homepage = "${protocol}://${domain}/${slug}/";
96 inherit
97 tag
98 owner
99 repo
100 ;
101 rev = revWithTag;
102 }
103)