NixOS / NixOS/nix

nix commands shouldn't cache remote git refs

Open
#6,830 20 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
17.7k
Forks
2k
Avg merge
1d 16h
Merged PRs (30d)
80

Description

Describe the bug

In some situations, nix appears to cache the revision information for remote git repositories when it (arguably) shouldn't.

Steps To Reproduce

  1. Create a flake repository, push the initial commit.
  2. Run any of the following commands:
    • nix flake prefetch 'github:repo/name'
    • nix flake metadata 'github:repo/name'
    • nix build 'github:repo/name'
    • nix run 'github:repo/name'
  3. Make some changes in the repository, commit and push them
  4. Run any of the commands in (2) again.
  5. Observe, that all the commands use the old commit revision instead of checking if the master HEAD was updated.
  6. Run these commands with -vvvv and note the following lines:
    using cache entry '{"name":"source","type":"file","url":"https://api.github.com/repos/repo/name/commits/HEAD"}' -> '{"etag":"W/\"<redacted>\"","url":"https://api.github.com/repos/repo/name/commits/HEAD"}', '/nix/store/<redacted>-source'
    HEAD revision for 'https://api.github.com/repos/repo/name/commits/HEAD' is <old-commit-sha>
    

Expected behavior

nix commands should not cache the ref revision information.

nix-env --version output

nix-env (Nix) 2.8.1

P.S. This is not a GitHub-specific issue. The same problem happens with gitlab:repo/name and 'git+https://github.com/repo/name'.

P.P.S. Turns out, this is not HEAD or master specific either. github:repo/name?ref=other and git+https://github.com/repo/name?ref=other are also apparently cached.

P.P.P.S. The caching seems to expire on its own after some time which makes the current behaviour extra confusing.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the listed nix flake prefetch, metadata, build, and run commands, using -vvvv to inspect the remote Git cache entry. Trace how the HEAD or ref revision is resolved and cached; done means repeated commands check the current remote revision instead of using an expired-looking cached one.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, git
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.