Check if Attic Binary Cache Working
As I was setting up the Attic binary cache on my Hetzner box, I wondered whether it is actually being utilized by my machines.
First thing to check is whether the cache is even there from the machine that is logged in the Attic cache:
attic cache info main
It should return something like:
Public: false
Public Key: main:yaFFdf36FdfggsdfslqqjfDF
Binary Cache Endpoint: https://cache.example.com/main
API Endpoint: https://cache.example.com/
Store Directory: /nix/store
Priority: 41
Upstream Cache Keys: ["cache.nixos.org-1"]
Retention Period: Global Default
In my case, the endpoint was https://cache.example.commain. Notice the
missing trailing slash. It’s the sign of the server misconfiguration.
The particular fix is in this commit.
Next, let’s build some simple program and push it to the configured cache.
nix build nixpkgs#hello
Push the result to the cache:
attic push --ignore-upstream-cache-filter main result
TIP: Run the command above without --ignore-upstream-cache-filter and
notice the difference.
The reason we are using --ignore-upstream-cache-filter is that the hello
package is already store in on the main NixOS cache, so Attic will not accept
out result.
Check where the result is stored in /nix/store:
readlink result
/nix/store/8qi947kixhz1nw83dkwxm6d0wndprqkj-hello-2.12.2
We can check if it’s on the cache.nixos.org:
nix path-info -r /nix/store/8qi947kixhz1nw83dkwxm6d0wndprqkj-hello-2.12.2 --store https://cache.nixos.org/
Now to access our private cache. curl has a neat option --netrc-file which
allows us to specify the access details for a private endpoint (in clear
text!).
Create a .netrc file with this content:
machine cache.example.com
password <attic_token>
Password here is the token that you can create with atticd-atticadm make-token
command.
Check if hello exists in the cache:
curl --netrc-file .netrc -v https://cache.example.com/main/8qi947kixhz1nw83dkwxm6d0wndprqkj.narinfo
Finally delete .netrc:
rm .netrc