Laptop: Difference between revisions

m Update (rename): hardware.opengl -> hardware.graphics
Granddave (talk | contribs)
m Code formatting, minor capitalization changes
Line 11: Line 11:
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
services.tlp = {
services.tlp = {
      enable = true;
  enable = true;
      settings = {
  settings = {
        CPU_SCALING_GOVERNOR_ON_AC = "performance";
    CPU_SCALING_GOVERNOR_ON_AC = "performance";
        CPU_SCALING_GOVERNOR_ON_BAT = "powersave";
    CPU_SCALING_GOVERNOR_ON_BAT = "powersave";


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


        CPU_MIN_PERF_ON_AC = 0;
    CPU_MIN_PERF_ON_AC = 0;
        CPU_MAX_PERF_ON_AC = 100;
    CPU_MAX_PERF_ON_AC = 100;
        CPU_MIN_PERF_ON_BAT = 0;
    CPU_MIN_PERF_ON_BAT = 0;
        CPU_MAX_PERF_ON_BAT = 20;
    CPU_MAX_PERF_ON_BAT = 20;


      #Optional helps save long term battery health
    # Optional helps save long term battery health
      START_CHARGE_THRESH_BAT0 = 40; # 40 and bellow it starts to charge
    START_CHARGE_THRESH_BAT0 = 40; # 40 and bellow 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
 
  };
      };
};
};
</syntaxHighlight>
</syntaxHighlight>
Line 42: Line 41:
services.auto-cpufreq.settings = {
services.auto-cpufreq.settings = {
   battery = {
   battery = {
    governor = "powersave";
    governor = "powersave";
    turbo = "never";
    turbo = "never";
   };
   };
   charger = {
   charger = {
    governor = "performance";
    governor = "performance";
    turbo = "auto";
    turbo = "auto";
   };
   };
};
};
</syntaxHighlight>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].<br> To summarize: 1) add the flake as an input to your <code>flake.nix</code> file and enable the module:<syntaxhighlight lang="nix">
</syntaxHighlight>
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>
1) add the flake as an input to your <code>flake.nix</code> file and enable the module:
<syntaxhighlight lang="nix">
# flake.nix
# flake.nix
{
{
    inputs = {
  inputs =
        # ---Snip---
    {
        auto-cpufreq = {
      # ---Snip---
            url = "github:AdnanHodzic/auto-cpufreq";
      auto-cpufreq = {
            inputs.nixpkgs.follows = "nixpkgs";
        url = "github:AdnanHodzic/auto-cpufreq";
        };
        inputs.nixpkgs.follows = "nixpkgs";
        # ---Snip---
      };
     }
      # ---Snip---
     };


    outputs = inputs@{nixpkgs, auto-cpufreq, ...} : {
  outputs = inputs@{ nixpkgs, auto-cpufreq, ... }: {
        nixosConfigurations.HOSTNAME = nixpkgs.lib.nixosSystem {
    nixosConfigurations.HOSTNAME = nixpkgs.lib.nixosSystem {
            specialArgs = { inherit inputs; };
      specialArgs = {
            modules = [
        inherit inputs;
                ./configuration.nix
      };
                auto-cpufreq.nixosModules.default
      modules = [
            ];
        ./configuration.nix
        };
        auto-cpufreq.nixosModules.default
    }  
      ];
    };
  };
}
}
</syntaxhighlight>2) Then enable it in your <code>configuration.nix</code> file:<syntaxhighlight lang="nix">
</syntaxhighlight>2) Then enable it in your <code>configuration.nix</code> file:
<syntaxhighlight lang="nix">
# configuration.nix
# configuration.nix
{ inputs, pkgs, ... }: {
  # ---Snip---


{inputs, pkgs, ...}: {
  programs.auto-cpufreq.enable = true;
    # ---Snip---


    programs.auto-cpufreq.enable = true;
  # optionally, you can configure your auto-cpufreq settings, if you have any
 
  programs.auto-cpufreq.settings = {
    # optionally, you can configure your auto-cpufreq settings, if you have any
    charger = {
    programs.auto-cpufreq.settings = {
      governor = "performance";
      charger = {
      turbo = "auto";
        governor = "performance";
    };
        turbo = "auto";
    battery = {
      };
      governor = "powersave";
      battery = {
      turbo = "auto";
        governor = "powersave";
        turbo = "auto";
      };
     };
     };
    # ---Snip---
  };
  # ---Snip---
}
}
</syntaxhighlight>Since v2.0 auto-cpufreq also includes a GUI that lets you temporarily override the CPU frequency governor setting.
</syntaxhighlight>
Since v2.0 auto-cpufreq also includes a GUI that lets you temporarily override the CPU frequency governor setting.


==== Powertop ====
==== Powertop ====
Powertop is a power analysis tool, but it also has a feature called auto-tune which will enable power saving settings on your device. These power saving settings should be almost the same as those enabled by tlp, although powertop enables USB auto-suspend by default. This can make your input devices such as the keyboard unresponsive for some time when it has been suspended. To enable powertop: <code>powerManagement.powertop.enable = true;</code>. This also enables the auto-tune feature of powertop.
Powertop is a power analysis tool, but it also has a feature called auto-tune which will enable power saving settings on your device. These power saving settings should be almost the same as those enabled by tlp, although Powertop enables USB auto-suspend by default. This can make your input devices such as the keyboard unresponsive for some time when it has been suspended.  
 
To enable Powertop: <code>powerManagement.powertop.enable = true;</code>.  
 
This also enables the auto-tune feature of Powertop.


== Hardware support ==
== Hardware support ==
Line 103: Line 114:
Many laptops have both a dedicated and a discrete GPU. To use your laptop effectively you have to manage both GPUs. For guidance on how to configure the GPUs, refer to the dedicated wiki-pages for your configuration. If you want to have the option to run your laptop with and without the discrete GPU to save power, you can either disable it in the bios (if possible) or you can use Nix's feature to define specialisations to give you two boot entries on each rebuild of your system.
Many laptops have both a dedicated and a discrete GPU. To use your laptop effectively you have to manage both GPUs. For guidance on how to configure the GPUs, refer to the dedicated wiki-pages for your configuration. If you want to have the option to run your laptop with and without the discrete GPU to save power, you can either disable it in the bios (if possible) or you can use Nix's feature to define specialisations to give you two boot entries on each rebuild of your system.


Example of a nvidia specialisation:
Example of a Nvidia specialisation:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
specialisation = {  
specialisation = {
  nvidia.configuration = {  
  nvidia.configuration = {
    # Nvidia Configuration  
    # Nvidia Configuration
    services.xserver.videoDrivers = [ "nvidia" ];  
    services.xserver.videoDrivers = [ "nvidia" ];
    hardware.graphics.enable = true;  
    hardware.graphics.enable = true;
 
 
    # Optionally, you may need to select the appropriate driver version for your specific GPU.  
    # Optionally, you may need to select the appropriate driver version for your specific GPU.
    hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;  
    hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable;
 
 
    # nvidia-drm.modeset=1 is required for some wayland compositors, e.g. sway  
    # nvidia-drm.modeset=1 is required for some wayland compositors, e.g. sway
    hardware.nvidia.modesetting.enable = true;  
    hardware.nvidia.modesetting.enable = true;
 
 
    hardware.nvidia.prime = {  
    hardware.nvidia.prime = {
      sync.enable = true;  
      sync.enable = true;
 
 
      # Bus ID of the NVIDIA GPU. You can find it using lspci, either under 3D or VGA  
      # Bus ID of the NVIDIA GPU. You can find it using lspci, either under 3D or VGA
      nvidiaBusId = "PCI:1:0:0";  
      nvidiaBusId = "PCI:1:0:0";
 
 
      # Bus ID of the Intel GPU. You can find it using lspci, either under 3D or VGA  
      # Bus ID of the Intel GPU. You can find it using lspci, either under 3D or VGA
      intelBusId = "PCI:0:2:0";  
      intelBusId = "PCI:0:2:0";
    };
    };
   };
   };
};
};
Line 137: Line 148:
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
services.tlp = {
services.tlp = {
    enable = true;
  enable = true;
    settings = {
  settings = {
      TLP_DEFAULT_MODE = "BAT";
    TLP_DEFAULT_MODE = "BAT";
      TLP_PERSISTENT_DEFAULT = 1;
    TLP_PERSISTENT_DEFAULT = 1;
    };
  };
};  
};
</syntaxHighlight>
</syntaxHighlight>