1 { config, lib, pkgs, ... }:
6 cfg = config.services.mbpfan;
7 verbose = if cfg.verbose then "v" else "";
8 settingsFormat = pkgs.formats.ini {};
9 settingsFile = settingsFormat.generate "mbpfan.ini" cfg.settings;
12 options.services.mbpfan = {
13 enable = mkEnableOption (lib.mdDoc "mbpfan, fan controller daemon for Apple Macs and MacBooks");
17 default = pkgs.mbpfan;
18 defaultText = literalExpression "pkgs.mbpfan";
19 description = lib.mdDoc ''
20 The package used for the mbpfan daemon.
27 description = lib.mdDoc ''
28 If true, sets the log level to verbose.
34 description = lib.mdDoc "INI configuration for Mbpfan.";
35 type = types.submodule {
36 freeformType = settingsFormat.type;
38 options.general.min_fan1_speed = mkOption {
39 type = types.nullOr types.int;
41 description = lib.mdDoc ''
42 You can check minimum and maximum fan limits with
43 `cat /sys/devices/platform/applesmc.768/fan*_min` and
44 `cat /sys/devices/platform/applesmc.768/fan*_max` respectively.
45 Setting to null implies using default value from applesmc.
48 options.general.low_temp = mkOption {
51 description = lib.mdDoc "If temperature is below this, fans will run at minimum speed.";
53 options.general.high_temp = mkOption {
56 description = lib.mdDoc "If temperature is above this, fan speed will gradually increase.";
58 options.general.max_temp = mkOption {
61 description = lib.mdDoc "If temperature is above this, fans will run at maximum speed.";
63 options.general.polling_interval = mkOption {
66 description = lib.mdDoc "The polling interval.";
73 (mkRenamedOptionModule [ "services" "mbpfan" "pollingInterval" ] [ "services" "mbpfan" "settings" "general" "polling_interval" ])
74 (mkRenamedOptionModule [ "services" "mbpfan" "maxTemp" ] [ "services" "mbpfan" "settings" "general" "max_temp" ])
75 (mkRenamedOptionModule [ "services" "mbpfan" "lowTemp" ] [ "services" "mbpfan" "settings" "general" "low_temp" ])
76 (mkRenamedOptionModule [ "services" "mbpfan" "highTemp" ] [ "services" "mbpfan" "settings" "general" "high_temp" ])
77 (mkRenamedOptionModule [ "services" "mbpfan" "minFanSpeed" ] [ "services" "mbpfan" "settings" "general" "min_fan1_speed" ])
78 (mkRenamedOptionModule [ "services" "mbpfan" "maxFanSpeed" ] [ "services" "mbpfan" "settings" "general" "max_fan1_speed" ])
81 config = mkIf cfg.enable {
82 boot.kernelModules = [ "coretemp" "applesmc" ];
84 environment.etc."mbpfan.conf".source = settingsFile;
85 environment.systemPackages = [ cfg.package ];
87 systemd.services.mbpfan = {
88 description = "A fan manager daemon for MacBook Pro";
89 wantedBy = [ "sysinit.target" ];
90 after = [ "syslog.target" "sysinit.target" ];
91 restartTriggers = [ config.environment.etc."mbpfan.conf".source ];
94 ExecStart = "${cfg.package}/bin/mbpfan -f${verbose}";
95 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
96 PIDFile = "/run/mbpfan.pid";