2021-08-05 21:33:18 +00:00
|
|
|
{ fetchgit, fetchzip, lib }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
lib.makeOverridable (
|
2020-04-24 23:36:52 +00:00
|
|
|
# gitlab example
|
2021-10-28 06:52:43 +00:00
|
|
|
{ owner, repo, rev, protocol ? "https", domain ? "gitlab.com", name ? "source", group ? null
|
2021-08-05 21:33:18 +00:00
|
|
|
, fetchSubmodules ? false, leaveDotGit ? false, deepClone ? false
|
2020-04-24 23:36:52 +00:00
|
|
|
, ... # For hash agility
|
|
|
|
} @ args:
|
|
|
|
|
|
|
|
let
|
2021-08-05 21:33:18 +00:00
|
|
|
slug = lib.concatStringsSep "/" ((lib.optional (group != null) group) ++ [ owner repo ]);
|
|
|
|
escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug;
|
|
|
|
escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] rev;
|
2022-11-04 12:27:35 +00:00
|
|
|
passthruAttrs = removeAttrs args [ "protocol" "domain" "owner" "group" "repo" "rev" "fetchSubmodules" "leaveDotGit" "deepClone" ];
|
2021-08-05 21:33:18 +00:00
|
|
|
|
|
|
|
useFetchGit = deepClone || fetchSubmodules || leaveDotGit;
|
|
|
|
fetcher = if useFetchGit then fetchgit else fetchzip;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
gitRepoUrl = "${protocol}://${domain}/${slug}.git";
|
|
|
|
|
2021-08-05 21:33:18 +00:00
|
|
|
fetcherArgs = (if useFetchGit then {
|
|
|
|
inherit rev deepClone fetchSubmodules leaveDotGit;
|
2022-06-16 17:23:12 +00:00
|
|
|
url = gitRepoUrl;
|
2021-08-05 21:33:18 +00:00
|
|
|
} else {
|
2021-10-28 06:52:43 +00:00
|
|
|
url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}";
|
2022-06-16 17:23:12 +00:00
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit gitRepoUrl;
|
|
|
|
};
|
2021-08-05 21:33:18 +00:00
|
|
|
}) // passthruAttrs // { inherit name; };
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
|
2021-10-28 06:52:43 +00:00
|
|
|
fetcher fetcherArgs // { meta.homepage = "${protocol}://${domain}/${slug}/"; inherit rev; }
|
2023-05-24 13:37:59 +00:00
|
|
|
)
|