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

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

115 lines
3.5 KiB
Nix
Raw Permalink Normal View History

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