From 42637c305fe9ca226ed8394cc24a9c1982926ae8 Mon Sep 17 00:00:00 2001 From: Michael Daniels Date: Sat, 27 Sep 2025 12:38:29 -0400 Subject: [PATCH] fetchFromGitHub: use fetchgit when the rootDir option is set This argument was added to fetchgit in #427165, and it's not supported by fetchzip. Co-authored-by: Philip Taron --- doc/build-helpers/fetchers.chapter.md | 9 ++++++++- pkgs/build-support/fetchgithub/default.nix | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/build-helpers/fetchers.chapter.md b/doc/build-helpers/fetchers.chapter.md index 866bde570f8a..a875a009ed74 100644 --- a/doc/build-helpers/fetchers.chapter.md +++ b/doc/build-helpers/fetchers.chapter.md @@ -860,7 +860,14 @@ A number of fetcher functions wrap part of `fetchurl` and `fetchzip`. They are m To use a different GitHub instance, use `githubBase` (defaults to `"github.com"`). -`fetchFromGitHub` uses `fetchzip` to download the source archive generated by GitHub for the specified revision. If `leaveDotGit`, `deepClone` or `fetchSubmodules` are set to `true`, `fetchFromGitHub` will use `fetchgit` instead. Refer to its section for documentation of these options. +By default, `fetchFromGitHub` uses `fetchzip` to download GitHub's source archive for the specified revision. +However, `fetchFromGitHub` will automatically switch to using `fetchgit` in any of these cases: + +- `forceFetchGit`, `leaveDotGit`, `deepClone`, `fetchLFS`, or `fetchSubmodules` are set to `true` +- `sparseCheckout` contains any entries (is a non-empty list) +- `rootDir` is set to a non-empty string + +When `fetchgit` is used, refer to the `fetchgit` section for documentation of its available options. ## `fetchFromGitLab` {#fetchfromgitlab} diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix index 2b3ab060418a..dfe210f32c41 100644 --- a/pkgs/build-support/fetchgithub/default.nix +++ b/pkgs/build-support/fetchgithub/default.nix @@ -18,7 +18,8 @@ lib.makeOverridable ( private ? false, forceFetchGit ? false, fetchLFS ? false, - sparseCheckout ? [ ], + rootDir ? "", + sparseCheckout ? lib.optional (rootDir != "") rootDir, githubBase ? "github.com", varPrefix ? null, meta ? { }, @@ -69,6 +70,7 @@ lib.makeOverridable ( || deepClone || forceFetchGit || fetchLFS + || (rootDir != "") || (sparseCheckout != [ ]); # We prefer fetchzip in cases we don't need submodules as the hash # is more stable in that case.