1 { config, lib, pkgs, ... }:
6 cpupower = config.boot.kernelPackages.cpupower;
7 cfg = config.powerManagement;
13 options.powerManagement = {
15 # TODO: This should be aliased to powerManagement.cpufreq.governor.
16 # https://github.com/NixOS/nixpkgs/pull/53041#commitcomment-31825338
17 cpuFreqGovernor = mkOption {
18 type = types.nullOr types.str;
22 Configure the governor used to regulate the frequency of the
23 available CPUs. By default, the kernel configures the
24 performance governor, although this may be overwritten in your
25 hardware-configuration.nix file.
27 Often used values: "ondemand", "powersave", "performance"
34 type = types.nullOr types.ints.unsigned;
38 The maximum frequency the CPU will use. Defaults to the maximum possible.
43 type = types.nullOr types.ints.unsigned;
47 The minimum frequency the CPU will use.
59 governorEnable = cfg.cpuFreqGovernor != null;
60 maxEnable = cfg.cpufreq.max != null;
61 minEnable = cfg.cpufreq.min != null;
63 !config.boot.isContainer &&
64 (governorEnable || maxEnable || minEnable);
68 boot.kernelModules = optional governorEnable "cpufreq_${cfg.cpuFreqGovernor}";
70 environment.systemPackages = [ cpupower ];
72 systemd.services.cpufreq = {
73 description = "CPU Frequency Setup";
74 after = [ "systemd-modules-load.service" ];
75 wantedBy = [ "multi-user.target" ];
76 path = [ cpupower pkgs.kmod ];
77 unitConfig.ConditionVirtualization = false;
80 RemainAfterExit = "yes";
81 ExecStart = "${cpupower}/bin/cpupower frequency-set " +
82 optionalString governorEnable "--governor ${cfg.cpuFreqGovernor} " +
83 optionalString maxEnable "--max ${toString cfg.cpufreq.max} " +
84 optionalString minEnable "--min ${toString cfg.cpufreq.min} ";
85 SuccessExitStatus = "0 237";