at 18.09-beta 1.2 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cpupower = config.boot.kernelPackages.cpupower; 7 cfg = config.powerManagement; 8in 9 10{ 11 ###### interface 12 13 options = { 14 15 powerManagement.cpuFreqGovernor = mkOption { 16 type = types.nullOr types.str; 17 default = null; 18 example = "ondemand"; 19 description = '' 20 Configure the governor used to regulate the frequence of the 21 available CPUs. By default, the kernel configures the 22 performance governor. 23 ''; 24 }; 25 26 }; 27 28 29 ###### implementation 30 31 config = mkIf (!config.boot.isContainer && config.powerManagement.cpuFreqGovernor != null) { 32 33 boot.kernelModules = [ "cpufreq_${cfg.cpuFreqGovernor}" ]; 34 35 environment.systemPackages = [ cpupower ]; 36 37 systemd.services.cpufreq = { 38 description = "CPU Frequency Governor Setup"; 39 after = [ "systemd-modules-load.service" ]; 40 wantedBy = [ "multi-user.target" ]; 41 path = [ cpupower pkgs.kmod ]; 42 unitConfig.ConditionVirtualization = false; 43 serviceConfig = { 44 Type = "oneshot"; 45 RemainAfterExit = "yes"; 46 ExecStart = "${cpupower}/bin/cpupower frequency-set -g ${cfg.cpuFreqGovernor}"; 47 SuccessExitStatus = "0 237"; 48 }; 49 }; 50 51 }; 52}