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 ${cfg.levels} 47 ''; 48 49in { 50 51 options = { 52 53 services.thinkfan = { 54 55 enable = mkOption { 56 default = false; 57 description = '' 58 Whether to enable thinkfan, fan controller for ibm/lenovo thinkpads. 59 ''; 60 }; 61 62 sensor = mkOption { 63 default = "/proc/acpi/ibm/thermal"; 64 description ='' 65 Sensor used by thinkfan 66 ''; 67 }; 68 69 levels = mkOption { 70 default = '' 71 (0, 0, 55) 72 (1, 48, 60) 73 (2, 50, 61) 74 (3, 52, 63) 75 (6, 56, 65) 76 (7, 60, 85) 77 (127, 80, 32767) 78 ''; 79 description ='' 80 Sensor used by thinkfan 81 ''; 82 }; 83 84 85 }; 86 87 }; 88 89 config = mkIf cfg.enable { 90 91 environment.systemPackages = [ pkgs.thinkfan ]; 92 93 systemd.services.thinkfan = { 94 description = "Thinkfan"; 95 after = [ "basic.target" ]; 96 wantedBy = [ "multi-user.target" ]; 97 path = [ pkgs.thinkfan ]; 98 serviceConfig.ExecStart = "${pkgs.thinkfan}/bin/thinkfan -n -c ${configFile}"; 99 }; 100 101 boot.extraModprobeConfig = "options thinkpad_acpi experimental=1 fan_control=1"; 102 103 }; 104 105}