{ config, lib, ... }: let cfg = config.os.srv.zfs; in { options.os.srv.zfs.enable = lib.mkEnableOption "enables zfs drive maintnance"; config = lib.mkIf cfg.enable { assertions = [ { assertion = config.os.core.drivers.kernel == "zfs"; message = "ZFS requires the zfs supported kernel"; } { assertion = config.os.srv.sops.enable; message = "required for storing the ntfy token"; } ]; sops.secrets."ntfy/zed".neededForUsers = false; boot = { kernelParams = [ "zfs.zfs_arc_max=${toString (32 * 1024 * 1024 * 1024)}" ]; zfs = { requestEncryptionCredentials = [ "zroot" ]; useKeyringForCredentials = true; extraPools = [ "tank" ]; }; supportedFilesystems = [ "zfs" ]; initrd.supportedFilesystems = [ "zfs" ]; }; services.zfs = { expandOnBoot = "all"; autoScrub.enable = true; trim.enable = true; autoSnapshot = { enable = true; flags = "-k -p --utc"; }; zed = { enableCustomScripts = true; settings = { ZED_DEBUG_LOG = "/var/log/zed.debug.log"; ZED_NOTIFY_INTERVAL_SECS = 3600; ZED_NOTIFY_VERBOSE = 0; ZED_USE_ENCLOSURE_LEDS = 1; ZED_SCRUB_AFTER_RESILVER = 1; ZED_POWER_OFF_ENCLOSURE_SLOT_ON_FAULT = 1; ZED_POWER_OFF_ENCLOSURE_SLOT_ON_DEADMAN = 1; ZED_NTFY_TOPIC = "zed-alerts-bibus-lab"; ZED_NTFY_URL = "http://${config.os.core.network.ips.monitor-vm}:8085"; }; }; }; systemd.services.zfs-zed.serviceConfig.EnvironmentFile = config.sops.secrets."ntfy/zed".path; networking.hostId = "4e3e22e1"; }; }