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