Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
L-as opened this issue Aug 10, 2021 · 5 comments · May be fixed by #9376
Open

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

L-as opened this issue Aug 10, 2021 · 5 comments · May be fixed by #9376
Labels

Comments

@L-as
Copy link
Member

L-as commented Aug 10, 2021

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.

@L-as L-as added the bug label Aug 10, 2021
@AleXoundOS
Copy link

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

@yajo
Copy link
Contributor

yajo commented May 16, 2022

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?

@yajo
Copy link
Contributor

yajo commented May 19, 2022

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:https://$TEST_ROOT/shallow\"; ref = \"dev\"; shallow = true; }).revCount or 123") == 123 ]]

@ImBearChild
Copy link

ImBearChild commented Oct 17, 2023

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);

@poelzi
Copy link
Member

poelzi commented Oct 20, 2023

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

@DavHau DavHau linked a pull request Nov 18, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants