Laptop: Difference between revisions
- reordered headings (moved all headings one heading up). Added the 3 options for closing the lid. |
m fix the language parameter in {{file}} template |
||
| (4 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
= Closing the lid = | = Closing the lid = | ||
{{File|3=services.logind.settings.Login = { | |||
services.logind. | HandleLidSwitch = "poweroff"; | ||
HandleLidSwitchExternalPower = "lock"; | |||
HandleLidSwitchDocked = "ignore"; | |||
}; | |||
# one of "ignore", "poweroff", "reboot", "halt", "kexec", "suspend", "hibernate", "hybrid-sleep", "suspend-then-hibernate", "lock" | # one of "ignore", "poweroff", "reboot", "halt", "kexec", "suspend", "hibernate", "hybrid-sleep", "suspend-then-hibernate", "lock"|name=/etc/nixos/configuration.nix|lang=nix}} | ||
These three options can be used to configure how a laptop should behave when the lid is closed. In this example, it normally shuts down. If power is connected, only the screen is locked. If another screen is connected instead, nothing happens. | |||
= Power management = | = Power management = | ||
| Line 18: | Line 19: | ||
A common tool used to save power on laptops is [https://linrunner.de/tlp/index.html TLP], which has sensible defaults for most laptops. To enable TLP you simply just write <code>services.tlp.enable = true;</code> in your <code>configuration.nix</code>. However, if you need a specific configuration, you can do as shown in the example below. | A common tool used to save power on laptops is [https://linrunner.de/tlp/index.html TLP], which has sensible defaults for most laptops. To enable TLP you simply just write <code>services.tlp.enable = true;</code> in your <code>configuration.nix</code>. However, if you need a specific configuration, you can do as shown in the example below. | ||
{{file|configuration.nix|nix|3= | |||
services.tlp = { | services.tlp = { | ||
enable = true; | enable = true; | ||
| Line 34: | Line 35: | ||
# Optional helps save long term battery health | # Optional helps save long term battery health | ||
START_CHARGE_THRESH_BAT0 = 40; # 40 and | START_CHARGE_THRESH_BAT0 = 40; # 40 and below it starts to charge | ||
STOP_CHARGE_THRESH_BAT0 = 80; # 80 and above it stops charging | STOP_CHARGE_THRESH_BAT0 = 80; # 80 and above it stops charging | ||
}; | }; | ||
}; | }; | ||
}} | |||
This example enables TLP and sets the minimum and maximum frequencies for the CPU based on whether it is plugged into power or not. It also changes the CPU scaling governor based on this. | This example enables TLP and sets the minimum and maximum frequencies for the CPU based on whether it is plugged into power or not. It also changes the CPU scaling governor based on this. | ||
| Line 46: | Line 47: | ||
Example of how to configure auto-cpufreq: | Example of how to configure auto-cpufreq: | ||
{{file|configuration.nix|nix|3= | |||
services.auto-cpufreq.enable = true; | services.auto-cpufreq.enable = true; | ||
services.auto-cpufreq.settings = { | services.auto-cpufreq.settings = { | ||
| Line 58: | Line 59: | ||
}; | }; | ||
}; | }; | ||
}} | |||
Alternatively, if you have [[Flakes]] enabled you can also use the flake directly provided by the auto-cpufreq authors to get a more up-to-date version. They offer a detailed explanation how to add it to your system on their [https://github.com/AdnanHodzic/auto-cpufreq?tab=readme-ov-file#nixos GitHub page]. | Alternatively, if you have [[Flakes]] enabled you can also use the flake directly provided by the auto-cpufreq authors to get a more up-to-date version. They offer a detailed explanation how to add it to your system on their [https://github.com/AdnanHodzic/auto-cpufreq?tab=readme-ov-file#nixos GitHub page]. | ||
To summarize:</br> | To summarize:</br> | ||
1) add the flake as an input to your <code>flake.nix</code> file and enable the module: | 1) add the flake as an input to your <code>flake.nix</code> file and enable the module: | ||
{{file|flake.nix|nix|3= | |||
{ | { | ||
inputs = | inputs = | ||
| Line 88: | Line 88: | ||
}; | }; | ||
} | } | ||
}} | |||
2) Then enable it in your <code>configuration.nix</code> file: | |||
{{file|configuration.nix|nix|3= | |||
{ inputs, pkgs, ... }: { | { inputs, pkgs, ... }: { | ||
# ---Snip--- | # ---Snip--- | ||
| Line 109: | Line 109: | ||
# ---Snip--- | # ---Snip--- | ||
} | } | ||
}} | |||
Since v2.0 auto-cpufreq also includes a GUI that lets you temporarily override the CPU frequency governor setting. | Since v2.0 auto-cpufreq also includes a GUI that lets you temporarily override the CPU frequency governor setting. | ||