This stuff is pretty straightforward. I set up automatic snapshots, and SSD TRIM and scrubbing:
nix source: :tangle ~/arroyo-nix/nixos/zfs.nix{ pkgs, lib, ... }: { boot.zfs.devNodes = "/dev/mapper"; # (ref:devNodes) boot.zfs.forceImportRoot = false; boot.zfs.forceImportAll = false; # i wonder how much disk this will eat up services.zfs.autoSnapshot = { enable = true; daily = 2; weekly = 2; monthly = 3; }; services.zfs.trim.enable = true; services.zfs.autoScrub.enable = true; imports = [ ./zed.nix # ./zfs-snapshot-activation.nix ]; }
everyone I've seen talk about this sort of just says "oh boot.zfs.devNodes is a thing you do to make virtualization disks work" or whatever, but (devNodes) instructs ZFS to load the underlying physical devices out of /dev/mapper which is where LUKS volumes unvaulted with cryptsetup luksOpen will end up.
Snapshot ZFS volumes when you activate a nixos generation:
I don't do this any more, but i got nerd sniped really hard a while ago by someone asking if this was possible:
nix source: :tangle ~/arroyo-nix/nixos/zfs-snapshot-activation.nix{ config, pkgs, ... }: with pkgs; let mkSnapshotCommand = fsName: fsAttrs: "${config.boot.zfs.package}/bin/zfs snapshot ${fsAttrs.device}@${config.system.nixos.label}-$(date +%s) \n"; eligibleFs = lib.filterAttrs (name: attrs: attrs.fsType == "zfs") config.fileSystems; snapshotCommands = lib.mapAttrsToList mkSnapshotCommand eligibleFs; in { system.activationScripts.zfs-snapshot.text = lib.concatStrings snapshotCommands; }