nixos/modules/hdparm.nix

57 lines
1.5 KiB
Nix

{ pkgs, lib, config, ... }:
let
cfg = config.services.hdparm;
diskPath = disk: path:
if path == null then "/dev/disk/by-id/${disk}" else path;
mkService = disk: settings: {
name = "hdparm-${disk}";
value = {
description = "Configure hdparm settings for HDD ${disk}";
serviceConfig.Type = "oneshot";
serviceConfig.ExecStart = ''
${pkgs.hdparm}/bin/hdparm -q ${
lib.strings.optionalString (settings.spinDown5Secs != null)
"-S ${builtins.toString settings.spinDown5Secs}"
} ${lib.strings.optionalString settings.powerDownOnStart "-y"} ${
diskPath disk settings.path
}
'';
wantedBy = [ "multi-user.target" ];
};
};
in {
options.services.hdparm = with lib;
mkOption {
type = types.attrsOf (types.submodule {
options = {
path = mkOption {
type = types.nullOr types.str;
description =
"Path to the disk. Will assume <name> is the id in `/dev/disk/by-id/` if left null";
default = null;
};
spinDown5Secs = mkOption {
type = types.nullOr types.int;
description = "Spin down after x * 5s";
default = null;
};
powerDownOnStart = mkOption {
type = types.bool;
description = "Put the drive to sleep after boot";
default = false;
};
};
});
default = { };
description = "Settings for HDDs";
};
config.systemd.services = lib.mapAttrs' mkService cfg;
}