blob: f1789a6a31b0165957b02886c4f95517b5dbe7d3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# This module sets up basic impermenance the way I like to do it on my ZFS
# hosts. It assumes there is a main zpool called rpool, which has a dataset
# `rpool/local/root` mounted at `/`, and that the dataset has an empty dataset
# called `@blank`.
#
# Here is the dataset structure I use:
#
# rpool
# ├── local
# │ ├── nix (atime=off, mountpoint=/nix)
# │ └── root (mountpoint=/)
# └── safe
# ├── home (mountpoint=/home)
# └── persist (mountpoint=/persist)
#
# I usually follow the convention that `rpool/local` isn't backed up and
# `rpool/safe` is.
#
# See: https://grahamc.com/blog/erase-your-darlings/
{lib, ...}: {
# Reset / to empty on boot. This is what achieves the impermenance.
# Unlike the holy book (the linked article), I had to use `postResumeCommands`
# as this is the step where ZFS imports the dataset (but doesnt't mounted it yet).
# See: https://github.com/NixOS/nixpkgs/blob/b681065d0919f7eb5309a93cea2cfa84dec9aa88/nixos/modules/tasks/filesystems/zfs.nix#L627-L659
boot.initrd.postResumeCommands = lib.mkAfter ''
zfs rollback -r rpool/local/root@blank
'';
# Filesystems with mountpoints at `/` and `/nix` are automatically mounted at boot,
# but `/persist` is bespoke, so we have to teach init about that one ourselves.
fileSystems."/persist".neededForBoot = true;
}
|