Nix rebuilds instead of downloading from substituters

I am running nix on a ubuntu in a virtualbox to test the reproducibility of this webpage:

In my (nonvirtual) machine, running NixOS, the line
nix-shell --run cachedMake # Wait about one minute takes about 1s.
Because in fact it runs nix-build (without arguments), which downloads a cached result and copies some files around.

However in my virtual machine, running the whole installation procedure, install cachix, adding caches anf finally the Work! section. The invocation of nix-build does not download but rebuilds, as if it did not find the derivation in cachix. However, reading the log, it does look at the right cachix cache, and it is still in the cache as I write these lines:

$ curl https://math-comp.cachix.org/bgbmz6z0igxvkang42h8by66ndii8y9n.narinfo
StorePath: /nix/store/bgbmz6z0igxvkang42h8by66ndii8y9n-coq8.13-mathcomp-dev
URL: nar/a805a5d6509bc348cae7242cf36eda56906496eb58b3732e840b9116e4b15eed.nar.xz
Compression: xz
FileHash: sha256:a805a5d6509bc348cae7242cf36eda56906496eb58b3732e840b9116e4b15eed
FileSize: 26784608
NarHash: sha256:1g5cpv5yjjdqzbrhy37vimr0fnl5g1f4p93mhgq5irs18nxgk9q7
NarSize: 90879312
References: 
Deriver: rqsqskn621wvcsc70q9i3xqyj788qcpi-coq8.13-mathcomp-dev.drv
Sig: math-comp.cachix.org-1:kT1lhjNUCyLoy0DYGp3OQQ50e3u8RQLqHfxpI9xtN9dsb40qQJmHHRBuko0smU5Rb47PdirgeHQ7mZrBkpcxCw==

(and it was indeed stored in a github action run)

So why would it rebuild it instead of downloading it?

1 Like

I retried today, without changing anything, and it works perfectly… I’m quite puzzled…

I wrote a section on how to debug this, let me know if there’s something missing!

https://docs.cachix.org/faq.html#why-is-nix-not-picking-up-on-any-of-the-pre-built-artifacts

3 Likes

I might have an idea of what is going wrong but first I have a few questions. You talk about calling nix-build but the command you show is nix-shell which might be relevant since they don’t work exactly the same especially when it comes to caching. It is also not clear from either your log or your wiki entry how you populate the cache.

The difference between the two commands is that nix-shell deals with a development environment and build dependencies while the output derivation from nix-build only includes the runtime dependencies. So if you cache something with nix-build default.nix | cachix push mycache it will only cache the build result and runtime dependencies. The reason it works now might be because the cachix github action caches all things built during the run.

Actually I am really calling nix-build (the reason for the nix-shell is just to get a shellHook that calls nix-build and does extra stuff)

The cache is populated from a github action (using cachix with authToken) using a build that is supposed to cover the one in the shellHook (I made sure that it was indeed cached at some point during my attempts).

Thanks! I did not know about the negative cache. Since rebooting my virtual machine did not help, I guess that is what happened.

I really hope we fix nix-cache-info setting for negative narinfo cache · Issue #4478 · NixOS/nix · GitHub as this will solve problems like this for newcomers.

1 Like

I managed to reproduce the problem by trying nix-build slightly to early… and then rm $HOME/.cache/nix/binary-cache-v*.sqlite* did indeed solve the problem.
Thank you!

1 Like

@CohenCyril I wonder, how many hours did you lose because of this?

Maybe one or two hours…

1 Like