Cache misses with binary caching of nix-shell derivations

I wanted to binary cache a nix-shell that I use to provide a LaTeX environment with texlive.combine.

I can’t cache the pkgs.mkShell derivation directly as it’s not buildable, but I can produce a .drv file and query its dependencies:

nix-store -qR --include-outputs $(nix-instantiate shell.nix)

I then sign and nix copy all those store paths to my binary cache.

When testing it out I expected all dependencies to be available in the cache, but that is (to my surprise) not the case.

For example when running nix-shell I see that the texlive-combine package is built locally even though it is in the cache, both the deriver and the output. I manually verified by checking the <hash>.narinfo files. The archives are there, with signatures.

It also downloaded a whole bunch of texlive source packages but not from cache. This is perhaps expected since I’m not caching the recursive build closure and would not happen if I didn’t get a cache miss of the combined texlive package.

I think I can rule out signature or cache config issues since I’ve cleaned the cache during my testing and I get a bunch of cache-hits as well.

Any ideas of what the issue might be or how to investigate this would be very helpful.

Thanks in advance!


For reference this is the shell.nix I used for testing.

let
  pkgs = (import (builtins.fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.09.tar.gz)) {};
  texpkgs = pkgs.texlive.combine {
    inherit (pkgs.texlive) scheme-medium listings lastpage multirow tcolorbox
    draftwatermark everypage biblatex logreq environ trimspaces glossaries
    mfirstuc xfor datatool substr;
  };
in
pkgs.mkShell {
  buildInputs = with pkgs; [ biber texpkgs ];
  shellHook = ''
    echo "Welcome to Nix-shell, run 'latexmk' to build documentation"
    '';
}

1 Like

Could it be because preferLocalBuild is set for combined texlive? That might explain why nix refuses to download a cached build. Although it does not explain why sources are getting cache misses as well. They should be part of the derivation closure (nix-store -qR $(nix-instantiate shell.nix)), right?

Edit:

Issue is that texlive derivation has unspecified allowSubstitutes, which prevents the cache from being used:

...
 "env": {
      "allowSubstitutes": "",
...