2014-04-14 18:26:48 +04:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-12-17 03:44:37 +04:00
|
|
|
|
2014-04-14 18:26:48 +04:00
|
|
|
with lib;
|
2011-12-17 03:44:37 +04:00
|
|
|
|
2014-03-18 03:07:46 +04:00
|
|
|
let
|
|
|
|
cpupower = config.boot.kernelPackages.cpupower;
|
|
|
|
cfg = config.powerManagement;
|
|
|
|
in
|
|
|
|
|
2011-12-17 03:44:37 +04:00
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2012-08-23 20:12:25 +04:00
|
|
|
|
2011-12-21 02:44:58 +04:00
|
|
|
powerManagement.cpuFreqGovernor = mkOption {
|
2013-10-30 20:37:45 +04:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2011-12-17 03:44:37 +04:00
|
|
|
example = "ondemand";
|
|
|
|
description = ''
|
|
|
|
Configure the governor used to regulate the frequence of the
|
2013-01-24 16:55:59 +04:00
|
|
|
available CPUs. By default, the kernel configures the
|
|
|
|
on-demand governor.
|
2011-12-17 03:44:37 +04:00
|
|
|
'';
|
|
|
|
};
|
2012-08-23 20:12:25 +04:00
|
|
|
|
2011-12-17 03:44:37 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2014-04-16 03:11:32 +04:00
|
|
|
config = mkIf (!config.boot.isContainer && config.powerManagement.cpuFreqGovernor != null) {
|
2011-12-21 02:44:58 +04:00
|
|
|
|
2014-07-14 04:35:09 +04:00
|
|
|
boot.kernelModules = [ "cpufreq_${cfg.cpuFreqGovernor}" ];
|
2013-11-26 21:17:12 +04:00
|
|
|
|
2014-03-18 03:07:46 +04:00
|
|
|
environment.systemPackages = [ cpupower ];
|
2011-12-17 03:44:37 +04:00
|
|
|
|
2014-03-18 03:07:46 +04:00
|
|
|
systemd.services.cpufreq = {
|
|
|
|
description = "CPU Frequency Governor Setup";
|
|
|
|
after = [ "systemd-modules-load.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-05-24 22:36:56 +03:00
|
|
|
path = [ cpupower config.system.sbin.modprobe ];
|
2014-04-16 12:36:16 +04:00
|
|
|
unitConfig.ConditionVirtualization = false;
|
2014-03-18 03:07:46 +04:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = "yes";
|
2014-04-28 21:13:04 +04:00
|
|
|
ExecStart = "${cpupower}/bin/cpupower frequency-set -g ${cfg.cpuFreqGovernor}";
|
|
|
|
SuccessExitStatus = "0 237";
|
2011-12-17 03:44:37 +04:00
|
|
|
};
|
2014-03-18 03:07:46 +04:00
|
|
|
};
|
2011-12-17 03:44:37 +04:00
|
|
|
|
2014-03-18 03:07:46 +04:00
|
|
|
};
|
2011-12-17 03:44:37 +04:00
|
|
|
}
|