nix-git/modules/spin-down/hd-idle.nix

33 lines
824 B
Nix
Raw Normal View History

2023-11-23 20:11:28 +01:00
{ lib, config, options, pkgs, modulesPath, ... }:
with lib;
let
cfg = config.yoda.spin-down.hd-idle;
in
{
options = {
yoda.spin-down.hd-idle = mkOption {
type = types.listOf types.str;
default = [ ];
example = ["ata-ST6000DM003-2CY186_ZR11WA9K"];
description = ''
List with IDs (/dev/disk/by-id/<ID>) of HDDs to spin down with hd-idle after 5 minutes.
Please try to use yoda.spin-down.hdparm first.
'';
};
};
config = mkIf (length cfg > 0) {
systemd.services."hd-idle" = {
description = "Spin down inactive HDDs";
wantedBy = [ "multi-user.target" ];
script =
let
args = strings.concatMapStrings (x: " -a disk/by-id/${x} -i 300") cfg;
in ''
${pkgs.hd-idle}/bin/hd-idle ${args}
'';
};
};
}