about summary refs log tree commit diff
path: root/nixos/modules/hardware
diff options
context:
space:
mode:
authorAnderson Torres <torres.anderson.85@protonmail.com>2022-11-03 22:33:20 -0300
committerGitHub <noreply@github.com>2022-11-03 22:33:20 -0300
commit97f523e3c8c31c7ac7276b1ec69b1beb734a3d9f (patch)
treeca0bb7c28398512adcd232043da7ad3a5eafa895 /nixos/modules/hardware
parentf4d7b3810e5a1262af772b95a7d139fa58d7d619 (diff)
parentac06f213ef185e21069a96d39ca5422b3279e37c (diff)
Merge pull request #185688 from bb2020/usbstor
nixos/usbStorage: add new option
Diffstat (limited to 'nixos/modules/hardware')
-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"
+    '';
+  };
+}