Repository navigation
Description
Describe the bug
The new shallow-by-default fetches introduced in Nix 2.23 do not seem to work with all servers. An example server for which it does not work is git.savannah.gnu.org.
I suspect but have not fully confirmed that it does not work with servers that do not have uploadpack.allowReachableSHA1InWant enabled (this is disabled by default).
Confusingly, the error message is different if allRefs = true is passed (even though https://nix.dev/manual/nix/2.23/release-notes/rl-2.23 says that argument "will be ignored").
Steps To Reproduce
> nix repl
Nix 2.23.1
Type :? for help.
nix-repl> fetchTree { type = "git"; url = "https://git.savannah.gnu.org/git/emms.git"; rev = "cead7b435a679690fd4bbe91fa2f57739a1e0077"; }
error: Server does not allow request for unadvertised object cead7b435a679690fd4bbe91fa2f57739a1e0077
error:
… while calling the 'fetchTree' builtin
at «string»:1:1:
1| fetchTree { type = "git"; url = "https://git.savannah.gnu.org/git/emms.git"; rev = "cead7b435a679690fd4bbe91fa2f57739a1e0077"; }
| ^
… while fetching the input 'git+https://git.savannah.gnu.org/git/emms.git?rev=cead7b435a679690fd4bbe91fa2f57739a1e0077&shallow=1'
error: Cannot find Git revision 'cead7b435a679690fd4bbe91fa2f57739a1e0077' in ref 'refs/heads/master' of repository 'https://git.savannah.gnu.org/git/emms.git'! Please make sure that the rev exists on the ref you've specified or add allRefs = true; to fetchGit.
nix-repl> fetchTree { type = "git"; url = "https://git.savannah.gnu.org/git/emms.git"; rev = "cead7b435a679690fd4bbe91fa2f57739a1e0077"; allRefs = true; }
error:
… while calling the 'fetchTree' builtin
at «string»:1:1:
1| fetchTree { type = "git"; url = "https://git.savannah.gnu.org/git/emms.git"; rev = "cead7b435a679690fd4bbe91fa2f57739a1e0077"; allRefs = true; }
| ^
… while fetching the input 'git+https://git.savannah.gnu.org/git/emms.git?rev=cead7b435a679690fd4bbe91fa2f57739a1e0077&shallow=1'
error: Cannot find Git revision 'cead7b435a679690fd4bbe91fa2f57739a1e0077' in ref 'refs/heads/master' of repository 'https://git.savannah.gnu.org/git/emms.git'! Please make sure that the rev exists on the ref you've specified or add allRefs = true; to fetchGit.
nix-repl> fetchTree { type = "git"; url = "https://git.savannah.gnu.org/git/emms.git"; rev = "cead7b435a679690fd4bbe91fa2f57739a1e0077"; shallow = false; }
{
lastModified = 1718231004;
lastModifiedDate = "20240612222324";
narHash = "sha256-1VTAUBGW3/DggSxFDVuO88G/43IgBhTzwpvFNzqGj8E=";
outPath = "/nix/store/ihyv01mklfqjfq1cq87gq7gaq2fncicl-source";
rev = "cead7b435a679690fd4bbe91fa2f57739a1e0077";
revCount = 1647;
shortRev = "cead7b4";
submodules = false;
}
Notice that when passing allRefs = true, the initial error that "Server does not allow request for unadvertised object" is not printed, making the problem more difficult to troubleshoot.
Passing the current HEAD commit does work. Note I would expect the following to start failing if the repository I'm testing against gets further commits: please update the commit to the current HEAD if that happens. (Other ref tips may also work, I have not experimented with this.)
nix-repl> fetchTree { type = "git"; url = "https://git.savannah.gnu.org/git/emms.git"; rev = "e0331bd7c480b3ac326140bd5b312bfdbc4881c9"; }
{
lastModified = 1719870626;
lastModifiedDate = "20240701215026";
narHash = "sha256-DNbX18xpjXcgMh5aKThKeeqsYVQQnP9YhV0DSetwehs=";
outPath = "/nix/store/vbkrj5qz2kra1y5azkxc3pi0511lsmis-source";
rev = "e0331bd7c480b3ac326140bd5b312bfdbc4881c9";
shortRev = "e0331bd";
submodules = false;
}
Expected behavior
It would be convenient if Nix could fall back to full clones automatically, particularly because otherwise fetching the current head will succeed until the repository gets further commits (which means it is not necessarily obvious when to force shallow = false.
nix-env --version output
nix-env (Nix) 2.23.1
Additional context
The "error: Server does not allow request for unadvertised object" message can also be triggered by using git cli commands:
$ git init test
Initialized empty Git repository in /tmp/test/.git/
$ cd test
$ git remote add origin https://git.savannah.gnu.org/git/emms.git
$ git fetch origin cead7b435a679690fd4bbe91fa2f57739a1e0077
error: Server does not allow request for unadvertised object cead7b435a679690fd4bbe91fa2f57739a1e0077
Nix 2.22 fails the same way with shallow = true forced. I did not check earlier versions.
Priorities
Add 👍 to issues you find important.
Activity
terlar commentedon Jul 12, 2024
I have run into this issue since 2.19. Therefore on CI that works with these repos I have had to pin to 2.18.
Would be nice to find the root of this issue.
nixos-discourse commentedon Jul 15, 2024
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/2024-07-03-nix-team-meeting-minutes-158/49097/1
roberth commentedon Jul 15, 2024
Triaged in team meeting 2024-07-03 (apologies for the delay)
Notes:
Some repos don't support it for legitimate security reasons.
We could add a fallback, by detecting the error message.
This adds latency, so it would be nice to know more
shallow = falseuser input is good, but the initial fetch works, so it's really bad UX to find out later, possibly only on a different host because of cacheIn this specific case, a fixed-output derivation based fetcher may be better, if it's only fetching sources, and not doing
import,readFileor other IFD.Would
shallow = false;be an acceptable solution for this?marienz commentedon Jul 16, 2024
That's been my main pain point. I had to sprinkle several more
shallow = falseover my fetches as more things failed. Between that and the different default <2.23 (adding a "which Nix" variable on top of the "which host" one) I'd argueshallow = truemay be too confusing relative to the network/storage savings it provides to be a good default.(...admittedly only a default for
fetchTree, which is still experimental as a whole...)It's also somewhat inconvenient to check if a host is going to fail in the future (sufficiently so I haven't really tried).
I'm using the built-in fetchers because I don't have hashes for the trees I'm fetching, just commit IDs (correct me if I'm wrong but I think that means I can't easily switch to fixed-output derivations, that'd need something like what's described in #9077?). And I do have IFD shenanigans going on as well (extracting dependencies from the fetched packages so I can fetch/build those).
I'm unfortunately a bit low on cycles to do this research myself soon, but I'd be curious how many popular hosts/forges besides GitHub this does work with... so far, I ended up forcing
shallow = falsefor git.savannah.gnu.org, git.sr.ht, codeberg.org and gitlab.com, but I'd need to do some tinkering to list ones for which it does actually work.If it fails against as many of them as it feels like it does, I'd argue the default should change back (with some notes in the doc around testing with an older rev to confirm
shallow = trueactually works before opting in to the benefits it provides).terlar commentedon Jul 22, 2024
I see, seems
shallow = falsesolved thegit.savannah.gnu.orgissue. I was using it as a flake input and then it was not super clear how to set it, sinceshallow = falseis not allowed in the schema. However, it worked by appendingshallow=0to the flake input url.Perhaps it would be nice to have an explicit shallow option to use for flake inputs?
Revert "fetchTree: shallow git fetching by default"
nixos-discourse commentedon Aug 1, 2024
This pull request has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/2024-07-29-nix-team-meeting-minutes-165/49970/1
Never do shallow fetches