This stuff is pretty straightforward. I set up automatic snapshots, and SSD TRIM and scrubbing:
{ pkgs, lib, ... }:
{
boot.zfs.devNodes = lib.mkDefault "/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:
{ 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;
}