Check if package is available in cache?


simple question here, how can I check if a package in a flake is available in a cache ?

I would like a way that can just check the exitcode of a command, the different posts I see require reading the logs.


So my strategy is:

  • run nix-build-uncached with -j0
  • success means it didn’t want to build anything (aka every out was in a cache)

You could throw flags at it to look at only one cache or multiple depending on what you need.

(Do note that n-b-u is in fact doing this by reading the stdout/err as you rightly want to avoid.)


[nix-shell:~/code/nixcfg]$ nix eval --raw ".#toplevels.raisin.outPath"
trace: warning: `virtualisation.containerd.configFile` is deprecated. use `virtualisation.containerd.settings` instead.


[nix-shell:~/code/nixcfg]$ hash="$(\
  nix eval --raw .#toplevels.raisin.outPath \
    | cut -d '/' -f4 | cut -d '-' -f1)"

[nix-shell:~/code/nixcfg]$ echo "${hash}"

[nix-shell:~/code/nixcfg]$ curl "${hash}.narinfo"
# spews the narinfo out

thanks ! I wanted to check against a s3 bucket so I used aws s3api head-object --bucket bucketname --key 22ir11cbp0zzgpjdk6if2kly7p09fkk1.narinfo instead.