Use as a lower store with nix
This document describes how to configure snix as the lower layer in your
Local Overlay
nix store.
Run the snix daemon
snix daemon is the component exposing castore and store data. By default,
these live inside /var/lib/snix-{castore,store}, so make sure they are
writable for the user you’re executing it with. See snix store daemon --help
for customization options.
You can run the daemon with:
snix store daemonMount the store
To expose the store paths and their contents as a file system, if can be FUSE-mounted with the following command:
snix store mount /path/to/mountThis mount will talk to the previously invoked daemon.
Note that by default, this mount won’t allow listing files and directories at
the root of the store, if you want to enable it, use the --list-root flag, but
be careful with it if your store is really large.
Run snix nix-daemon
snix nix-daemon -l /tmp/snix-daemon.sock \
--unix-listen-unlinkThis will launch the snix nix-daemon listening on a unix domain socket.
Nix will communicate with it to get metadata about store paths.
Create an overlayfs mount
Caution
Depending on your usecase, this might not be appropriate for a physical NixOS
system, replacing /nix globally.
In these cases, you want to ensure store paths needed to boot the system are available on the plain disk.
You most likely want to mount this combined mountpoint elsewhere, and spin up a
separate mount namespace (via systemd-nspawn, bwrap or similar) exposing it
at /nix in there. You have been warned!
Bind mount your real /nix store on the side, so that nix has direct access to it, this is optional but allows you to have access to your real nix store without unmounting:
mount --bind /nix /opt/nixmount -t overlay overlay \
-o lowerdir=/path/to/mount \
-o upperdir=/opt/nix \
/nixConfigure nix to use the daemon
With all of the above out of the way, we are ready to configure nix. In the proposed setup we will configure nix-daemon with an overlay store but for the Nix CLI you can just configure nix with the overlay store.
nix-daemon
The daemon can be configured in the following way:
Add the following line to your /etc/nix.conf
store = local-overlay://?state=/opt/nix/var/nix&upper-layer=/opt/nix/store&check-mount=false&lower-store=unix%3A%2F%2F%2Ftmp%2Fsnix-daemon.sockPersonal nix config
With the above configuration in your /etc/nix.conf, we need to tell nix not to
use it but instead use store = daemon so that only the daemon is aware of the
Local Overlay Store.
This can be achieved by either setting the env variable
NIX_CONFIG='store = daemon or by adding store = daemon to your
$XDG_CONFIG_HOME/nix.conf file.
Profit
With the above setup you should now be able to have nix use Snix castore as its lower store.
Caution
There are some known (and not yet worked-on) performance issues in Snix castore, which is why the mount is expected to perform slower than the native file-system. Depending on your workload, this might or might not be an issue.
Check our Bug tracker for updates on that topic.