nixpkgs/nixos/modules/tasks/cpu-freq.nix
Eelco Dolstra 29027fd1e1 Rewrite ‘with pkgs.lib’ -> ‘with lib’
Using pkgs.lib on the spine of module evaluation is problematic
because the pkgs argument depends on the result of module
evaluation. To prevent an infinite recursion, pkgs and some of the
modules are evaluated twice, which is inefficient. Using ‘with lib’
prevents this problem.
2014-04-14 16:26:48 +02:00

53 lines
1.2 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{ config, lib, pkgs, ... }:
with lib;
{
###### interface
options = {
powerManagement.cpuFreqGovernor = mkOption {
type = types.nullOr types.str;
default = null;
example = "ondemand";
description = ''
Configure the governor used to regulate the frequence of the
available CPUs. By default, the kernel configures the
on-demand governor.
'';
};
};
###### implementation
config = mkIf (config.powerManagement.cpuFreqGovernor != null) {
environment.systemPackages = [ pkgs.cpufrequtils ];
jobs.cpufreq =
{ description = "CPU Frequency Governor Setup";
after = [ "systemd-modules-load.service" ];
wantedBy = [ "multi-user.target" ];
unitConfig.ConditionPathIsReadWrite = "/sys/devices/";
path = [ pkgs.cpufrequtils ];
preStart = ''
for i in $(seq 0 $(($(nproc) - 1))); do
for gov in $(cpufreq-info -c $i -g); do
if [ "$gov" = ${config.powerManagement.cpuFreqGovernor} ]; then
echo "<6>setting governor on CPU $i to $gov"
cpufreq-set -c $i -g $gov
fi
done
done
'';
};
};
}