1 { config, lib, pkgs, ... }:
3 cfg = config.services.mbpfan;
4 verbose = lib.optionalString cfg.verbose "v";
5 format = pkgs.formats.ini {};
6 cfgfile = format.generate "mbpfan.ini" cfg.settings;
9 options.services.mbpfan = {
10 enable = lib.mkEnableOption "mbpfan, fan controller daemon for Apple Macs and MacBooks";
11 package = lib.mkPackageOption pkgs "mbpfan" {};
13 verbose = lib.mkOption {
14 type = lib.types.bool;
16 description = "If true, sets the log level to verbose.";
19 aggressive = lib.mkOption {
20 type = lib.types.bool;
22 description = "If true, favors higher default fan speeds.";
25 settings = lib.mkOption {
27 description = "INI configuration for Mbpfan.";
28 type = lib.types.submodule {
29 freeformType = format.type;
31 options.general.low_temp = lib.mkOption {
33 default = (if cfg.aggressive then 55 else 63);
34 defaultText = lib.literalExpression "55";
35 description = "If temperature is below this, fans will run at minimum speed.";
37 options.general.high_temp = lib.mkOption {
39 default = (if cfg.aggressive then 58 else 66);
40 defaultText = lib.literalExpression "58";
41 description = "If temperature is above this, fan speed will gradually increase.";
43 options.general.max_temp = lib.mkOption {
45 default = (if cfg.aggressive then 78 else 86);
46 defaultText = lib.literalExpression "78";
47 description = "If temperature is above this, fans will run at maximum speed.";
49 options.general.polling_interval = lib.mkOption {
52 description = "The polling interval.";
59 (lib.mkRenamedOptionModule [ "services" "mbpfan" "pollingInterval" ] [ "services" "mbpfan" "settings" "general" "polling_interval" ])
60 (lib.mkRenamedOptionModule [ "services" "mbpfan" "maxTemp" ] [ "services" "mbpfan" "settings" "general" "max_temp" ])
61 (lib.mkRenamedOptionModule [ "services" "mbpfan" "lowTemp" ] [ "services" "mbpfan" "settings" "general" "low_temp" ])
62 (lib.mkRenamedOptionModule [ "services" "mbpfan" "highTemp" ] [ "services" "mbpfan" "settings" "general" "high_temp" ])
63 (lib.mkRenamedOptionModule [ "services" "mbpfan" "minFanSpeed" ] [ "services" "mbpfan" "settings" "general" "min_fan1_speed" ])
64 (lib.mkRenamedOptionModule [ "services" "mbpfan" "maxFanSpeed" ] [ "services" "mbpfan" "settings" "general" "max_fan1_speed" ])
67 config = lib.mkIf cfg.enable {
68 boot.kernelModules = [ "coretemp" "applesmc" ];
69 environment.systemPackages = [ cfg.package ];
70 environment.etc."mbpfan.conf".source = cfgfile;
72 systemd.services.mbpfan = {
73 description = "A fan manager daemon for MacBook Pro";
74 wantedBy = [ "sysinit.target" ];
75 after = [ "sysinit.target" ];
76 restartTriggers = [ config.environment.etc."mbpfan.conf".source ];
80 ExecStart = "${cfg.package}/bin/mbpfan -f${verbose}";
81 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
82 PIDFile = "/run/mbpfan.pid";