···
+
{ config, lib, pkgs, ... }:
+
inherit (lib) mkEnableOption mkIf mkOption types;
+
cfg = config.hardware.sata.timeout;
+
lib.concatStringsSep ", " [
+
''ENV{ID_${lib.toUpper d.idBy}}=="${d.name}"''
+
''ENV{SYSTEMD_WANTS}="${unitName d}"''
+
"/dev/disk/by-${device.idBy}/${device.name}";
+
"sata-timeout-${lib.strings.sanitizeDerivationName device.name}";
+
pkgs.writeShellScript "sata-timeout.sh" ''
+
${pkgs.smartmontools}/bin/smartctl \
+
-l scterc,${toString cfg.deciSeconds},${toString cfg.deciSeconds} \
+
--quietmode errorsonly \
+
meta.maintainers = with lib.maintainers; [ peterhoeg ];
+
options.hardware.sata.timeout = {
+
enable = mkEnableOption "SATA drive timeouts";
+
deciSeconds = mkOption {
+
Set SCT Error Recovery Control timeout in deciseconds for use in RAID configurations.
+
70 = default in consumer drives (7 seconds)
+
Maximum is disk dependant but probably 60 seconds.
+
description = "List of drives for which to configure the timeout.";
+
description = "Drive name without the full path.";
+
description = "The method to identify the drive.";
+
type = types.enum [ "path" "wwn" ];
+
config = mkIf cfg.enable {
+
services.udev.extraRules = lib.concatMapStringsSep "\n" buildRule cfg.drives;
+
systemd.services = lib.listToAttrs (map
+
lib.nameValuePair (unitName e) {
+
description = "SATA timeout for ${e.name}";
+
wantedBy = [ "sata-timeout.target" ];
+
ExecStart = "${startScript} '${devicePath e}'";
+
ProtectSystem = "strict";
+
systemd.targets.sata-timeout = {
+
description = "SATA timeout";
+
wantedBy = [ "multi-user.target" ];