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