Laptop: Difference between revisions

From NixOS Wiki
imported>AmnesiaAmesia
Added page including how to enable tlp.
 
imported>AmnesiaAmesia
m Added example of how to configure tlp
Line 2: Line 2:
NixOS has several tools to help you manage the power on your system.
NixOS has several tools to help you manage the power on your system.


A common tool used to save power on laptops is tlp. To enable tlp you simply just write <code>services.tlp.enable = true;</code> in your configraion.nix.
A common tool used to save power on laptops is tlp, which have sensible defaults for most laptops. To enable tlp you simply just write <code>services.tlp.enable = true;</code> in your configraion.nix. However if you need a specific configuration you can do as shown in the example here below.
 
<syntaxHighlight lang=nix>
services.tlp = {
      enable = true;
      settings = {
        CPU_SCALING_GOVERNOR_ON_AC = "performance";
        CPU_SCALING_GOVERNOR_ON_BAT = "powersave";
 
        CPU_ENERGY_PERF_POLICY_ON_BAT = "performance";
        CPU_ENERGY_PERF_POLICY_ON_AC = "power";
 
        CPU_SCALING_MIN_FREQ_ON_AC = 800000;
        CPU_SCALING_MAX_FREQ_ON_AC = 5000000;
        CPU_SCALING_MIN_FREQ_ON_BAT = 800000;
        CPU_SCALING_MAX_FREQ_ON_BAT = 2600000;
      };
    };
</syntaxHighlight>
 
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.

Revision as of 06:28, 18 June 2023

Power management

NixOS has several tools to help you manage the power on your system.

A common tool used to save power on laptops is tlp, which have sensible defaults for most laptops. To enable tlp you simply just write services.tlp.enable = true; in your configraion.nix. However if you need a specific configuration you can do as shown in the example here below.

services.tlp = {
      enable = true;
      settings = {
        CPU_SCALING_GOVERNOR_ON_AC = "performance";
        CPU_SCALING_GOVERNOR_ON_BAT = "powersave";

        CPU_ENERGY_PERF_POLICY_ON_BAT = "performance";
        CPU_ENERGY_PERF_POLICY_ON_AC = "power";

        CPU_SCALING_MIN_FREQ_ON_AC = 800000;
        CPU_SCALING_MAX_FREQ_ON_AC = 5000000;
        CPU_SCALING_MIN_FREQ_ON_BAT = 800000;
        CPU_SCALING_MAX_FREQ_ON_BAT = 2600000;
      };
    };

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.