Skip to content

Allow performing shallow clones with builtins.fetchGit #4455

Closed

Description

@chrsuser

Is your feature request related to a problem? Please describe.
builtins.fetchGit provides no way to perform a shallow clone, which makes it much more space-efficient to clone large repositories (specifically nixpkgs) where you only want a specific revision.

Describe the solution you'd like
Add an option to builtins.fetchGit to specify the depth when fetching.

Describe alternatives you've considered
n/a

Additional context
n/a

Activity

  1. JojOatXGME commented on Jan 24, 2021

    @JojOatXGME

    GitHub Actions even made --depth 1 the default.1 I think --depth 1 might be a sane default for Nix as well considering its field of application. I guess most builds don't want to look at previous commits. Anyway, I'm not that experienced with Nix yet, so I might be wrong. I assume making it the default would also cause problems with backward compatibility.

  2. edolstra commented on Jan 25, 2021

    @edolstra
    Member

    builtins.fetchTree supports shallow fetches:

    builtins.fetchTree { type = "git"; url = "..."; ref = "..."; shallow = true; }
  3. yajo commented on May 16, 2022

    @yajo
    Contributor

    This matrix chat might be interesting for this problem.

    Summarizing:

    Method builtins.fetchTree builtins.fetchGit nixpkgs.fetchgit
    Requires flakes enabled yes no no
    Requires a hash no no yes (when pure)
    Works with ssh agent (and remotes) yes yes no

    So, sadly, there's no solution that ticks all the boxes. 😕

    Besides, this is very unexpected:

    # nix repl
    Welcome to Nix 2.8.0pre20220318_00a6dab. Type :? for help.
    
    nix-repl> builtins ? fetchTree
    true
    
    nix-repl> builtins.fetchTree{shallow=true;type="git";url="https://github.com/OCA/server-tools";ref="15.0";rev="47d914f73f116882b5fb04e77d64559a7697e5f6";}
    error: experimental Nix feature 'flakes' is disabled; use '--extra-experimental-features flakes' to override

    builtins.fetchTree is available even when not enabled.

  4. aviallon commented on May 23, 2022

    @aviallon

    This matrix chat might be interesting for this problem.

    Summarizing:

    Method builtins.fetchTree builtins.fetchGit nixpkgs.fetchgit
    Requires flakes enabled yes no no
    Requires a hash no no yes (when pure)
    Works with ssh agent (and remotes) yes yes no
    So, sadly, there's no solution that ticks all the boxes. confused

    Besides, this is very unexpected:

    # nix repl
    Welcome to Nix 2.8.0pre20220318_00a6dab. Type :? for help.
    
    nix-repl> builtins ? fetchTree
    true
    
    nix-repl> builtins.fetchTree{shallow=true;type="git";url="https://github.com/OCA/server-tools";ref="15.0";rev="47d914f73f116882b5fb04e77d64559a7697e5f6";}
    error: experimental Nix feature 'flakes' is disabled; use '--extra-experimental-features flakes' to override

    builtins.fetchTree is available even when not enabled.

    The issue, also, is that it requires an experimental feature to be enabled... there doesn't seem to be any mid-term way to have shallow clones yet.

  5. yajo commented on May 24, 2022

    @yajo
    Contributor

    Yes, and besides there's #5119. The shallow cloning feature in fetchTree really doesn't work.

  6. ZoomRmc commented on Aug 4, 2025

    @ZoomRmc

    The issue is closed but it's not solved still.

    ref: #9376 (unfortunately, drafted and stalled), #9402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions