2022-08-07 17:51:04 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2024-01-27 09:25:21 +00:00
|
|
|
|
2022-08-07 17:51:04 +00:00
|
|
|
{
|
2024-01-27 09:25:21 +00:00
|
|
|
options.hardware.usbStorage.manageShutdown = lib.mkOption {
|
2024-08-24 20:05:30 +00:00
|
|
|
type = lib.types.bool;
|
2024-01-27 09:25:21 +00:00
|
|
|
default = false;
|
2022-08-07 17:51:04 +00:00
|
|
|
description = ''
|
|
|
|
Enable this option to gracefully spin-down external storage during shutdown.
|
|
|
|
If you suspect improper head parking after poweroff, install `smartmontools` and check
|
|
|
|
for the `Power-Off_Retract_Count` field for an increment.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-01-27 09:25:21 +00:00
|
|
|
config = lib.mkIf config.hardware.usbStorage.manageShutdown {
|
2022-08-07 17:51:04 +00:00
|
|
|
services.udev.extraRules = ''
|
2024-01-27 09:25:21 +00:00
|
|
|
ACTION=="add|change", SUBSYSTEM=="scsi_disk", DRIVERS=="usb-storage|uas", ATTR{manage_shutdown}="1"
|
2022-08-07 17:51:04 +00:00
|
|
|
'';
|
|
|
|
};
|
2024-01-27 09:25:21 +00:00
|
|
|
|
|
|
|
imports = [(lib.mkRenamedOptionModule [ "hardware" "usbStorage" "manageStartStop" ] [ "hardware" "usbStorage" "manageShutdown" ])];
|
2022-08-07 17:51:04 +00:00
|
|
|
}
|