Skip to content

fetchTree sets shallow = true #14588

@edolstra

Description

@edolstra

Describe the bug

fetchTree since 358c26f has this ad hoc treatment of the shallow attribute:

        // fetchTree should fetch git repos with shallow = true by default
        if (type == "git" && !params.isFetchGit && !attrs.contains("shallow")) {
            attrs.emplace("shallow", Explicit<bool>{true});
        }

This is bad because it makes fetchTree behave inconsistently with Git repos fetched in other ways. For example, when you add a flake input like

  inputs.nixpkgs = { type = "git"; url = "git@github.com:NixOS/nixpkgs.git"; };

running a build/eval on this flake the first time will result in a cache path like

/home/eelco/.cache/nix/gitv3/1is1wr7j5dq4hnf6yhzrj2d6zv0874crgjrpg5jd9nwnkxzyg1fw

but the second time you get

/home/eelco/.cache/nix/gitv3/1is1wr7j5dq4hnf6yhzrj2d6zv0874crgjrpg5jd9nwnkxzyg1fw-shallow

(i.e. the repo will be cloned again.) This is because fetchTree is only used internally when an input is already locked. Similarly, nix flake metadata git+ssh://git@github.com/NixOS/nixpkgs.git doesn't use fetchTree.

builtins.fetchTree should never mess with the input attributes like this. Doing a shallow clone should be an optimization done in the git fetcher, if appropriate (e.g. if the revCount is already specified).

Steps To Reproduce

Expected behavior

Metadata

Additional context

Checklist


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions