summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Simons <simons@cryp.to>2013-03-10 01:19:44 +0100
committerPeter Simons <simons@cryp.to>2013-03-10 01:19:44 +0100
commit415ff3c39a6b39e571ddece06faef0cc84a5c86c (patch)
treede0e774321bd6b16e0600c202f7a44a4c6783c6d
parent763835e77071f5964b622741733157817043821c (diff)
downloadnixpkgs-415ff3c39a6b39e571ddece06faef0cc84a5c86c.tar
nixpkgs-415ff3c39a6b39e571ddece06faef0cc84a5c86c.tar.gz
nixpkgs-415ff3c39a6b39e571ddece06faef0cc84a5c86c.tar.bz2
nixpkgs-415ff3c39a6b39e571ddece06faef0cc84a5c86c.tar.lz
nixpkgs-415ff3c39a6b39e571ddece06faef0cc84a5c86c.tar.xz
nixpkgs-415ff3c39a6b39e571ddece06faef0cc84a5c86c.tar.zst
nixpkgs-415ff3c39a6b39e571ddece06faef0cc84a5c86c.zip
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.
-rw-r--r--modules/services/monitoring/smartd.nix27
1 files changed, 25 insertions, 2 deletions
diff --git a/modules/services/monitoring/smartd.nix b/modules/services/monitoring/smartd.nix
index 07acab761d0..71eb6b99ed3 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