2022-01-07 04:07:37 +00:00
|
|
|
{ fetchgit, fetchhg, fetchzip, lib }:
|
2021-03-12 07:09:13 +00:00
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
lib.makeOverridable (
|
2021-03-12 07:09:13 +00:00
|
|
|
{ owner
|
|
|
|
, repo, rev
|
|
|
|
, domain ? "sr.ht"
|
|
|
|
, vc ? "git"
|
|
|
|
, name ? "source"
|
2022-01-07 04:07:37 +00:00
|
|
|
, fetchSubmodules ? false
|
2021-03-12 07:09:13 +00:00
|
|
|
, ... # For hash agility
|
|
|
|
} @ args:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
assert (lib.assertOneOf "vc" vc [ "hg" "git" ]);
|
|
|
|
|
|
|
|
let
|
2023-07-15 17:15:38 +00:00
|
|
|
urlFor = resource: "https://${resource}.${domain}/${owner}/${repo}";
|
|
|
|
baseUrl = urlFor vc;
|
2022-01-07 04:07:37 +00:00
|
|
|
baseArgs = {
|
|
|
|
inherit name;
|
|
|
|
} // removeAttrs args [
|
|
|
|
"owner" "repo" "rev" "domain" "vc" "name" "fetchSubmodules"
|
|
|
|
];
|
|
|
|
vcArgs = baseArgs // {
|
|
|
|
inherit rev;
|
|
|
|
url = baseUrl;
|
|
|
|
};
|
|
|
|
fetcher = if fetchSubmodules then vc else "zip";
|
|
|
|
cases = {
|
|
|
|
git = {
|
|
|
|
fetch = fetchgit;
|
|
|
|
arguments = vcArgs // { fetchSubmodules = true; };
|
|
|
|
};
|
|
|
|
hg = {
|
|
|
|
fetch = fetchhg;
|
|
|
|
arguments = vcArgs // { fetchSubrepos = true; };
|
|
|
|
};
|
|
|
|
zip = {
|
|
|
|
fetch = fetchzip;
|
|
|
|
arguments = baseArgs // {
|
|
|
|
url = "${baseUrl}/archive/${rev}.tar.gz";
|
2022-06-16 17:23:12 +00:00
|
|
|
postFetch = optionalString (vc == "hg") ''
|
2022-01-07 04:07:37 +00:00
|
|
|
rm -f "$out/.hg_archival.txt"
|
|
|
|
''; # impure file; see #12002
|
2023-07-15 17:15:38 +00:00
|
|
|
passthru = {
|
|
|
|
gitRepoUrl = urlFor "git";
|
|
|
|
};
|
2022-01-07 04:07:37 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in cases.${fetcher}.fetch cases.${fetcher}.arguments // {
|
|
|
|
inherit rev;
|
|
|
|
meta.homepage = "${baseUrl}";
|
|
|
|
}
|
2023-05-24 13:37:59 +00:00
|
|
|
)
|