at 18.03-beta 2.5 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.mbpfan; 7 verbose = if cfg.verbose then "v" else ""; 8 9in { 10 options.services.mbpfan = { 11 enable = mkEnableOption "mbpfan, fan controller daemon for Apple Macs and MacBooks"; 12 13 package = mkOption { 14 type = types.package; 15 default = pkgs.mbpfan; 16 defaultText = "pkgs.mbpfan"; 17 description = '' 18 The package used for the mbpfan daemon. 19 ''; 20 }; 21 22 minFanSpeed = mkOption { 23 type = types.int; 24 default = 2000; 25 description = '' 26 The minimum fan speed. 27 ''; 28 }; 29 30 maxFanSpeed = mkOption { 31 type = types.int; 32 default = 6200; 33 description = '' 34 The maximum fan speed. 35 ''; 36 }; 37 38 lowTemp = mkOption { 39 type = types.int; 40 default = 63; 41 description = '' 42 The low temperature. 43 ''; 44 }; 45 46 highTemp = mkOption { 47 type = types.int; 48 default = 66; 49 description = '' 50 The high temperature. 51 ''; 52 }; 53 54 maxTemp = mkOption { 55 type = types.int; 56 default = 86; 57 description = '' 58 The maximum temperature. 59 ''; 60 }; 61 62 pollingInterval = mkOption { 63 type = types.int; 64 default = 7; 65 description = '' 66 The polling interval. 67 ''; 68 }; 69 70 verbose = mkOption { 71 type = types.bool; 72 default = false; 73 description = '' 74 If true, sets the log level to verbose. 75 ''; 76 }; 77 }; 78 79 config = mkIf cfg.enable { 80 boot.kernelModules = [ "coretemp" "applesmc" ]; 81 82 environment = { 83 etc."mbpfan.conf".text = '' 84 [general] 85 min_fan_speed = ${toString cfg.minFanSpeed} 86 max_fan_speed = ${toString cfg.maxFanSpeed} 87 low_temp = ${toString cfg.lowTemp} 88 high_temp = ${toString cfg.highTemp} 89 max_temp = ${toString cfg.maxTemp} 90 polling_interval = ${toString cfg.pollingInterval} 91 ''; 92 systemPackages = [ cfg.package ]; 93 }; 94 95 systemd.services.mbpfan = { 96 description = "A fan manager daemon for MacBook Pro"; 97 wantedBy = [ "sysinit.target" ]; 98 after = [ "syslog.target" "sysinit.target" ]; 99 restartTriggers = [ config.environment.etc."mbpfan.conf".source ]; 100 serviceConfig = { 101 Type = "simple"; 102 ExecStart = "${cfg.package}/bin/mbpfan -f${verbose}"; 103 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 104 PIDFile = "/var/run/mbpfan.pid"; 105 Restart = "always"; 106 }; 107 }; 108 }; 109}