Nix-channel --update on isolated system

So when I tried to use a binary cache, I kept finding that whenever I ran nix-channel --update, it kept trying to reach out to cache.nixos.org for https://cache.nixos.org/zh0yr18j8vr77is99mj01yxwmf2cy4xn.narinfo instead of http://cache.example.com, which is my binary cache which is hosted locally on my network, even when I pointed it to the right URL where I stored the nixexprs.tar.xz accessible from within the network. It is a simple nginx reverse proxy like: FAQ/Private Cache Proxy - NixOS Wiki

I tried the following to stop it from doing that:

  • nix-channel --update --option substituters http://cache.example.com/
  • NIX_SUBSTITUTERS='http://cache.example.com/' nix-channel --update
  • nix-channel --update --option binary-caches http://cache.example.com/

The ONLY way to do it is to rebuild the system with the following enabled:

nix.settings.substituters = lib.mkForce [ "http://hub-prod-nixcache.hub.andrewcz.com/" ];

As shown here: With nix options changes, first substituter is always cache.nixos.org · Issue #158356 · NixOS/nixpkgs · GitHub

And then only after running nixos-rebuild --option substituters http://cache.example.com/ switch would nix-channel --update succeed. (FWIW, I already was able to host the nixexprs.tar.xz needed to point to the right derivations. Since this was offline except for the cache servers, this was necessary to host on that same nginx server.)

It’s not ideal to rebuild the system (these are servers) before updating the list of packages, but as long as my base image isn’t too old, it works. (I’ll have to update from 23.11 soon haha)

EDIT: Looks like the fix for https://discourse.nixos.org/t/cache-nixos-org-is-unreachable/28770https://discourse.nixos.org/t/cache-nixos-org-is-unreachable/28770 too

Hi

nix.settings.substituters = lib.mkForce [ "http://hub-prod-nixcache.hub.andrewcz.com/?priority=10" ];

should do the trick. See also: Setting up a private Nix cache for fun and profit

1 Like