Where to put /nix on a NAS

A suggestion often seen when building NAS is to put your boot drive on a SSD, and to put the rest of your data on HDD.

However on NixOS /nix/store contains both boot files and several miscellaneous build products.
How should we organize your NAS, especially considering I’m planning on using it to prebuild updates both to my pc and for my android via Robotnix.
In particular I want to put some build on the SSD and other on the HDD.
I think that I’m confident enough that How to put your /nix directory on a separate device is not unfamiliar

1 Like

It is unclear what exactly you consider as boot files. If you mean the files required by your bootloader, they will be on your boot partition and do not require accessing your /nix/store. But I assume you talk about the files required for your general system including all services etc. Those are, as you said, mixed up with all other things in /nix/store.

AFAIK nix doesn’t support to split up the store to multiple device. I guess you could build something with an overlay filesystem, where your main store resides on an HDD and for each generation you keep an overlayfs on an SSD which contains exactly the paths referenced by your current system.

That said, in general I would try to avoid running /nix/store on an HDD if you plan to execute builds on that machine and care about performance. Most builds do a lot of tiny random IO operations. Therefore builds will be significantly (if not orders of magnitude) slower than on an SSD

In particular I want to put some build on the SSD and other on the HDD.

If you want to do that, you could just run two nix instances on your server, by for example using two VMs/containers, each of them mounting their /nix/store from a different device. If those need to be synchronized you could setup the SSD-nix to use the HDD-nix as a cache/substituter. Builds would always be executed on the SSD-nix and then pushed to the HDD-nix when finished. You could use the min-free and max-free options on the SSD-nix to enable automatic garbage collection.

1 Like

What about dedicating an entire ssd to a bcache, minus the /boot partition?
What would be its performance?
From what I’ve read there would be not too many problems,but then it would be the first time I’ve used bcache

Interesting. How would one made a container with, say, /mnt as root including /mnt/nix, and to start it on boot

Interesting idea with containers. Just recently I was googling around on how to put /nix/store outside of the root partition, and the common answer was by using an initrd script to mount that partition early enough. Having two instances handles both performance and bootstrapping.

Do you have a pointer to sample code by any chance?