forked from grmat/amdgpu-fancontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
102 lines (87 loc) · 3.29 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{
description =
"Simple bash script to control AMD Radeon graphics cards fan speeds";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/master";
outputs = { self, nixpkgs }:
with nixpkgs; {
defaultPackage.x86_64-linux =
with import nixpkgs { system = "x86_64-linux"; };
stdenv.mkDerivation {
name = "amdgpu-fancontrol";
version = "1.0";
src = self;
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
mkdir -p $out/bin
cp amdgpu-fancontrol $out/bin/amdgpu-fancontrol
wrapProgram $out/bin/amdgpu-fancontrol --prefix PATH ":" ${
lib.makeBinPath [ "$out" coreutils bc ]
}
'';
};
nixosModules = {
amdgpu-fancontrol = { config, ... }:
let cfg = config.services.amdgpu-fancontrol;
in {
options.services.amdgpu-fancontrol = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description =
"Service to manually define fan curve for AMG GPUs";
};
debugLevel = lib.mkOption {
type = lib.types.int;
default = 0;
description = ''
Debugging to syslog.
1: log when changing fan speed (noisy)
2: also log current temperature on every loop (very noisy)
'';
};
fanCurve = lib.mkOption {
type = lib.types.listOf (lib.types.listOf lib.types.int);
default = [ [ 65 0 ] [ 80 153 ] [ 90 255 ] ];
description = ''
Define fan curve as a list of lists following the format:
```
[
[TEMP1 PWM1]
[TEMP2 PWM2]
]
```
Where `TEMP{N}` is a temperature in degrees Celsius, `PWM{N}` is a value between 0-255 to define
corresponding fan speed. Values between entries are calculated with linear interpolation.
'';
};
};
config = lib.mkIf cfg.enable {
systemd.services.amdgpu-fancontrol = {
description = "Fan speed management for AMD GPUs";
wantedBy = [ "multi-user.target" ];
path = [ self.defaultPackage.x86_64-linux ];
serviceConfig = {
ExecStart =
"${self.defaultPackage.x86_64-linux}/bin/amdgpu-fancontrol";
Type = "simple";
Restart = "on-failure";
};
};
environment.etc."amdgpu-fancontrol.cfg".text = ''
TEMPS=(${
builtins.concatStringsSep " " (builtins.map
(x: builtins.toString ((builtins.elemAt x 0) * 1000))
cfg.fanCurve)
})
PWMS=(${
builtins.concatStringsSep " "
(builtins.map (x: builtins.toString (builtins.elemAt x 1))
cfg.fanCurve)
})
DEBUG=${builtins.toString cfg.debugLevel}
'';
};
};
};
};
}