Skip to content

Nix doesn't fetch repositories shallowly when told to #5119

Open

Description

@L-as

Describe the bug

nix build 'git+https://github.com/NixOS/nixpkgs?shallow=1#hello' doesn't fetch Nixpkgs shallowly.

Steps To Reproduce

rm -rf "$HOME/.cache/nix/gitv3"
time nix build 'git+https://github.com/NixOS/nixpkgs?shallow=1#hello' # 9 s for me
time git clone https://github.com/NixOS/nixpkgs --depth 1 --single-branch --branch=master # 250 s for me

Since Nix runs git internally, it should take around the same time, disregarding the time it takes to fetch hello from Hydra.

Activity

  1. AleXoundOS commented on Dec 24, 2021

    @AleXoundOS

    Interesting, when did it break? Or was the bug around since the shallow attribute has been introduced?

  2. yajo commented on May 16, 2022

    @yajo
    Contributor

    I think the use case is not reproducible and might be a misconception. Maybe hello or nixpkgs is already on the nix store and there's no need to fetch any sources?

  3. yajo commented on May 19, 2022

    @yajo
    Contributor

    I have been able to check it and it's definitely happening. Big problem here 😢

    It seems this test just checks that nix derivation doesn't contain commit count, not that it's being really shallow:

    [[ $(nix eval --impure --expr "(builtins.fetchTree { type = \"git\"; url = \"file://$TEST_ROOT/shallow\"; ref = \"dev\"; shallow = true; }).revCount or 123") == 123 ]]

  4. ImBearChild commented on Oct 17, 2023

    @ImBearChild

    Well, maybe this parameter can only determine whether shallow clone is "allowed".

    - `shallow` (default: `false`)
    A Boolean parameter that specifies whether fetching a shallow clone is allowed.

    According to the code, it just checks the local git repository if is "shallow repository" or not.

    nix/src/libfetchers/git.cc

    Lines 586 to 590 in e92cac7

    bool isShallow = chomp(runProgram("git", true, { "-C", repoDir, "--git-dir", gitDir, "rev-parse", "--is-shallow-repository" })) == "true";
    if (isShallow && !shallow)
    throw Error("'%s' is a shallow Git repository, but shallow repositories are only allowed when `shallow = true;` is specified.", actualUrl);

    And this parameter is never used when calling "git fetch". So it have no impact on how git fetches remote content.

    runProgram("git", true, { "-C", repoDir, "--git-dir", gitDir, "fetch", "--quiet", "--force", "--", actualUrl, fmt("%s:%s", fetchRef, fetchRef) }, {}, true);

  5. poelzi commented on Oct 20, 2023

    @poelzi
    Member

    nix run also ignores the shallow argument.

    When I tried nix shell "git+https://github.com/r-ryantm/nixpkgs.git?ref=auto-update/rt-tests?shallow=true#rt-tests", it downloaded the full nixpkgs repo. When shallow is supported there, it becomes much easier to test PRs

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions