Check if package is available in cache?

hi,

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.

2 Likes

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.)

Alternatively:

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

/nix/store/p635qfcfznbpjqb807ihk6lq1q0y8liv-nixos-system-raisin-21.11.20210628.b55a298


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

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

[nix-shell:~/code/nixcfg]$ curl "https://colemickens.cachix.org/${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.