summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc/builders/fetchers.chapter.md9
-rw-r--r--nixos/doc/manual/from_md/release-notes/rl-2205.section.xml9
-rw-r--r--nixos/doc/manual/release-notes/rl-2205.section.md4
-rw-r--r--pkgs/build-support/fetchsourcehut/default.nix45
4 files changed, 56 insertions, 11 deletions
diff --git a/doc/builders/fetchers.chapter.md b/doc/builders/fetchers.chapter.md
index e36724f295f..5b28b2dcb39 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 4a2e86a60b9..5d7b3cf3f51 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.
         </para>
       </listitem>
+      <listitem>
+        <para>
+          <literal>fetchFromSourcehut</literal> now allows fetching
+          repositories recursively using <literal>fetchgit</literal> or
+          <literal>fetchhg</literal> if the argument
+          <literal>fetchSubmodules</literal> is set to
+          <literal>true</literal>.
+        </para>
+      </listitem>
     </itemizedlist>
   </section>
 </section>
diff --git a/nixos/doc/manual/release-notes/rl-2205.section.md b/nixos/doc/manual/release-notes/rl-2205.section.md
index 2a062d0573b..3c1ba344d87 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 ed2f074200c..2b1feaa496e 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}";
+}