NobbZ / nixos-config

MIT License
231 stars 7 forks source link

/var/lib/ mounts? #814

Closed shishkin closed 4 months ago

shishkin commented 6 months ago

Hi @NobbZ! I came across your config from a discussion on NixOS discourse. I hope you don't mind a quick question.

I noticed something in your setup that I don't understand. In the paperless service you write:

systemd.services.paperless-consumer.after = ["var-lib-paperless.mount"];
systemd.services.paperless-scheduler.after = ["var-lib-paperless.mount"];
systemd.services.paperless-task-queue.after = ["var-lib-paperless.mount"];
systemd.services.paperless-web.after = ["var-lib-paperless.mount"];

Is "var-lib-paperless.mount" the same mount defined in hardware? What is /dev/pool/paperless in that mount?

The background of my curiosity is trying to point systemd service's data directories somewhere else (e.g. mount point of another drive), but I don't understand how to do that in nix. I also don't want to create a partition for each service.

NobbZ commented 6 months ago

mimas has 2 LVM VGs connected. In a quite basic setup. Both are just formed from a single PV, though both contain several (thin) LVs. pool is the VG on the internal disk, while usbpool is on the external HDD:

❯ sudo pvs
[sudo] password for nmelzer: 
  PV         VG      Fmt  Attr PSize    PFree 
  /dev/sda3  pool    lvm2 a--  <914.51g 54.21g
  /dev/sdb3  usbpool lvm2 a--    <1.32t     0 
❯ sudo vgs
  VG      #PV #LV #SN Attr   VSize    VFree 
  pool      1  12   0 wz--n- <914.51g 54.21g
  usbpool   1   5   0 wz--n-   <1.32t     0 
❯ sudo lvs
  LV                    VG      Attr       LSize   Pool      Origin Data%  Meta%  Move Log Cpy%Sync Convert  docker                pool    Vwi-aotz--  40.00g thin-pool        4.19
  gitea                 pool    Vwi-aotz--  20.00g thin-pool        74.36
  grafana               pool    Vwi-aotz--  25.00g thin-pool        4.15
  home                  pool    -wi-ao---- 550.00g
  lvm-test              pool    Vwi-aotz--  20.00g thin-pool        2.21
  lvm-tmp               pool    Vwi-aotz--  50.00g thin-pool        15.98
  paperless             pool    Vwi-aotz--  50.00g thin-pool        3.00
  photoprism            pool    Vwi-a-tz--  25.00g thin-pool        2.08
  prometheus            pool    Vwi-aotz--  25.00g thin-pool        6.42
  root                  pool    -wi-ao----  10.00g
  store                 pool    -wi-ao---- 150.00g
  thin-pool             pool    twi-aotz-- 150.00g                  19.76  17.55
  random                usbpool Vwi-a-tz-- 100.00g usb-thin         25.68
  restic                usbpool Vwi-aotz-- 660.00g usb-thin         66.84
  ums                   usbpool Vwi-aotz-- 600.00g usb-thin         1.76
  usb-thin              usbpool twi-aotz--  <1.32t                  35.42  18.28

And the /dev/pool/paperless is the paperless LV on the pool VG.

.mount units are created by systemd automatically such that you can easily make your services depend on them. This way I ensure that services won't get started before the appropriate mounts happened.

And I have given up on moving the data dirs else where. More and more units get some hardening, and I am bored to figuring out how to escape it for each new service and also having to keep track when hardening options get changed.

Therefore I just mount my data-partitions where systemd expects the data folder.

shishkin commented 6 months ago

I see. Thanks for the explanation. I wasn't familiar with LVM. Thin pools especially seem to be a nice feature.

I also came across bind mounts. Those allow to mount e.g. /data/apps/paperless to /var/lib/paperless (edit: fixed mount source and target). And systemd seems to chown the directory, so /data/apps can be exclusively owned by root, while the service can write to it when running. What do you think of this approach?

NobbZ commented 4 months ago

Yeah, using a larger overal data sink with bind mounts and quota would actually be my next approach to this, though I have to do more research and planning into that. As I always also have to consider snapshotting, which is a capability I do not want to miss for backups.