2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.mbpfan;
|
2023-04-29 16:46:19 +00:00
|
|
|
verbose = optionalString cfg.verbose "v";
|
2024-04-21 15:54:59 +00:00
|
|
|
format = pkgs.formats.ini {};
|
|
|
|
cfgfile = format.generate "mbpfan.ini" cfg.settings;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
in {
|
|
|
|
options.services.mbpfan = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "mbpfan, fan controller daemon for Apple Macs and MacBooks";
|
|
|
|
package = mkPackageOption pkgs "mbpfan" {};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
verbose = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "If true, sets the log level to verbose.";
|
2023-02-22 10:55:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
aggressive = mkOption {
|
|
|
|
type = types.bool;
|
2023-10-09 19:29:22 +00:00
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "If true, favors higher default fan speeds.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2022-01-19 23:45:15 +00:00
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
default = {};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "INI configuration for Mbpfan.";
|
2022-01-19 23:45:15 +00:00
|
|
|
type = types.submodule {
|
2024-04-21 15:54:59 +00:00
|
|
|
freeformType = format.type;
|
2022-01-19 23:45:15 +00:00
|
|
|
|
|
|
|
options.general.low_temp = mkOption {
|
|
|
|
type = types.int;
|
2023-10-09 19:29:22 +00:00
|
|
|
default = (if cfg.aggressive then 55 else 63);
|
|
|
|
defaultText = literalExpression "55";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "If temperature is below this, fans will run at minimum speed.";
|
2022-01-19 23:45:15 +00:00
|
|
|
};
|
|
|
|
options.general.high_temp = mkOption {
|
|
|
|
type = types.int;
|
2023-10-09 19:29:22 +00:00
|
|
|
default = (if cfg.aggressive then 58 else 66);
|
|
|
|
defaultText = literalExpression "58";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "If temperature is above this, fan speed will gradually increase.";
|
2022-01-19 23:45:15 +00:00
|
|
|
};
|
|
|
|
options.general.max_temp = mkOption {
|
|
|
|
type = types.int;
|
2023-10-09 19:29:22 +00:00
|
|
|
default = (if cfg.aggressive then 78 else 86);
|
|
|
|
defaultText = literalExpression "78";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "If temperature is above this, fans will run at maximum speed.";
|
2022-01-19 23:45:15 +00:00
|
|
|
};
|
|
|
|
options.general.polling_interval = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "The polling interval.";
|
2022-01-19 23:45:15 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2022-01-19 23:45:15 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "mbpfan" "pollingInterval" ] [ "services" "mbpfan" "settings" "general" "polling_interval" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "mbpfan" "maxTemp" ] [ "services" "mbpfan" "settings" "general" "max_temp" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "mbpfan" "lowTemp" ] [ "services" "mbpfan" "settings" "general" "low_temp" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "mbpfan" "highTemp" ] [ "services" "mbpfan" "settings" "general" "high_temp" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "mbpfan" "minFanSpeed" ] [ "services" "mbpfan" "settings" "general" "min_fan1_speed" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "mbpfan" "maxFanSpeed" ] [ "services" "mbpfan" "settings" "general" "max_fan1_speed" ])
|
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
config = mkIf cfg.enable {
|
2023-02-22 10:55:15 +00:00
|
|
|
boot.kernelModules = [ "coretemp" "applesmc" ];
|
2022-01-19 23:45:15 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2024-04-21 15:54:59 +00:00
|
|
|
environment.etc."mbpfan.conf".source = cfgfile;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
systemd.services.mbpfan = {
|
|
|
|
description = "A fan manager daemon for MacBook Pro";
|
|
|
|
wantedBy = [ "sysinit.target" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
after = [ "sysinit.target" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
restartTriggers = [ config.environment.etc."mbpfan.conf".source ];
|
2023-10-09 19:29:22 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
ExecStart = "${cfg.package}/bin/mbpfan -f${verbose}";
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
PIDFile = "/run/mbpfan.pid";
|
|
|
|
Restart = "always";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|