1{ fetchgit, fetchzip, lib }:
2
3# gitlab example
4{ owner, repo, rev, protocol ? "https", domain ? "gitlab.com", name ? "source", group ? null
5, fetchSubmodules ? false, leaveDotGit ? false, deepClone ? false
6, ... # For hash agility
7} @ args:
8
9let
10 slug = lib.concatStringsSep "/" ((lib.optional (group != null) group) ++ [ owner repo ]);
11 escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug;
12 escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] rev;
13 passthruAttrs = removeAttrs args [ "protocol" "domain" "owner" "group" "repo" "rev" ];
14
15 useFetchGit = deepClone || fetchSubmodules || leaveDotGit;
16 fetcher = if useFetchGit then fetchgit else fetchzip;
17
18 fetcherArgs = (if useFetchGit then {
19 inherit rev deepClone fetchSubmodules leaveDotGit;
20 url = "${protocol}://${domain}/${slug}.git";
21 } else {
22 url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}";
23 }) // passthruAttrs // { inherit name; };
24in
25
26fetcher fetcherArgs // { meta.homepage = "${protocol}://${domain}/${slug}/"; inherit rev; }