|
1 | | -{ lib, fetchgit, fetchzip }: |
| 1 | +{ |
| 2 | + lib, |
| 3 | + fetchgit, |
| 4 | + fetchzip, |
| 5 | +}: |
2 | 6 |
|
3 | 7 | lib.makeOverridable ( |
4 | | -# gitlab example |
5 | | -{ owner, repo, rev, protocol ? "https", domain ? "gitlab.com", name ? "source", group ? null |
6 | | -, fetchSubmodules ? false, leaveDotGit ? false |
7 | | -, deepClone ? false, forceFetchGit ? false |
8 | | -, sparseCheckout ? [] |
9 | | -, ... # For hash agility |
10 | | -} @ args: |
11 | | - |
12 | | -let |
13 | | - slug = lib.concatStringsSep "/" ((lib.optional (group != null) group) ++ [ owner repo ]); |
14 | | - escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug; |
15 | | - escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] rev; |
16 | | - passthruAttrs = removeAttrs args [ "protocol" "domain" "owner" "group" "repo" "rev" "fetchSubmodules" "forceFetchGit" "leaveDotGit" "deepClone" ]; |
17 | | - |
18 | | - useFetchGit = fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || (sparseCheckout != []); |
19 | | - fetcher = if useFetchGit then fetchgit else fetchzip; |
20 | | - |
21 | | - gitRepoUrl = "${protocol}://${domain}/${slug}.git"; |
22 | | - |
23 | | - fetcherArgs = (if useFetchGit then { |
24 | | - inherit rev deepClone fetchSubmodules sparseCheckout leaveDotGit; |
25 | | - url = gitRepoUrl; |
26 | | - } else { |
27 | | - url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}"; |
28 | | - |
29 | | - passthru = { |
30 | | - inherit gitRepoUrl; |
31 | | - }; |
32 | | - }) // passthruAttrs // { inherit name; }; |
33 | | -in |
34 | | - |
35 | | -fetcher fetcherArgs // { meta.homepage = "${protocol}://${domain}/${slug}/"; inherit rev owner repo; } |
| 8 | + # gitlab example |
| 9 | + { |
| 10 | + owner, |
| 11 | + repo, |
| 12 | + rev ? null, |
| 13 | + tag ? null, |
| 14 | + protocol ? "https", |
| 15 | + domain ? "gitlab.com", |
| 16 | + name ? "source", |
| 17 | + group ? null, |
| 18 | + fetchSubmodules ? false, |
| 19 | + leaveDotGit ? false, |
| 20 | + deepClone ? false, |
| 21 | + forceFetchGit ? false, |
| 22 | + sparseCheckout ? [ ], |
| 23 | + ... # For hash agility |
| 24 | + }@args: |
| 25 | + |
| 26 | + assert ( |
| 27 | + lib.assertMsg (lib.xor (tag == null) ( |
| 28 | + rev == null |
| 29 | + )) "fetchFromGitLab requires one of either `rev` or `tag` to be provided (not both)." |
| 30 | + ); |
| 31 | + |
| 32 | + let |
| 33 | + slug = lib.concatStringsSep "/" ( |
| 34 | + (lib.optional (group != null) group) |
| 35 | + ++ [ |
| 36 | + owner |
| 37 | + repo |
| 38 | + ] |
| 39 | + ); |
| 40 | + escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug; |
| 41 | + escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] ( |
| 42 | + if tag != null then "refs/tags/" + tag else rev |
| 43 | + ); |
| 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=${escapedRev}"; |
| 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 | + rev |
| 99 | + owner |
| 100 | + repo |
| 101 | + ; |
| 102 | + } |
36 | 103 | ) |
0 commit comments