diff options
author | Linnnus <[email protected]> | 2024-12-21 15:32:01 +0000 |
---|---|---|
committer | Linnnus <[email protected]> | 2024-12-27 09:07:36 +0100 |
commit | 99f77809ea6f5d873c1b8cfd7b4816f877e29316 (patch) | |
tree | 659c28032b21e012973be4880e7c48291af32f83 /shared/nixos | |
parent | 13774af03212266507af7f6b722978dd5db538e5 (diff) |
Add new host omar
Diffstat (limited to 'shared/nixos')
-rw-r--r-- | shared/nixos/zfs-impermenance/default.nix | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/shared/nixos/zfs-impermenance/default.nix b/shared/nixos/zfs-impermenance/default.nix new file mode 100644 index 0000000..f1789a6 --- /dev/null +++ b/shared/nixos/zfs-impermenance/default.nix @@ -0,0 +1,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; +} |