Skip to content

Commit

Permalink
smart
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhoeg committed Mar 18, 2019
1 parent da1a2b1 commit b81efc8
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
79 changes: 79 additions & 0 deletions nixos/modules/hardware/smart.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;
};
};
};
}
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Expand Up @@ -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
Expand Down

0 comments on commit b81efc8

Please sign in to comment.