Skip to content

Add error message when git returns non-0 for fetch#13449

Merged
tomberek merged 3 commits intoNixOS:masterfrom
fzakaria:issue-10431
Jul 17, 2025
Merged

Add error message when git returns non-0 for fetch#13449
tomberek merged 3 commits intoNixOS:masterfrom
fzakaria:issue-10431

Conversation

@fzakaria
Copy link
Contributor

@fzakaria fzakaria commented Jul 11, 2025

Users have complained that fetchGit is flaky however the culprit is likely that git fetch was unable itself to download the repository for whatever reason (i.e. poor network etc..)

Nothing was checking the status of git fetch and the error message that would eventually surface to the users were that the commit was not found.

Add explicit error checking for status code from git fetch and return a message earlier on to indicate that the failure was from that point.

fixes #10431

validation

# create netnamespace
> sudo ip netns add no-dns

# enter it
> sudo ip netns exec no-dns zsh

# try to eval
> ./build/src/nix/nix eval --expr ' builtins.fetchGit { url = "https://github.com/intel/ipu6-drivers.git"; ref = "master"; rev =  "b4ba63df5922150ec14ef7f202b3589896e0301a"; }'

warning: you don't have Internet access; disabling some network-dependent features
fatal: unable to access 'https://github.com/intel/ipu6-drivers.git/': Failed to connect to github.com port 443 after 24 ms: Could not connect to server
error:
       … while calling the 'fetchGit' builtin
         at «string»:1:2:
            1|  builtins.fetchGit { url = "https://github.com/intel/ipu6-drivers.git"; ref = "master"; rev =  "b4ba63df5922150ec14ef7f202b3589896e0301a"; }
             |  ^

       … while fetching the input 'git+https://github.com/intel/ipu6-drivers.git?exportIgnore=1&ref=master&rev=b4ba63df5922150ec14ef7f202b3589896e0301a'

  error: Failed to fetch git repository https://github.com/intel/ipu6-drivers.git : fatal: unable to access 'https://github.com/intel/ipu6-drivers.git/': Failed to connect to github.com port 443 after 4 ms: Could not connect to server

This message is different from the previous one that looks like the following when the commit is checked to be in the repo which was causing confusion.

       error: Cannot find Git revision '84956ea0e3ab4cc44919e4a06862644b58c09469' in ref 'refs/heads/flox/remove_recording_struct' of repository 'https://github.com/flox/httpmock.git'! Please make sure that the rev exists on the ref you've specified or add allRefs = true; to fetchGit.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@fzakaria fzakaria requested a review from edolstra as a code owner July 11, 2025 16:35
@github-actions github-actions bot added the fetching Networking with the outside (non-Nix) world, input locking label Jul 11, 2025
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Jul 11, 2025
@fzakaria
Copy link
Contributor Author

@tomberek thanks for the review.
I added a little more code -- since trying to fix the fetchGit demonstrated some more missing cases.

One of the more suprising ones, is that in the presence of "packed-refs", the git fetcher caching functionality breaks.
The reason is because it uses the ref file /refs/heads/master mtime as the tarball TTL.

When packed-refs are enabled this is not present and so code has to be refetched.

This was previously hidden before because the code previously would silently fail on the git fetch but thankfully the cacheDir is the same value and the commit was already present from the prior fetches.... so the code proceeded as normal.
(which was wrong).

Is there an issue for the failure to cache in the presence of packed-refs ?
I'm not sure yet of a solution but that seems problematic for big repositories albeit it only happens if you only specify refs

@fzakaria fzakaria requested a review from tomberek July 11, 2025 21:13
@fzakaria
Copy link
Contributor Author

MacOS failures are "nix-daemon-compat-tests> daemon died unexpectedly"

@fzakaria
Copy link
Contributor Author

I opened #13457 for the caching issue with a test case reproduction to track the failure:
#13456

fzakaria added 3 commits July 16, 2025 08:04
Users have complained that fetchGit is flaky however the culprit is
likely that `git fetch` was unable itself to download the repository for
whatever reason (i.e. poor network etc..)

Nothing was checking the status of `git fetch` and the error message
that would eventually surface to the users were that the commit was not
found.

Add explicit error checking for status code from `git fetch` and return
a message earlier on to indicate that the failure was from that point.

fixes NixOS#10431
@tomberek tomberek merged commit 5ced59a into NixOS:master Jul 17, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fetching Networking with the outside (non-Nix) world, input locking with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fetchGit is flaky: sometimes cannot find git revision

2 participants