{ config, lib, ... }: with lib; let hardDrives = config.numbus.hardware.spindown.list; cfg = config.numbus.hardware; in { config = mkIf (cfg.HddSpindown.enable == true) { systemd.services.hd-idle = { description = "External HD spin down daemon"; wantedBy = [ "multi-user.target" ]; serviceConfig = { Type = "simple"; ExecStart = let idleTime = toString 1800; hardDriveParameter = lib.strings.concatMapStringsSep " " (x: "-a ${x} -i ${idleTime}") hardDrives; in "${pkgs.hd-idle}/bin/hd-idle -i 0 ${hardDriveParameter}"; }; }; }; options.numbus = { hardware = { spindown = { enable = mkEnableOption "hard drives spin down when inactive in order to save power."; list = mkOption { description = "The list of compatible hard drives that will spin down."; type = types.listOf types.str; default = []; example = [ "/dev/disk/by-id/ata_Hitachi_MZVPYEHCO_159Ejz224G0000" "/dev/disk/by-id/ata-WD_159Ejz224G" ]; }; optimize = mkOption { description = "Optimize services to reduce HDD wakeups when spindown is enabled. Can be set to \"compatible\" to optimize all compatible services, or a list of service names to optimize."; type = types.nullOr (types.either (types.enum [ "compatible" ]) (types.listOf types.str)); default = "compatible"; example = "[ \"crafty\" \"gitea\" ]"; }; }; }; }; }