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