2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-12-16 23:44:37 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2011-12-16 23:44:37 +00:00
|
|
|
|
2014-03-17 23:07:46 +00:00
|
|
|
let
|
|
|
|
cpupower = config.boot.kernelPackages.cpupower;
|
2019-01-03 11:57:49 +00:00
|
|
|
cfg = config.powerManagement;
|
2014-03-17 23:07:46 +00:00
|
|
|
in
|
|
|
|
|
2011-12-16 23:44:37 +00:00
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
2019-01-03 11:57:49 +00:00
|
|
|
options.powerManagement = {
|
2012-08-23 16:12:25 +00:00
|
|
|
|
2019-01-03 11:57:49 +00:00
|
|
|
# TODO: This should be aliased to powerManagement.cpufreq.governor.
|
|
|
|
# https://github.com/NixOS/nixpkgs/pull/53041#commitcomment-31825338
|
|
|
|
cpuFreqGovernor = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2011-12-16 23:44:37 +00:00
|
|
|
example = "ondemand";
|
|
|
|
description = ''
|
2021-04-21 19:56:21 +00:00
|
|
|
Configure the governor used to regulate the frequency of the
|
2013-01-24 12:55:59 +00:00
|
|
|
available CPUs. By default, the kernel configures the
|
2019-01-03 11:57:49 +00:00
|
|
|
performance governor, although this may be overwritten in your
|
2018-12-29 13:09:47 +00:00
|
|
|
hardware-configuration.nix file.
|
|
|
|
|
|
|
|
Often used values: "ondemand", "powersave", "performance"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-01-03 11:57:49 +00:00
|
|
|
cpufreq = {
|
2018-12-29 13:09:47 +00:00
|
|
|
|
2019-01-03 11:57:49 +00:00
|
|
|
max = mkOption {
|
|
|
|
type = types.nullOr types.ints.unsigned;
|
|
|
|
default = null;
|
|
|
|
example = 2200000;
|
|
|
|
description = ''
|
|
|
|
The maximum frequency the CPU will use. Defaults to the maximum possible.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
min = mkOption {
|
|
|
|
type = types.nullOr types.ints.unsigned;
|
|
|
|
default = null;
|
|
|
|
example = 800000;
|
|
|
|
description = ''
|
|
|
|
The minimum frequency the CPU will use.
|
|
|
|
'';
|
|
|
|
};
|
2011-12-16 23:44:37 +00:00
|
|
|
};
|
2012-08-23 16:12:25 +00:00
|
|
|
|
2011-12-16 23:44:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2018-12-29 13:09:47 +00:00
|
|
|
config =
|
|
|
|
let
|
2019-01-03 11:57:49 +00:00
|
|
|
governorEnable = cfg.cpuFreqGovernor != null;
|
|
|
|
maxEnable = cfg.cpufreq.max != null;
|
|
|
|
minEnable = cfg.cpufreq.min != null;
|
2018-12-29 13:09:47 +00:00
|
|
|
enable =
|
|
|
|
!config.boot.isContainer &&
|
|
|
|
(governorEnable || maxEnable || minEnable);
|
|
|
|
in
|
|
|
|
mkIf enable {
|
2011-12-20 22:44:58 +00:00
|
|
|
|
2019-01-03 11:57:49 +00:00
|
|
|
boot.kernelModules = optional governorEnable "cpufreq_${cfg.cpuFreqGovernor}";
|
2013-11-26 17:17:12 +00:00
|
|
|
|
2018-12-29 13:09:47 +00:00
|
|
|
environment.systemPackages = [ cpupower ];
|
2011-12-16 23:44:37 +00:00
|
|
|
|
2018-12-29 13:09:47 +00:00
|
|
|
systemd.services.cpufreq = {
|
|
|
|
description = "CPU Frequency Setup";
|
|
|
|
after = [ "systemd-modules-load.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ cpupower pkgs.kmod ];
|
|
|
|
unitConfig.ConditionVirtualization = false;
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = "yes";
|
|
|
|
ExecStart = "${cpupower}/bin/cpupower frequency-set " +
|
2019-01-03 11:57:49 +00:00
|
|
|
optionalString governorEnable "--governor ${cfg.cpuFreqGovernor} " +
|
|
|
|
optionalString maxEnable "--max ${toString cfg.cpufreq.max} " +
|
|
|
|
optionalString minEnable "--min ${toString cfg.cpufreq.min} ";
|
2018-12-29 13:09:47 +00:00
|
|
|
SuccessExitStatus = "0 237";
|
|
|
|
};
|
2011-12-16 23:44:37 +00:00
|
|
|
};
|
|
|
|
|
2014-03-17 23:07:46 +00:00
|
|
|
};
|
2011-12-16 23:44:37 +00:00
|
|
|
}
|