Power Management: Difference between revisions
Add notes on hibernation |
Restructuring, add section on hdd power modes |
||
Line 1: | Line 1: | ||
This article covers configurations related to power management in terms of energy saving modes of various devices and components. | |||
== | == Configuration == | ||
=== Hard drive power management === | |||
Following snippet configures [[Udev]] rules which automatically run the program <code>hdparm</code> to enable power saving modes for hard disks, especially rotational drives mapped to <code>/dev/sd*</code>.<syntaxhighlight lang="nix"> | |||
services.udev.extraRules = | |||
let | |||
mkRule = as: lib.concatStringsSep ", " as; | |||
mkRules = rs: lib.concatStringsSep "\n" rs; | |||
in mkRules ([( mkRule [ | |||
''ACTION=="add|change"'' | |||
''SUBSYSTEM=="block"'' | |||
''KERNEL=="sd[a-z]"'' | |||
''ATTR{queue/rotational}=="1"'' | |||
''RUN+="${pkgs.hdparm}/bin/hdparm -B 90 -S 41 /dev/%k"'' | |||
])]); | |||
</syntaxhighlight>The <code>hdparm</code> parameters <code>-B</code> and <code>-S</code> define power saving modes and in case of <code>-S</code> the standby (spindown) timeout. The number 41 means therefore: Turn off the motor after 205 = 41*5 seconds. | |||
=== Suspend hooks === | === Suspend hooks === | ||
NixOS provides the {{nixos:option|powerManagement.resumeCommands}} option which defines commands that are added to a global script that will be executed after resuming. | NixOS provides the {{nixos:option|powerManagement.resumeCommands}} option which defines commands that are added to a global script that will be executed after resuming. | ||
Line 27: | Line 41: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Hibernation == | === Hibernation === | ||
Hibernation requires a configured swap device. See [https://nixos.org/manual/nixos/stable/#ch-installation installation instructions] on how to create a swap partition. An example configuration could look like this:<syntaxhighlight lang="nix"> | Hibernation requires a configured swap device. See [https://nixos.org/manual/nixos/stable/#ch-installation installation instructions] on how to create a swap partition. An example configuration could look like this:<syntaxhighlight lang="nix"> | ||
swapDevices = [ | swapDevices = [ |