2022-08-07 20:51:04 +03:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2024-01-27 12:25:21 +03:00
|
|
|
|
2022-08-07 20:51:04 +03:00
|
|
|
{
|
2024-01-27 12:25:21 +03:00
|
|
|
options.hardware.usbStorage.manageShutdown = lib.mkOption {
|
2024-08-24 22:05:30 +02:00
|
|
|
type = lib.types.bool;
|
2024-01-27 12:25:21 +03:00
|
|
|
default = false;
|
2022-08-07 20:51:04 +03: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 12:25:21 +03:00
|
|
|
config = lib.mkIf config.hardware.usbStorage.manageShutdown {
|
2022-08-07 20:51:04 +03:00
|
|
|
services.udev.extraRules = ''
|
2024-01-27 12:25:21 +03:00
|
|
|
ACTION=="add|change", SUBSYSTEM=="scsi_disk", DRIVERS=="usb-storage|uas", ATTR{manage_shutdown}="1"
|
2022-08-07 20:51:04 +03:00
|
|
|
'';
|
|
|
|
};
|
2024-01-27 12:25:21 +03:00
|
|
|
|
|
|
|
imports = [
|
|
|
|
(lib.mkRenamedOptionModule
|
|
|
|
[ "hardware" "usbStorage" "manageStartStop" ]
|
|
|
|
[ "hardware" "usbStorage" "manageShutdown" ]
|
2024-12-10 20:26:33 +01:00
|
|
|
)
|
2024-01-27 12:25:21 +03:00
|
|
|
];
|
2022-08-07 20:51:04 +03:00
|
|
|
}
|