From 3c81fc54394fe1680d7929a3a34bc7dc58def373 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Mon, 9 Oct 2023 14:00:40 +0200 Subject: [PATCH] don't wake up disks --- modules/spin-down.nix | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/modules/spin-down.nix b/modules/spin-down.nix index bce8b9f..c2d2764 100644 --- a/modules/spin-down.nix +++ b/modules/spin-down.nix @@ -56,6 +56,11 @@ # # -i 120: Spin down after 2 minutes (120 seconds) of inactivity. # ExecStart = "${pkgs.hd-idle}/bin/hd-idle -a /dev/disk/by-id/XXX-XXX-XXX -i 120"; +# Note about the `script` settings below. +# If the disk is spun-down (in standby mode): +# - The standby timeout has been set before already, otherwise it would be spinning. +# - Don't set the standby timeout again, as this will spin up the disk. + { environment.systemPackages = with pkgs; [ hdparm @@ -63,25 +68,25 @@ systemd.services."hdparm-4tb1" = { description = "Spin down inactive HDD"; wantedBy = [ "multi-user.target" ]; - serviceConfig = { - Type = "oneshot"; - ExecStart = "${pkgs.hdparm}/bin/hdparm -S 24 /dev/disk/by-id/ata-WDC_WD40EFRX-68N32N0_WD-WCC7K0CPF0N1"; - }; + serviceConfig.Type = "oneshot"; + script = '' + ${pkgs.hdparm}/bin/hdparm -C /dev/disk/by-id/ata-WDC_WD40EFRX-68N32N0_WD-WCC7K0CPF0N1 | ${pkgs.busybox}/bin/grep 'standby' || ${pkgs.hdparm}/bin/hdparm -S 24 /dev/disk/by-id/ata-WDC_WD40EFRX-68N32N0_WD-WCC7K0CPF0N1 + ''; }; systemd.services."hdparm-3tb1" = { description = "Spin down inactive HDD"; wantedBy = [ "multi-user.target" ]; - serviceConfig = { - Type = "oneshot"; - ExecStart = "${pkgs.hdparm}/bin/hdparm -S 24 /dev/disk/by-id/ata-WDC_WD30EFRX-68EUZN0_WD-WCC4N1173157"; - }; + serviceConfig.Type = "oneshot"; + script = '' + ${pkgs.hdparm}/bin/hdparm -C /dev/disk/by-id/ata-WDC_WD30EFRX-68EUZN0_WD-WCC4N1173157 | ${pkgs.busybox}/bin/grep 'standby' || ${pkgs.hdparm}/bin/hdparm -S 24 /dev/disk/by-id/ata-WDC_WD30EFRX-68EUZN0_WD-WCC4N1173157 + ''; }; systemd.services."hdparm-3tb2" = { description = "Spin down inactive HDD"; wantedBy = [ "multi-user.target" ]; - serviceConfig = { - Type = "oneshot"; - ExecStart = "${pkgs.hdparm}/bin/hdparm -S 24 /dev/disk/by-id/ata-WDC_WD30EFRX-68EUZN0_WD-WMC4N0564095"; - }; + serviceConfig.Type = "oneshot"; + script = '' + ${pkgs.hdparm}/bin/hdparm -C /dev/disk/by-id/ata-WDC_WD30EFRX-68EUZN0_WD-WMC4N0564095 | ${pkgs.busybox}/bin/grep 'standby' || ${pkgs.hdparm}/bin/hdparm -S 24 /dev/disk/by-id/ata-WDC_WD30EFRX-68EUZN0_WD-WMC4N0564095 + ''; }; }