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.
This commit is contained in:
Peter Simons 2013-03-10 01:19:44 +01:00
parent 763835e770
commit 415ff3c39a

@ -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