2020-10-17 11:59:01 +11:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
acfg = config.services.amdgpu;
|
|
|
|
cfg = config.services.amdgpu.fan;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options.services.amdgpu.fan = {
|
|
|
|
enable = mkEnableOption "amdgpu-fan";
|
|
|
|
|
2020-10-18 14:39:36 +11:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.amdgpu-fan or (import ../../.. { inherit pkgs; }).amdgpu-fan;
|
|
|
|
defaultText = "pkgs.amdgpu-fan";
|
|
|
|
};
|
|
|
|
|
2020-10-17 11:59:01 +11:00
|
|
|
speedMatrix = mkOption {
|
|
|
|
type = with types; listOf (listOf int);
|
|
|
|
# Translated from upstream default config. Since it tries to write the
|
|
|
|
# config if it's not found, we want some kind of default.
|
|
|
|
default = [
|
|
|
|
[ 0 0 ]
|
|
|
|
[ 30 33 ]
|
|
|
|
[ 45 50 ]
|
|
|
|
[ 60 66 ]
|
|
|
|
[ 65 69 ]
|
|
|
|
[ 70 75 ]
|
|
|
|
[ 75 89 ]
|
|
|
|
[ 80 100 ]
|
|
|
|
];
|
2021-11-13 19:15:05 +11:00
|
|
|
example = [
|
|
|
|
[ 0 0 ]
|
|
|
|
[ 40 30 ]
|
|
|
|
[ 60 50 ]
|
|
|
|
[ 80 100 ]
|
|
|
|
];
|
2020-10-17 11:59:01 +11:00
|
|
|
description = ''
|
|
|
|
A list of temperature-fan speed pairs. The temperature is specified in
|
|
|
|
degrees celcius, and speed is specified in %.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = singleton {
|
|
|
|
assertion = all (speeds: length speeds == 2) cfg.speedMatrix;
|
2020-10-18 14:39:36 +11:00
|
|
|
message = "services.amdgpu.fan.speedMatrix must be a list of paired lists";
|
2020-10-17 11:59:01 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc."amdgpu-fan.yml".text = builtins.toJSON {
|
|
|
|
speed_matrix = cfg.speedMatrix;
|
|
|
|
cards = acfg.cards;
|
|
|
|
};
|
|
|
|
|
|
|
|
powerManagement.resumeCommands = "${pkgs.systemd}/bin/systemctl try-restart amdgpu-fan";
|
|
|
|
|
|
|
|
# Translated from the upstream service file.
|
|
|
|
systemd.services = {
|
|
|
|
amdgpu-fan = {
|
|
|
|
description = "amdgpu fan controller";
|
|
|
|
wantedBy = [ "default.target" ];
|
2020-10-18 14:39:36 +11:00
|
|
|
after = [ "amdgpu-pwm.service" ];
|
2020-10-17 11:59:01 +11:00
|
|
|
serviceConfig = {
|
2020-10-18 14:39:36 +11:00
|
|
|
ExecStart = "${cfg.package}/bin/amdgpu-fan";
|
2020-10-17 11:59:01 +11:00
|
|
|
Restart = "always";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|