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

fetchTree performs fetch even when a narHash is provided #10104

Closed
yajo opened this issue Feb 28, 2024 · 2 comments
Closed

fetchTree performs fetch even when a narHash is provided #10104

yajo opened this issue Feb 28, 2024 · 2 comments
Assignees
Labels
bug fetching Networking with the outside (non-Nix) world

Comments

@yajo
Copy link
Contributor

yajo commented Feb 28, 2024

Describe the bug

According to the docs, when you add narHash to a fetchTree call, the result won't be fetched if it's already available:

If `narHash` is set, the source is first looked up is the Nix store and [substituters](@docroot@/command-ref/conf-file.md#conf-substituters), and only fetched if not available.

Well, that's not happening.

Steps To Reproduce

The 1st time you fetch, it downloads ✅:

➤ nix eval --no-eval-cache --debug --expr 'builtins.fetchTree {type="github"; owner="OCA"; repo="account-analytic"; rev="bc8dbde0477634d64915d027093756defcf0ebc3"; narHash="sha256-sD75xS86JRr7q1be+U8FMI7ijDj4tgexlyNGVEa8fpc=";}'
did not find cache entry for '{"rev":"bc8dbde0477634d64915d027093756defcf0ebc3","type":"git-tarball"}'
did not find cache entry for '{"name":"source","type":"tarball","url":"https://github.com/OCA/account-analytic/archive/bc8dbde0477634d64915d027093756defcf0ebc3.tar.gz"}'
did not find cache entry for '{"name":"source","type":"file","url":"https://github.com/OCA/account-analytic/archive/bc8dbde0477634d64915d027093756defcf0ebc3.tar.gz"}'
downloading 'https://github.com/OCA/account-analytic/archive/bc8dbde0477634d64915d027093756defcf0ebc3.tar.gz'...
starting download of https://github.com/OCA/account-analytic/archive/bc8dbde0477634d64915d027093756defcf0ebc3.tar.gz
finished download of 'https://github.com/OCA/account-analytic/archive/bc8dbde0477634d64915d027093756defcf0ebc3.tar.gz'; curl status = 0, HTTP status = 200, body = 1089274 bytes
performing daemon worker op: 39
acquiring write lock on '/nix/var/nix/temproots/575565'
performing daemon worker op: 7
performing daemon worker op: 26
{ lastModified = 1697447248; lastModifiedDate = "20231016090728"; narHash = "sha256-sD75xS86JRr7q1be+U8FMI7ijDj4tgexlyNGVEa8fpc="; outPath = "/nix/store/q3fw9j28hdlyal51xgqlrac9vcb59p2f-source"; rev = "bc8dbde0477634d64915d027093756defcf0ebc3"; shortRev = "bc8dbde"; }
download thread shutting down

The next time you download, it says "using cache entry". That's suspicious 🕵️‍♂️. It shouldn't need any cache because there's a narHash parameter passed:

➤ nix eval --no-eval-cache --debug --expr 'builtins.fetchTree {type="github"; owner="OCA"; repo="account-analytic"; rev="bc8dbde0477634d64915d027093756defcf0ebc3"; narHash="sha256-sD75xS86JRr7q1be+U8FMI7ijDj4tgexlyNGVEa8fpc=";}'
performing daemon worker op: 11
acquiring write lock on '/nix/var/nix/temproots/575669'
performing daemon worker op: 1
using cache entry '{"rev":"bc8dbde0477634d64915d027093756defcf0ebc3","type":"git-tarball"}' -> '{"lastModified":1697447248,"rev":"bc8dbde0477634d64915d027093756defcf0ebc3"}', '/nix/store/q3fw9j28hdlyal51xgqlrac9vcb59p2f-source'
performing daemon worker op: 26
{ lastModified = 1697447248; lastModifiedDate = "20231016090728"; narHash = "sha256-sD75xS86JRr7q1be+U8FMI7ijDj4tgexlyNGVEa8fpc="; outPath = "/nix/store/q3fw9j28hdlyal51xgqlrac9vcb59p2f-source"; rev = "bc8dbde0477634d64915d027093756defcf0ebc3"; shortRev = "bc8dbde"; }

Let's remove cache and retry. We can see how fetches again. ❌ It shouldn't!:

➤ rm -rf ~/.cache/nix

➤ nix eval --no-eval-cache --debug --expr 'builtins.fetchTree {type="github"; owner="OCA"; repo="account-analytic"; rev="bc8dbde0477634d64915d027093756defcf0ebc3"; narHash="sha256-sD75xS86JRr7q1be+U8FMI7ijDj4tgexlyNGVEa8fpc=";}'
did not find cache entry for '{"rev":"bc8dbde0477634d64915d027093756defcf0ebc3","type":"git-tarball"}'
did not find cache entry for '{"name":"source","type":"tarball","url":"https://github.com/OCA/account-analytic/archive/bc8dbde0477634d64915d027093756defcf0ebc3.tar.gz"}'
did not find cache entry for '{"name":"source","type":"file","url":"https://github.com/OCA/account-analytic/archive/bc8dbde0477634d64915d027093756defcf0ebc3.tar.gz"}'
downloading 'https://github.com/OCA/account-analytic/archive/bc8dbde0477634d64915d027093756defcf0ebc3.tar.gz'...
starting download of https://github.com/OCA/account-analytic/archive/bc8dbde0477634d64915d027093756defcf0ebc3.tar.gz
finished download of 'https://github.com/OCA/account-analytic/archive/bc8dbde0477634d64915d027093756defcf0ebc3.tar.gz'; curl status = 0, HTTP status = 200, body = 1089274 bytes
performing daemon worker op: 39
acquiring write lock on '/nix/var/nix/temproots/575717'
performing daemon worker op: 7
performing daemon worker op: 26
{ lastModified = 1697447248; lastModifiedDate = "20231016090728"; narHash = "sha256-sD75xS86JRr7q1be+U8FMI7ijDj4tgexlyNGVEa8fpc="; outPath = "/nix/store/q3fw9j28hdlyal51xgqlrac9vcb59p2f-source"; rev = "bc8dbde0477634d64915d027093756defcf0ebc3"; shortRev = "bc8dbde"; }
download thread shutting down

Expected behavior

When calling with a NAR hash, it shouldn't need to even check the cache. Nix should just check the store and skip the fetching/caching completely.

nix-env --version output
nix-env (Nix) 2.18.1

Additional context

This might be duplicate of #9077 or #9570, but I'm not sure so I open separately.

Priorities

Add 👍 to issues you find important.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-03-04-nix-team-meeting-minute-130/40830/1

@roberth roberth added the fetching Networking with the outside (non-Nix) world label Mar 22, 2024
@edolstra
Copy link
Member

edolstra commented Apr 3, 2024

This appears to have been fixed in Nix 2.19:

$ nix shell nix/2.19.0

$ rm -rf ~/.cache/nix/

$ $ nix eval --no-eval-cache --debug --expr 'builtins.fetchTree {type="github"; owner="OCA"; repo="account-analytic"; rev="bc8dbde0477634d64915d027093756defcf0ebc3"; narHash="sha256-sD75xS86JRr7q1be+U8FMI7ijDj4tgexlyNGVEa8fpc=";}'
evaluating file '/derivation-internal.nix'
performing daemon worker op: 10
using substituted/cached input 'github:OCA/account-analytic/bc8dbde0477634d64915d027093756defcf0ebc3' in '/nix/store/q3fw9j28hdlyal51xgqlrac9vcb59p2f-source'
{ narHash = "sha256-sD75xS86JRr7q1be+U8FMI7ijDj4tgexlyNGVEa8fpc="; outPath = "/nix/store/q3fw9j28hdlyal51xgqlrac9vcb59p2f-source"; rev = "bc8dbde0477634d64915d027093756defcf0ebc3"; shortRev = "bc8dbde"; }

@edolstra edolstra closed this as completed Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fetching Networking with the outside (non-Nix) world
Projects
Archived in project
Development

No branches or pull requests

4 participants