From 415ff3c39a6b39e571ddece06faef0cc84a5c86c Mon Sep 17 00:00:00 2001 From: Peter Simons Date: Sun, 10 Mar 2013 01:19:44 +0100 Subject: [PATCH] smartd: change 'devices' option from "list of strings" to "list of attribute sets" The smartd used to expect a list of devices to monitor. After this patch, it expects a list of attribute sets, which may have two attributes: - device: path to the device (required) - options: smartd options to apply to this particular device (optional) A concrete example configuration would be: services.smartd = { enable = true; devices = [ { device = "/dev/sda"; } { device = "/dev/sdb"; options = "-d sat"; } ]; }; Furthermore, the config option 'deviceOpts' can be used to configure options that are applied to *every* device. --- modules/services/monitoring/smartd.nix | 27 ++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/modules/services/monitoring/smartd.nix b/modules/services/monitoring/smartd.nix index 07acab761d08..71eb6b99ed3b 100644 --- a/modules/services/monitoring/smartd.nix +++ b/modules/services/monitoring/smartd.nix @@ -6,6 +6,27 @@ let cfg = config.services.smartd; + smartdOpts = { name, ... }: { + + options = { + + device = mkOption { + example = "/dev/sda"; + type = types.string; + description = "Location of the device."; + }; + + options = mkOption { + default = ""; + example = "-d sat"; + type = types.string; + merge = pkgs.lib.concatStringsSep " "; + description = "Options that determine how smartd monitors the device"; + }; + }; + + }; + smartdMail = pkgs.writeScript "smartdmail.sh" '' #! ${pkgs.stdenv.shell} TMPNAM=/tmp/smartd-message.$$.tmp @@ -24,7 +45,7 @@ let smartdConf = pkgs.writeText "smartd.conf" (concatMapStrings (device: '' - ${device} -a -m root -M exec ${smartdMail} ${cfg.deviceOpts} + ${device.device} -a -m root -M exec ${smartdMail} ${device.options} ${cfg.deviceOpts} '' ) cfg.devices); @@ -63,7 +84,9 @@ in devices = mkOption { default = []; - example = ["/dev/sda" "/dev/sdb"]; + example = [ { device = "/dev/sda"; } { device = "/dev/sdb"; options = "-d sat"; } ]; + type = types.list types.optionSet; + options = [ smartdOpts ]; description = '' List of devices to monitor. By default -- if this list is empty --, smartd will monitor all devices connected to the machine at the time