{ flake.modules.nixos.base = { config, lib, pkgs, ... }: let cfg = config.infra.zfs; in { options.infra.zfs = { pool = lib.mkOption { type = lib.types.str; description = "The name of the ZFS pool."; }; reservation = lib.mkOption { type = lib.types.strMatching "[0-9]+[KMGTP]?"; description = "The amount of space to reserve for the reservation dataset."; default = "10G"; }; }; config = { boot = { kernelPackages = pkgs.linuxPackages_7_0; zfs.forceImportRoot = false; }; assertions = let expectedZfsVersion = "2.4.2"; in [ { assertion = pkgs.zfs.version == expectedZfsVersion; message = '' ZFS version is ${pkgs.zfs.version}, expected ${expectedZfsVersion}. Check the latest supported kernel version at https://github.com/openzfs/zfs/releases and update `boot.kernelPackages` in modules/zfs.nix if needed as well as this assertion. ''; } ]; disko.devices.zpool."${cfg.pool}" = { type = "zpool"; rootFsOptions = { acltype = "posix"; atime = "off"; canmount = "off"; compression = "zstd-3"; dnodesize = "auto"; setuid = "off"; xattr = "sa"; normalization = "formD"; utf8only = "on"; }; datasets = { reservation = { type = "zfs_fs"; options = { reservation = cfg.reservation; mountpoint = "legacy"; }; }; "local/nix" = { type = "zfs_fs"; mountpoint = "/nix"; options = { canmount = "on"; mountpoint = "legacy"; }; mountOptions = [ "nosuid" "nodev" ]; }; "local/root" = { type = "zfs_fs"; mountpoint = "/"; options = { canmount = "on"; mountpoint = "legacy"; }; postCreateHook = '' zfs snapshot "${cfg.pool}/local/root@blank" ''; mountOptions = [ "nosuid" "nodev" ]; }; "persist" = { type = "zfs_fs"; mountpoint = "/persist"; options = { canmount = "on"; mountpoint = "legacy"; }; mountOptions = [ "nosuid" "nodev" ]; }; }; }; }; }; }