diff --git a/nixos/modules/tasks/filesystems/zfs.nix b/nixos/modules/tasks/filesystems/zfs.nix index b750820bfa50..59676e996785 100644 --- a/nixos/modules/tasks/filesystems/zfs.nix +++ b/nixos/modules/tasks/filesystems/zfs.nix @@ -326,30 +326,36 @@ in }; }; - services.zfs.zed.settings = mkOption { - type = with types; attrsOf (oneOf [ str int bool (listOf str) ]); - example = literalExample '' - { - ZED_DEBUG_LOG = "/tmp/zed.debug.log"; + services.zfs.zed = { + enableMail = mkEnableOption "ZED's ability to send emails" // { + default = cfgZfs.package.enableMail; + }; - ZED_EMAIL_ADDR = [ "root" ]; - ZED_EMAIL_PROG = "mail"; - ZED_EMAIL_OPTS = "-s '@SUBJECT@' @ADDRESS@"; + settings = mkOption { + type = with types; attrsOf (oneOf [ str int bool (listOf str) ]); + example = literalExample '' + { + ZED_DEBUG_LOG = "/tmp/zed.debug.log"; - ZED_NOTIFY_INTERVAL_SECS = 3600; - ZED_NOTIFY_VERBOSE = false; + ZED_EMAIL_ADDR = [ "root" ]; + ZED_EMAIL_PROG = "mail"; + ZED_EMAIL_OPTS = "-s '@SUBJECT@' @ADDRESS@"; - ZED_USE_ENCLOSURE_LEDS = true; - ZED_SCRUB_AFTER_RESILVER = false; - } - ''; - description = '' - ZFS Event Daemon /etc/zfs/zed.d/zed.rc content + ZED_NOTIFY_INTERVAL_SECS = 3600; + ZED_NOTIFY_VERBOSE = false; - See - zed8 - for details on ZED and the scripts in /etc/zfs/zed.d to find the possible variables - ''; + ZED_USE_ENCLOSURE_LEDS = true; + ZED_SCRUB_AFTER_RESILVER = false; + } + ''; + description = '' + ZFS Event Daemon /etc/zfs/zed.d/zed.rc content + + See + zed8 + for details on ZED and the scripts in /etc/zfs/zed.d to find the possible variables + ''; + }; }; }; @@ -358,6 +364,14 @@ in config = mkMerge [ (mkIf cfgZfs.enabled { assertions = [ + { + assertion = cfgZED.enableMail -> cfgZfs.package.enableMail; + message = '' + To allow ZED to send emails, ZFS needs to be configured to enable + this. To do so, one must override the `zfs` package and set + `enableMail` to true. + ''; + } { assertion = config.networking.hostId != null; message = "ZFS requires networking.hostId to be set"; @@ -437,7 +451,7 @@ in }; services.zfs.zed.settings = { - ZED_EMAIL_PROG = mkDefault "${pkgs.mailutils}/bin/mail"; + ZED_EMAIL_PROG = mkIf cfgZED.enableMail (mkDefault "${pkgs.mailutils}/bin/mail"); PATH = lib.makeBinPath [ cfgZfs.package pkgs.coreutils diff --git a/pkgs/os-specific/linux/zfs/default.nix b/pkgs/os-specific/linux/zfs/default.nix index a66520b6fa18..202dc9091fd5 100644 --- a/pkgs/os-specific/linux/zfs/default.nix +++ b/pkgs/os-specific/linux/zfs/default.nix @@ -8,8 +8,8 @@ , libtirpc , nfs-utils , gawk, gnugrep, gnused, systemd -, smartmontools, sysstat, sudo -, pkg-config +, smartmontools, enableMail ? false +, sysstat, sudo, pkg-config # Kernel dependencies , kernel ? null @@ -18,6 +18,8 @@ with lib; let + smartmon = smartmontools.override { inherit enableMail; }; + buildKernel = any (n: n == configFile) [ "kernel" "all" ]; buildUser = any (n: n == configFile) [ "user" "all" ]; @@ -148,7 +150,7 @@ let ''; postFixup = let - path = "PATH=${makeBinPath [ coreutils gawk gnused gnugrep util-linux smartmontools sysstat ]}:$PATH"; + path = "PATH=${makeBinPath [ coreutils gawk gnused gnugrep util-linux smartmon sysstat ]}:$PATH"; in '' for i in $out/libexec/zfs/zpool.d/*; do sed -i '2i${path}' $i @@ -157,12 +159,17 @@ let outputs = [ "out" ] ++ optionals buildUser [ "lib" "dev" ]; - passthru.tests = if isUnstable then - [ nixosTests.zfs.unstable ] - else [ - nixosTests.zfs.installer - nixosTests.zfs.stable - ]; + passthru = { + inherit enableMail; + + tests = + if isUnstable then [ + nixosTests.zfs.unstable + ] else [ + nixosTests.zfs.installer + nixosTests.zfs.stable + ]; + }; meta = { description = "ZFS Filesystem Linux Kernel module"; diff --git a/pkgs/tools/system/smartmontools/default.nix b/pkgs/tools/system/smartmontools/default.nix index 9eaf00b537a3..954c9eb4110c 100644 --- a/pkgs/tools/system/smartmontools/default.nix +++ b/pkgs/tools/system/smartmontools/default.nix @@ -1,5 +1,6 @@ { lib, stdenv, fetchurl, autoreconfHook -, mailutils, inetutils +, mailutils, enableMail ? true +, inetutils , IOKit, ApplicationServices }: let @@ -26,7 +27,7 @@ in stdenv.mkDerivation rec { postPatch = "cp -v ${driverdb} drivedb.h"; configureFlags = [ - "--with-scriptpath=${lib.makeBinPath [ mailutils inetutils ]}" + "--with-scriptpath=${lib.makeBinPath ([ inetutils ] ++ lib.optional enableMail mailutils)}" ]; nativeBuildInputs = [ autoreconfHook ];