Skip to content

fetchGit is flaky: sometimes cannot find git revision #10431

@DavHau

Description

@DavHau

Describe the bug

The problem only occurs since nix 2.21.x

fetchGit is flaky on an empty ~/.cache/nix/gitv3 and can often crash like that:

error: Cannot find Git revision '43c751b41d74f96cbbd4e07b7aec9675651e2951' in [...]

Steps To Reproduce

  • Evaluate fetchGit { url="https://github.com/sebastianbergmann/environment.git"; rev = "43c751b41d74f96cbbd4e07b7aec9675651e2951";} on an empty ~/.cache/nix/gitv3 several times in a row.
  • notice that sometimes the fetching works and sometimes it crashes.
  • To speed up the evaluation, you can set shallow=true. It does not affect the outcome.

Here an example with 3 evaluations of the same expression, succeeding 2 times and failing one time.

❯ rm -rf ~/.cache/nix/gitv3

~
❯ nix repl
Nix 2.21.2
Type :? for help.
nix-repl> fetchGit { url="https://github.com/sebastianbergmann/environment.git"; rev = "43c751b41d74f96cbbd4e07b7aec9675651e2951"; }
fatal: unable to access 'https://github.com/sebastianbergmann/environment.git/': Could not resolve host: github.com
warning: could not read HEAD ref from repo at 'https://github.com/sebastianbergmann/environment.git', using 'master'
warning: could not update mtime for file '/home/grmpf/.cache/nix/gitv3/0da421j037zz3w3qxl31dc3r7s84xsrgr7hs25yn3ic0h6iqald1/refs/heads/master': No such file or directory
fatal: Refusing to point HEAD outside of refs/
warning: could not update cached head 'master' for 'https://github.com/sebastianbergmann/environment.git'
{
  lastModified = 1681191566;
  lastModifiedDate = "20230411053926";
  narHash = "sha256-Ttez88NVbtHeT/4AglFTEdsGqLgkKTuvqP7uR4tP7BI=";
  outPath = "/nix/store/391g2lyf8f1014riqpfdbn93s9gjv42h-source";
  rev = "43c751b41d74f96cbbd4e07b7aec9675651e2951";
  revCount = 448;
  shortRev = "43c751b";
  submodules = false;
}



~ took 13s
❯ rm -rf ~/.cache/nix/gitv3

~
❯ nix repl
Nix 2.21.2
Type :? for help.
nix-repl> fetchGit { url="https://github.com/sebastianbergmann/environment.git"; rev = "43c751b41d74f96cbbd4e07b7aec9675651e2951"; }
warning: could not update mtime for file '/home/grmpf/.cache/nix/gitv3/0da421j037zz3w3qxl31dc3r7s84xsrgr7hs25yn3ic0h6iqald1/refs/heads/main': No such file or directory
{
  lastModified = 1681191566;
  lastModifiedDate = "20230411053926";
  narHash = "sha256-Ttez88NVbtHeT/4AglFTEdsGqLgkKTuvqP7uR4tP7BI=";
  outPath = "/nix/store/391g2lyf8f1014riqpfdbn93s9gjv42h-source";
  rev = "43c751b41d74f96cbbd4e07b7aec9675651e2951";
  revCount = 448;
  shortRev = "43c751b";
  submodules = false;
}



~ took 49s
❯ rm -rf ~/.cache/nix/gitv3

~
❯ nix repl
Nix 2.21.2
Type :? for help.
nix-repl> fetchGit { url="https://github.com/sebastianbergmann/environment.git"; rev = "43c751b41d74f96cbbd4e07b7aec9675651e2951"; }
fatal: unable to access 'https://github.com/sebastianbergmann/environment.git/': Could not resolve host: github.com
warning: could not update mtime for file '/home/grmpf/.cache/nix/gitv3/0da421j037zz3w3qxl31dc3r7s84xsrgr7hs25yn3ic0h6iqald1/refs/heads/main': No such file or directory
error:
       … while calling the 'fetchGit' builtin
         at «string»:1:1:
            1| fetchGit { url="https://github.com/sebastianbergmann/environment.git"; rev = "43c751b41d74f96cbbd4e07b7aec9675651e2951"; }
             | ^

       … while fetching the input 'git+https://github.com/sebastianbergmann/environment.git?exportIgnore=1&rev=43c751b41d74f96cbbd4e07b7aec9675651e2951'

       error: Cannot find Git revision '43c751b41d74f96cbbd4e07b7aec9675651e2951' in ref 'refs/heads/main' of repository 'https://github.com/sebastianbergmann/environment.git'! Please make sure that the rev exists on the ref you've specified or add allRefs = true; to fetchGit.

What can be observed is that the warnings raised by nix are not reproducible as well. Though, I could not determine any correlation between the warnings and the outcome.

Expected behavior

nix-env --version output

Additional context

Add any other context about the problem here.

Priorities

Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfetchingNetworking with the outside (non-Nix) world, input lockingregressionSomething doesn't work anymore

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions