Skip to content
Permalink
Browse files

smart

  • Loading branch information
peterhoeg committed Mar 18, 2019
1 parent da1a2b1 commit b81efc840a0a37bb8883eb787e3367b839d19eb8
Showing with 80 additions and 0 deletions.
  1. +79 −0 nixos/modules/hardware/smart.nix
  2. +1 −0 nixos/modules/module-list.nix
@@ -0,0 +1,79 @@
{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.hardware.smart;

smartDeviceOpts = { name, ... }: {
options = {

device = mkOption {
example = "/dev/sda";
type = types.str;
description = "Location of the device.";
};

timeout = mkOption {
default = -1;
example = "70";
type = types.int;
description = ''
Set SCT Error Recovery Control timeout in deciseconds for use in RAID configurations.
Values are as follows:
-1 = do not touch, leave at default
0 = disable SCT ERT
70 = default in consumer drives (7 seconds)
Maximum is disk dependant but probably 60 seconds.
'';
};

options = mkOption {
default = "";
example = "-J 30";
type = types.separatedString " ";
description = "Options for smartctl";
};
};
};

deviceTimeout = d:
lib.optionalString (d.timeout > -1) ''
${smartctl} ${d.device} "-l scterc,${d.timeout},${d.timeout} --silent errorsonly"
'';

smartctl = device: options: ''
${pkgs.smartmontools}/bin/smartctl ${options} ${device}
'';

in {
options.hardware.smart = {
enable = mkEnableOption "SMART for disks";

devices = mkOption {
default = [];
example = [
{ device = "/dev/sda"; timeout = 0; }
{ device = "/dev/sdb"; options = "-J 30"; } ];
type = with types; listOf (submodule smartDeviceOpts);
description = "List of devices for which to configure SMART settings";
};
};

config = mkIf cfg.enable {
systemd.services.smart = {
description = "Configure SMART for storage devices";
before = [ "smartd.service" ];
wantedBy = [ "multi-user.target" ];
script = ''
${concatMapStringsSep "\n" deviceTimeout cfg.devices}
# ${concatMapStringsSep "\n" deviceTimeout cfg.devices}
'';
serviceConfig = {
Type = "oneshot";
PrivateTmp = true;
PrivateNetwork = true;
};
};
};
}
@@ -51,6 +51,7 @@
./hardware/opengl.nix
./hardware/pcmcia.nix
./hardware/raid/hpsa.nix
./hardware/smart.nix
./hardware/steam-hardware.nix
./hardware/usb-wwan.nix
./hardware/onlykey.nix

0 comments on commit b81efc8

Please sign in to comment.
You can’t perform that action at this time.