core/pkgs/build-support/fetchsourcehut/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

85 lines
1.5 KiB
Nix
Raw Normal View History

2024-05-02 00:46:19 +00:00
{
fetchgit,
fetchhg,
fetchzip,
lib,
}:
let
inherit (lib) assertOneOf makeOverridable optionalString;
in
makeOverridable (
{
owner,
repo,
rev,
domain ? "sr.ht",
vc ? "git",
name ? "source",
fetchSubmodules ? false,
... # For hash agility
}@args:
assert (
assertOneOf "vc" vc [
"hg"
"git"
]
);
let
urlFor = resource: "https://${resource}.${domain}/${owner}/${repo}";
baseUrl = urlFor vc;
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 = {
2024-06-30 08:16:52 +00:00
git = {
2024-05-02 00:46:19 +00:00
fetch = fetchgit;
arguments = vcArgs // {
fetchSubmodules = true;
};
2024-06-30 08:16:52 +00:00
};
hg = {
2024-05-02 00:46:19 +00:00
fetch = fetchhg;
arguments = vcArgs // {
fetchSubrepos = true;
};
2024-06-30 08:16:52 +00:00
};
2024-05-02 00:46:19 +00:00
zip = {
fetch = fetchzip;
arguments = baseArgs // {
url = "${baseUrl}/archive/${rev}.tar.gz";
postFetch = optionalString (vc == "hg") ''
rm -f "$out/.hg_archival.txt"
''; # impure file; see #12002
passthru = {
gitRepoUrl = urlFor "git";
2024-06-30 08:16:52 +00:00
};
2024-05-02 00:46:19 +00:00
};
};
};
in
cases.${fetcher}.fetch cases.${fetcher}.arguments
// {
inherit rev;
meta.homepage = "${baseUrl}";
}
)