1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.thinkfan;
8 configFile = pkgs.writeText "thinkfan.conf" ''
9 # ATTENTION: There is only very basic sanity checking on the configuration.
10 # That means you can set your temperature limits as insane as you like. You
11 # can do anything stupid, e.g. turn off your fan when your CPU reaches 70°C.
12 #
13 # That's why this program is called THINKfan: You gotta think for yourself.
14 #
15 ######################################################################
16 #
17 # IBM/Lenovo Thinkpads (thinkpad_acpi, /proc/acpi/ibm)
18 # ====================================================
19 #
20 # IMPORTANT:
21 #
22 # To keep your HD from overheating, you have to specify a correction value for
23 # the sensor that has the HD's temperature. You need to do this because
24 # thinkfan uses only the highest temperature it can find in the system, and
25 # that'll most likely never be your HD, as most HDs are already out of spec
26 # when they reach 55 °C.
27 # Correction values are applied from left to right in the same order as the
28 # temperatures are read from the file.
29 #
30 # For example:
31 # sensor /proc/acpi/ibm/thermal (0, 0, 10)
32 # will add a fixed value of 10 °C the 3rd value read from that file. Check out
33 # http://www.thinkwiki.org/wiki/Thermal_Sensors to find out how much you may
34 # want to add to certain temperatures.
35
36 # Syntax:
37 # (LEVEL, LOW, HIGH)
38 # LEVEL is the fan level to use (0-7 with thinkpad_acpi)
39 # LOW is the temperature at which to step down to the previous level
40 # HIGH is the temperature at which to step up to the next level
41 # All numbers are integers.
42 #
43
44 sensor ${cfg.sensor} (0, 10, 15, 2, 10, 5, 0, 3, 0, 3)
45
46 (0, 0, 55)
47 (1, 48, 60)
48 (2, 50, 61)
49 (3, 52, 63)
50 (6, 56, 65)
51 (7, 60, 85)
52 (127, 80, 32767)
53 '';
54
55in {
56
57 options = {
58
59 services.thinkfan = {
60
61 enable = mkOption {
62 default = false;
63 description = ''
64 Whether to enable thinkfan, fan controller for ibm/lenovo thinkpads.
65 '';
66 };
67
68 sensor = mkOption {
69 default = "/proc/acpi/ibm/thermal";
70 description =''
71 Sensor used by thinkfan
72 '';
73 };
74
75 };
76
77 };
78
79 config = mkIf cfg.enable {
80
81 environment.systemPackages = [ pkgs.thinkfan ];
82
83 systemd.services.thinkfan = {
84 description = "Thinkfan";
85 after = [ "basic.target" ];
86 wantedBy = [ "multi-user.target" ];
87 path = [ pkgs.thinkfan ];
88 serviceConfig.ExecStart = "${pkgs.thinkfan}/bin/thinkfan -n -c ${configFile}";
89 };
90
91 boot.extraModprobeConfig = "options thinkpad_acpi experimental=1 fan_control=1";
92
93 };
94
95}