complete-computing-environment/zfs-config.org

1.7 KiB

Basic ZFS Configuration

This stuff is pretty straightforward. I set up automatic snapshots, and SSD TRIM and scrubbing:

{ 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 = [ ./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 /rrix/complete-computing-environment/src/branch/main/(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:

{ 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;
}