about summary refs log tree commit diff
path: root/nixos/modules/hardware/usb-storage.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/modules/hardware/usb-storage.nix')
-rw-r--r--nixos/modules/hardware/usb-storage.nix20
1 files changed, 20 insertions, 0 deletions
diff --git a/nixos/modules/hardware/usb-storage.nix b/nixos/modules/hardware/usb-storage.nix
new file mode 100644
index 0000000000000..9c1b7a125fd18
--- /dev/null
+++ b/nixos/modules/hardware/usb-storage.nix
@@ -0,0 +1,20 @@
+{ config, lib, pkgs, ... }:
+with lib;
+
+{
+  options.hardware.usbStorage.manageStartStop = mkOption {
+    type = types.bool;
+    default = true;
+    description = lib.mdDoc ''
+      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.
+    '';
+  };
+
+  config = mkIf config.hardware.usbStorage.manageStartStop {
+    services.udev.extraRules = ''
+      ACTION=="add|change", SUBSYSTEM=="scsi_disk", DRIVERS=="usb-storage", ATTR{manage_start_stop}="1"
+    '';
+  };
+}