1{ lib, fetchgit, fetchzip }:
2
3lib.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
12let
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; };
33in
34
35fetcher fetcherArgs // { meta.homepage = "${protocol}://${domain}/${slug}/"; inherit rev owner repo; }
36)