From b97ccaa18d61b888b00513c0754745c27c36b293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Sat, 4 Dec 2021 23:01:49 +0700 Subject: [PATCH] fetchFromSourcehut: allow recursive fetching --- doc/builders/fetchers.chapter.md | 9 +++- .../from_md/release-notes/rl-2205.section.xml | 9 ++++ .../manual/release-notes/rl-2205.section.md | 4 ++ pkgs/build-support/fetchsourcehut/default.nix | 45 ++++++++++++++----- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/doc/builders/fetchers.chapter.md b/doc/builders/fetchers.chapter.md index e36724f295f9..5b28b2dcb398 100644 --- a/doc/builders/fetchers.chapter.md +++ b/doc/builders/fetchers.chapter.md @@ -82,4 +82,11 @@ This is used with repo.or.cz repositories. The arguments expected are very simil ## `fetchFromSourcehut` {#fetchfromsourcehut} -This is used with sourcehut repositories. The arguments expected are very similar to fetchFromGitHub above. Don't forget the tilde (~) in front of the user name! +This is used with sourcehut repositories. Similar to `fetchFromGitHub` above, +it expects `owner`, `repo`, `rev` and `sha256`, but don't forget the tilde (~) +in front of the username! Expected arguments also include `vc` ("git" (default) +or "hg"), `domain` and `fetchSubmodules`. + +If `fetchSubmodules` is `true`, `fetchFromSourcehut` uses `fetchgit` +or `fetchhg` with `fetchSubmodules` or `fetchSubrepos` set to `true`, +respectively. Otherwise the fetcher uses `fetchzip`. diff --git a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml index 4a2e86a60b92..5d7b3cf3f515 100644 --- a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml +++ b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml @@ -310,6 +310,15 @@ files. + + + fetchFromSourcehut now allows fetching + repositories recursively using fetchgit or + fetchhg if the argument + fetchSubmodules is set to + true. + + diff --git a/nixos/doc/manual/release-notes/rl-2205.section.md b/nixos/doc/manual/release-notes/rl-2205.section.md index 2a062d0573b5..3c1ba344d873 100644 --- a/nixos/doc/manual/release-notes/rl-2205.section.md +++ b/nixos/doc/manual/release-notes/rl-2205.section.md @@ -116,3 +116,7 @@ In addition to numerous new and upgraded packages, this release has the followin - The `services.stubby` module was converted to a [settings-style](https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md) configuration. - The option `services.duplicati.dataDir` has been added to allow changing the location of duplicati's files. + +- `fetchFromSourcehut` now allows fetching repositories recursively + using `fetchgit` or `fetchhg` if the argument `fetchSubmodules` + is set to `true`. diff --git a/pkgs/build-support/fetchsourcehut/default.nix b/pkgs/build-support/fetchsourcehut/default.nix index ed2f074200cd..2b1feaa496e4 100644 --- a/pkgs/build-support/fetchsourcehut/default.nix +++ b/pkgs/build-support/fetchsourcehut/default.nix @@ -1,10 +1,11 @@ -{ fetchzip, lib }: +{ fetchgit, fetchhg, fetchzip, lib }: { owner , repo, rev , domain ? "sr.ht" , vc ? "git" , name ? "source" +, fetchSubmodules ? false , ... # For hash agility } @ args: @@ -14,12 +15,36 @@ assert (lib.assertOneOf "vc" vc [ "hg" "git" ]); let baseUrl = "https://${vc}.${domain}/${owner}/${repo}"; - -in fetchzip (recursiveUpdate { - inherit name; - url = "${baseUrl}/archive/${rev}.tar.gz"; - meta.homepage = "${baseUrl}/"; - extraPostFetch = optionalString (vc == "hg") '' - rm -f "$out/.hg_archival.txt" - ''; # impure file; see #12002 -} (removeAttrs args [ "owner" "repo" "rev" "domain" "vc" ])) // { inherit rev; } + 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"; + extraPostFetch = optionalString (vc == "hg") '' + rm -f "$out/.hg_archival.txt" + ''; # impure file; see #12002 + }; + }; + }; +in cases.${fetcher}.fetch cases.${fetcher}.arguments // { + inherit rev; + meta.homepage = "${baseUrl}"; +}