Nix-cache-beacon - mDNS discovery for Nix binary caches

nix-cache-beacon is a binary cache that uses mDNS service discovery to announce & find caches on the local network & races gets against discovered caches, turning your entire network of Nix nodes into a distributed binary cache.

It’s still marked as alpha, but I’ve been using this at home for the last couple of weeks without much issue.

33 Likes

If you have a desktop and a laptop at home. What happens if you use your laptop outside home? Do you have a bunch of timeouts or your home’s caches are just not discovered and thus, are ignored?

The desktop’s cache will be evicted from the pool & not used.
Eviction happens either on TTL timeouts or network failures.

6 Likes

Wow I wanted exactly this the other day. Thanks, I’ll take a look!

btw I was deep into mDNS service discovery a couple years ago and ended up writing my own dns-sd browser, translated from the API that Apple uses: xds-mdns/dnssdbrowser/dnssdbrowser.go at 9124b71103e642d60aec6177df5f35848673d1a9 · bouk/xds-mdns · GitHub

Because I found that all the existing implementations were not quite following the spec (don’t remember the details, it was a while ago). Feel free to steal the code if you’re not happy with the library you’re using

1 Like

Would it make sense if we were able to configure nix-cache-beacon to also look for nix caches that might not always be available. Like when running attic on your lan. So that when we leave home with our laptop, nix doesn’t try to reach those caches for like 5 minutes.

3 Likes

I think things already work the way you want?

If you announce your attic cache on your LAN, and you leave your home the attic cache will be removed from the in-memory cache index.
Later when you get back your attic cache will be rediscovered and added back.

How do you announce your attic cache? I usually put my caches in nix.settings.substituters, but they get unreachable when I left home.

On the machine running attic:

  services.nix-cache-beacon = {
    advert = {
      enable = true;
      port = 8080; # Or whatever port attic is running on
    };
}

And on the other machines:

{
  services.nix-cache-beacon.cache.enable = true;
  nix.settings.substituters = [ "http://localhost:5028" ];
}
3 Likes