Precedence with multiple substituters

When you specify a list of substituters, what determines which substituter is tried first?

I am using a list of 3 substituters, one the official cache (https://cache.nixos.org), one primary cache and one backup (which is slow).

For some reason it is always using my backup substituter first. I initially put things in the order Primary, Nix, Backup thinking that putting Backup last that it would prefer the ones at the beginning. However it used up the backup one first. I also tried reversing the order, and also putting the backup in the middle and all had the same effect.

I also verified that if I omit the backup substituter, it pulls from our primary cache just fine.

The nix docs say you can give a list of URLs for substituters, but I cannot find information on which one is chosen.

substituters
A list of URLs of substituters, separated by whitespace. The default is https://cache.nixos.org .

1 Like

I believe they’re tried in order. EDIT: but I had the feeling relatively long time ago – since then there’s new http/2 support, etc.

We found a solution in old docs: the Priority configuration of the cache.

Old docs are here.

Priority

Each binary cache has a priority (defaulting to 50). Binary caches are checked for binaries in order of ascending priority; thus a higher number denotes a lower priority. The binary cache http://cache.nixos.org has priority 40.

This successfully worked for our use case.

It also helped to clear the local cache database as described here.

$ rm $HOME/.cache/nix/binary-cache-v5.sqlite*

In our case with the multiuser setup, we use $ rm /root/.cache/nix/binary-cache-v5.sqlite* since the nix-daemon runs as root.

2 Likes

I stuck with the same problem. My list of substituters have https, ssh, file:// entries but nix always use ssh one. If I keep only https and file:// substituters then it starts to use file:// one. Is there any way to lower down ssh substitutor priority?

Thx.