at 23.11-pre 1.8 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.hardware.fancontrol; 7 configFile = pkgs.writeText "fancontrol.conf" cfg.config; 8 9in 10{ 11 options.hardware.fancontrol = { 12 enable = mkEnableOption (lib.mdDoc "software fan control (requires fancontrol.config)"); 13 14 config = mkOption { 15 type = types.lines; 16 description = lib.mdDoc "Required fancontrol configuration file content. See {manpage}`pwmconfig(8)` from the lm_sensors package."; 17 example = '' 18 # Configuration file generated by pwmconfig 19 INTERVAL=10 20 DEVPATH=hwmon3=devices/virtual/thermal/thermal_zone2 hwmon4=devices/platform/f71882fg.656 21 DEVNAME=hwmon3=soc_dts1 hwmon4=f71869a 22 FCTEMPS=hwmon4/device/pwm1=hwmon3/temp1_input 23 FCFANS=hwmon4/device/pwm1=hwmon4/device/fan1_input 24 MINTEMP=hwmon4/device/pwm1=35 25 MAXTEMP=hwmon4/device/pwm1=65 26 MINSTART=hwmon4/device/pwm1=150 27 MINSTOP=hwmon4/device/pwm1=0 28 ''; 29 }; 30 }; 31 32 config = mkIf cfg.enable { 33 34 systemd.services.fancontrol = { 35 documentation = [ "man:fancontrol(8)" ]; 36 description = "software fan control"; 37 wantedBy = [ "multi-user.target" ]; 38 after = [ "lm_sensors.service" ]; 39 40 serviceConfig = { 41 Restart = "on-failure"; 42 ExecStart = "${pkgs.lm_sensors}/sbin/fancontrol ${configFile}"; 43 }; 44 }; 45 46 # On some systems, the fancontrol service does not resume properly after sleep because the pwm status of the fans 47 # is not reset properly. Restarting the service fixes this, in accordance with https://github.com/lm-sensors/lm-sensors/issues/172. 48 powerManagement.resumeCommands = '' 49 systemctl restart fancontrol.service 50 ''; 51 52 }; 53 54 meta.maintainers = [ maintainers.evils ]; 55}