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

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

63 lines
1.3 KiB
Nix
Raw Normal View History

{ fetchgit, fetchhg, fetchzip, lib }:
2020-10-31 10:28:06 +00:00
let
inherit (lib)
assertOneOf
makeOverridable
optionalString
;
in
makeOverridable (
2020-10-31 10:28:06 +00:00
{ owner
, repo, rev
, domain ? "sr.ht"
, vc ? "git"
, name ? "source"
, fetchSubmodules ? false
2020-10-31 10:28:06 +00:00
, ... # For hash agility
} @ args:
assert (assertOneOf "vc" vc [ "hg" "git" ]);
2020-10-31 10:28:06 +00:00
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 = {
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-05-17 19:10:33 +00:00
postFetch = optionalString (vc == "hg") ''
rm -f "$out/.hg_archival.txt"
''; # impure file; see #12002
passthru = {
gitRepoUrl = urlFor "git";
};
};
};
};
in cases.${fetcher}.fetch cases.${fetcher}.arguments // {
inherit rev;
meta.homepage = "${baseUrl}";
}
)