There seems to be more than one way to ‘cache’ files to reduce the bandwidth consumed by doing a nixos-install or nixos-rebuild. I have now tried two methods with varying levels of success.
My most recent attempt followed this guide from the old unofficial wiki ( my search error
) using NixOS 24.05.
I got to the point where I can successfully add a package (lnav) to my local binary-cache-server
[fsbof@binary-cache-server:/var]$ sudo nix-build '<nixpkgs>' -A pkgs.lnav
this path will be fetched (2.69 MiB download, 9.85 MiB unpacked):
/nix/store/y91bmbdc0zw84fdv5xsghxvy5h7dzcis-lnav-0.11.2
copying path '/nix/store/y91bmbdc0zw84fdv5xsghxvy5h7dzcis-lnav-0.11.2' from 'https://cache.nixos.org'...
/nix/store/y91bmbdc0zw84fdv5xsghxvy5h7dzcis-lnav-0.11.2
…and then add the file to configuration.nix on my client (testclient4), perform a rebuild and see that it appears to ‘copy’ the binary from the local binary-cache-server, even though this client can’t access the Internet at all (for test purposes).
<snip>
building Nix...
building the system configuration...
these 14 derivations will be built:
<snip>
/nix/store/r0zd078qq9rfzkby133gfja2yyfyg1gm-nixos-system-testclient4-30Jun24-1516-lnav_with_no_internet.drv
this path will be fetched (0.00 MiB download, 9.85 MiB unpacked):
/nix/store/y91bmbdc0zw84fdv5xsghxvy5h7dzcis-lnav-0.11.2
building '/nix/store/js4ddnhv0ykw7zi2kx1s9v7frazkqswi-boot.json.drv'...
copying path '/nix/store/y91bmbdc0zw84fdv5xsghxvy5h7dzcis-lnav-0.11.2' from 'http://binary-cache-server.local'...
building '/nix/store/4c0j85j9xjxxiszsy99khwz0if8l22cq-issue.drv'.
<snip>
So far, so good - looks like it does what it should.
So I tried a new install, using the same base-configuration.nix that I used to build both the binary-cache-server and testclient4 before I started following the wiki. My theory being with a similar configuration and being built just days apart, I should see a substantial reduction in bandwidth from the usual circa 1GB.
nixos-install --option substituters \"http://binary-cache-server.local\"
This is where it failed with many errors like this;
warning: ignoring substitute for '/nix/store/ckk16ns9yyy5lk0i1l4xmgghqw055yc2-dbus-1.14.10-dev' from 'http://binary-cache-server.local', as it's not signed by any of the keys in 'trusted-public-keys'
I presume this error is because the files in /nix/store haven’t been signed as they were installed before I did the setup of nginx and nix-serve.
Question 1 : Is there a way to sign all the packages that already exist in /nix/store or to force them to refresh and get signed? ( Of course if this is not the issue, I’m sure I will get schooled appropriately
)
Question 2: The one thing that is also kind of unclear here, if a package is not on the cache, is there a method to get the cache to automatically go and get it, or do I have to manually install/copy it each time? (ie. if I add a package to testclient4, do I need to manually add it to binary-cache-server before I do my rebuild or can I just do the rebuild and binary-cache-server will sort it out!)
I also tried doing this nixos-install --option substituters \"http://binary-cache-server.local https://cache.nixos.org/\" as a test, expecting it to fallback, which it did, but it added nearly 50% to the install time. My Internet access is not great and can be variable …there is far too much copper and not enough fibre it’s diet… so that could have been the issue to and the download was still around 1GB.
Question 3: I guess my last question, is… is the right way to go? The other method I tried was following @Solene’s guide but this was a while ago and my NixOS knowledge has improved considerably since then. Should I go back to that or do something else? ![]()
TIA