Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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" "fetchSubmodules" "leaveDotGit" "deepClone" ];
14
15 useFetchGit = deepClone || fetchSubmodules || leaveDotGit;
16 fetcher = if useFetchGit then fetchgit else fetchzip;
17
18 gitRepoUrl = "${protocol}://${domain}/${slug}.git";
19
20 fetcherArgs = (if useFetchGit then {
21 inherit rev deepClone fetchSubmodules leaveDotGit;
22 url = gitRepoUrl;
23 } else {
24 url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}";
25
26 passthru = {
27 inherit gitRepoUrl;
28 };
29 }) // passthruAttrs // { inherit name; };
30in
31
32fetcher fetcherArgs // { meta.homepage = "${protocol}://${domain}/${slug}/"; inherit rev; }