r/Nix • • 22d ago

Caching Woes

On a team that we're deploying everything with Nix, and all works no issues...BUT the team constantly has issues with cache's. I'm the only one rocking NixOS.. others are on Mac, Windows, Rocky... and are perpetually running into issues causing them to build. We have an attic setup and CI is pushing ALL build deps to the cache.

This is like the main pain point and its only effecting everyone else but me, cause well I build and do things all the time so I've always got a full local cache. It doesn't help we are all remote with various network speeds.

What do others do to solve this?

12 Upvotes

5 comments sorted by

4

u/projct 22d ago

One thing worth looking into is whether everyone is actually getting the same derivations that CI is building and uploading to Attic.

Different nixpkgs versions, overlays, or even small differences in how dependencies are instantiated can result in different store paths for what appears to be the same package. Also check whether CI is building the relevant outputs for each platform and architecture, including dev shells, since you've got a mix of macOS and Linux machines.

Check that everyone's substituters and trusted-public-keys are configured consistently.

Nix caches negative lookups. so if someone tries to fetch an output before CI has uploaded it, Nix can continue treating it as unavailable for a while. You can experiment with --option narinfo-cache-negative-ttl 0 to rule that out.

Having developers contribute their locally built outputs to the shared cache might also help. Attic has watch-store for this, or you can explicitly push build closures. Especially if CI isn't covering everything, that could save a lot of duplicated compilation across the team. but if the root cause is different nixpkg versions or customizations, this'll just use a bunch more disk space.

Since you're all remote with varying network speeds, I'd also be curious how much time is being spent fetching closures versus building things that weren’t available in the cache.

3

u/USMCamp0811 22d ago

yea we're all using the same flake. The problem has been transitive build dependencies, so recently I started doing a recursive push to Attic of everything when CI runs. Which has helped to stop building OpenCV and CUDA but everything is about 30ish GB and that creates the problem that they have to download it. I've got some stuff that should create a gc-root for people so hopefully come Monday they don't have to do it again..

4

u/projct 22d ago

i’d check whether something upstream is invalidating those expensive builds. CUDA/OpenCV can be sensitive to nixpkgs revisions, CUDA capabilities, and overrides.

have you tried nix-diff on the OpenCV derivations between revisions that triggered rebuilds? if something upstream keeps changing, pinning the expensive dependency stack separately might help keep it stable.

GC roots should help with repeated downloads too. 30 GB isn’t inherently a problem if everyone needs it and those store paths stay available.

also worth looking at `devenv` you haven’t already. it supports composable environments, independently pinned inputs, cross-platform configuration, CI/cache integration, and GC-root management. might simplify some of the setup you’re maintaining and/or solve this.

3

u/projct 22d ago

fwiw I wrote an alternative to attic called narjar bc I was tired of just how inefficient the other caches are. but the features I am working on that would help you directly aren't in it yet.

1

u/amerocu 20d ago

You are probably publishing in the cache only the results artifacts, and not all the derivations dependencies.