feat(blog): Add nix-deamon blog and guide.
Change-Id: I46b8632ac2bfa43ccf95bd63d37e08a8f6b0869e Reviewed-on: https://cl.snix.dev/c/snix/+/30244 Autosubmit: Vova Kryachko <v.kryachko@gmail.com> Tested-by: besadii Reviewed-by: Florian Klink <flokli@flokli.de>
This commit is contained in:
parent
7e22d4f55f
commit
57033490de
2 changed files with 187 additions and 0 deletions
118
web/content/docs/guides/local-overlay.md
Normal file
118
web/content/docs/guides/local-overlay.md
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
---
|
||||
title: "Use as a lower store with nix"
|
||||
slug: local-overlay
|
||||
description: ""
|
||||
summary: ""
|
||||
date: 2025-03-21T22:40:33+00:00
|
||||
lastmod: 2025-03-21T22:40:33+00:00
|
||||
draft: false
|
||||
weight: 14
|
||||
toc: true
|
||||
---
|
||||
|
||||
This document describes how to configure `snix` as the lower layer in your
|
||||
[Local Overlay] nix store.
|
||||
|
||||
### Build required `snix` components
|
||||
|
||||
To use this feature you will need to 2 `snix` compontents, for detailed building
|
||||
instructions see [Building]({{< ref "building" >}}).
|
||||
|
||||
```console
|
||||
$ nix-build -A snix.store
|
||||
$ nix-build -A snix.nix-daemon
|
||||
```
|
||||
|
||||
These will provide `snix-store` and `nix-daemon` binaries.
|
||||
|
||||
### Run the `snix` daemon
|
||||
|
||||
`snix daemon` is the component exposing `castore` and `store` data. By default,
|
||||
these live inside `/var/lib/snix`, so make sure it's writable for the user
|
||||
you're executing it with. See `snix-store daemon --help` for customization
|
||||
options. `/var/lib/snix`, you can run `snix-store daemon --help` for
|
||||
customization instructions.
|
||||
|
||||
You can run the daemon with:
|
||||
|
||||
```console
|
||||
$ $(nix-build -A snix.snix-store)/bin/snix-store daemon
|
||||
```
|
||||
|
||||
### Mount the castore onto your file system
|
||||
|
||||
To expose the store paths and their contents as a file system, if can be
|
||||
FUSE-mounted with the following command:
|
||||
|
||||
```console
|
||||
$ $(nix-build -A snix.snix-store)/bin/snix-store mount /path/to/mount
|
||||
```
|
||||
|
||||
This 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
|
||||
|
||||
```console
|
||||
$ $(nix-build -A snix.nix-daemon)/bin/nix-daemon -l /tmp/snix-daemon.sock \
|
||||
--unix-listen-unlink
|
||||
```
|
||||
|
||||
This will launch the `snix` nix-daemon listening on a unix domain socket
|
||||
|
||||
### Create an overlayfs mount
|
||||
|
||||
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:
|
||||
|
||||
```console
|
||||
$ mount --bind /nix /opt/nix
|
||||
```
|
||||
|
||||
```console
|
||||
$ mount -t overlay overlay \
|
||||
-o lowerdir=/path/to/mount \
|
||||
-o upperdir=/opt/nix \
|
||||
/nix
|
||||
```
|
||||
|
||||
### Configure 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.sock
|
||||
```
|
||||
|
||||
#### Personal 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.
|
||||
|
||||
Note that snix's FUSE mount might be performing slower than the native
|
||||
file-system depending on your workload. Please file bugs if you notice obviously
|
||||
bad performance.
|
||||
|
||||
[local overlay]: https://nix.dev/manual/nix/2.26/store/types/experimental-local-overlay-store.html
|
||||
Loading…
Add table
Add a link
Reference in a new issue