depot/ops/nixos/lib/zfs.nix

32 lines
713 B
Nix

{ lib, config, ... }:
let
inherit (lib) mkOption types mkAfter mkIf;
robCfg = config.services.zfs.rollbackOnBoot;
in
{
options.services.zfs.rollbackOnBoot = {
enable = mkOption {
type = types.bool;
default = false;
};
snapshot = mkOption {
type = types.str;
default = "zpool/local/root@blank";
};
};
config = {
boot.supportedFilesystems = [ "zfs" ];
boot.zfs.devNodes = "/dev/disk/by-partuuid";
services.zfs.autoScrub.enable = true;
services.zfs.autoSnapshot = {
enable = true;
monthly = 1;
};
boot.initrd.postDeviceCommands = mkIf robCfg.enable
(mkAfter ''
zfs rollback -r ${robCfg.snapshot}
'');
};
}