fetchFromSourcehut: add tag as an alternative for rev

This is just for consistency with fetchFromGitHub and fetchFromGitLab
since the URLs used are the same.

Signed-off-by: Marcin Serwin <marcin@serwin.dev>
This commit is contained in:
Marcin Serwin 2025-07-29 17:11:56 +02:00
parent be87108089
commit add1f7b7fe
No known key found for this signature in database
GPG Key ID: DACFAC4EA0B194E0

View File

@ -18,14 +18,21 @@ makeOverridable (
{ {
owner, owner,
repo, repo,
rev, rev ? null,
name ? repoRevToNameMaybe repo rev "sourcehut", tag ? null,
name ? repoRevToNameMaybe repo (lib.revOrTag rev tag) "sourcehut",
domain ? "sr.ht", domain ? "sr.ht",
vc ? "git", vc ? "git",
fetchSubmodules ? false, fetchSubmodules ? false,
... # For hash agility ... # For hash agility
}@args: }@args:
assert (
lib.assertMsg (lib.xor (tag == null) (
rev == null
)) "fetchFromSourcehut requires one of either `rev` or `tag` to be provided (not both)."
);
assert ( assert (
assertOneOf "vc" vc [ assertOneOf "vc" vc [
"hg" "hg"
@ -35,6 +42,7 @@ makeOverridable (
let let
urlFor = resource: "https://${resource}.${domain}/${owner}/${repo}"; urlFor = resource: "https://${resource}.${domain}/${owner}/${repo}";
rev' = if tag != null then tag else rev;
baseUrl = urlFor vc; baseUrl = urlFor vc;
baseArgs = { baseArgs = {
inherit name; inherit name;
@ -43,13 +51,14 @@ makeOverridable (
"owner" "owner"
"repo" "repo"
"rev" "rev"
"tag"
"domain" "domain"
"vc" "vc"
"name" "name"
"fetchSubmodules" "fetchSubmodules"
]; ];
vcArgs = baseArgs // { vcArgs = baseArgs // {
inherit rev; rev = rev';
url = baseUrl; url = baseUrl;
}; };
fetcher = if fetchSubmodules then vc else "zip"; fetcher = if fetchSubmodules then vc else "zip";
@ -69,7 +78,7 @@ makeOverridable (
zip = { zip = {
fetch = fetchzip; fetch = fetchzip;
arguments = baseArgs // { arguments = baseArgs // {
url = "${baseUrl}/archive/${rev}.tar.gz"; url = "${baseUrl}/archive/${rev'}.tar.gz";
postFetch = optionalString (vc == "hg") '' postFetch = optionalString (vc == "hg") ''
rm -f "$out/.hg_archival.txt" rm -f "$out/.hg_archival.txt"
''; # impure file; see #12002 ''; # impure file; see #12002
@ -82,7 +91,7 @@ makeOverridable (
in in
cases.${fetcher}.fetch cases.${fetcher}.arguments cases.${fetcher}.fetch cases.${fetcher}.arguments
// { // {
inherit rev; rev = rev';
meta.homepage = "${baseUrl}"; meta.homepage = "${baseUrl}";
} }
) )