nixpkgs/nixos/modules/services/misc/mbpfan.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
3.2 KiB
Nix
Raw Normal View History

2015-05-01 01:15:19 +00:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.mbpfan;
2023-03-19 20:44:31 +00:00
verbose = optionalString cfg.verbose "v";
2024-01-10 09:31:40 +00:00
format = pkgs.formats.ini {};
cfgfile = format.generate "mbpfan.ini" cfg.settings;
2015-05-01 01:15:19 +00:00
in {
options.services.mbpfan = {
enable = mkEnableOption "mbpfan, fan controller daemon for Apple Macs and MacBooks";
2024-01-10 09:31:40 +00:00
package = mkPackageOption pkgs "mbpfan" {};
2015-05-01 01:15:19 +00:00
verbose = mkOption {
type = types.bool;
default = false;
description = "If true, sets the log level to verbose.";
2023-02-19 13:55:04 +00:00
};
aggressive = mkOption {
type = types.bool;
2023-09-11 11:05:57 +00:00
default = true;
description = "If true, favors higher default fan speeds.";
};
settings = mkOption {
default = {};
description = "INI configuration for Mbpfan.";
type = types.submodule {
2024-01-10 09:31:40 +00:00
freeformType = format.type;
options.general.low_temp = mkOption {
type = types.int;
2023-09-11 11:05:57 +00:00
default = (if cfg.aggressive then 55 else 63);
defaultText = literalExpression "55";
description = "If temperature is below this, fans will run at minimum speed.";
};
options.general.high_temp = mkOption {
type = types.int;
2023-09-11 11:05:57 +00:00
default = (if cfg.aggressive then 58 else 66);
defaultText = literalExpression "58";
description = "If temperature is above this, fan speed will gradually increase.";
};
options.general.max_temp = mkOption {
type = types.int;
2023-09-11 11:05:57 +00:00
default = (if cfg.aggressive then 78 else 86);
defaultText = literalExpression "78";
description = "If temperature is above this, fans will run at maximum speed.";
};
options.general.polling_interval = mkOption {
type = types.int;
default = 1;
description = "The polling interval.";
};
};
};
2015-05-01 01:15:19 +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" ])
];
2015-05-01 01:15:19 +00:00
config = mkIf cfg.enable {
2023-02-19 13:55:04 +00:00
boot.kernelModules = [ "coretemp" "applesmc" ];
environment.systemPackages = [ cfg.package ];
2024-01-10 09:31:40 +00:00
environment.etc."mbpfan.conf".source = cfgfile;
2015-05-01 01:15:19 +00:00
systemd.services.mbpfan = {
description = "A fan manager daemon for MacBook Pro";
wantedBy = [ "sysinit.target" ];
2024-04-04 13:07:14 +00:00
after = [ "sysinit.target" ];
2015-05-01 01:15:19 +00:00
restartTriggers = [ config.environment.etc."mbpfan.conf".source ];
2023-09-11 11:05:57 +00:00
2015-05-01 01:15:19 +00:00
serviceConfig = {
Type = "simple";
ExecStart = "${cfg.package}/bin/mbpfan -f${verbose}";
2015-05-01 01:15:19 +00:00
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
2018-12-19 21:37:45 +00:00
PIDFile = "/run/mbpfan.pid";
2015-05-01 01:15:19 +00:00
Restart = "always";
};
};
};
}