blob: 01df7ae3fb5f42a6b794698230dc6cd487756334 (
plain)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
{
config,
lib,
pkgs,
...
}:
let
configFormat = pkgs.formats.json { };
cfg = config.hardware.fw-fanctrl;
in
{
options.hardware.fw-fanctrl = {
enable = lib.mkEnableOption "the fw-fanctrl systemd service and install the needed packages";
package = lib.mkPackageOption pkgs "fw-fanctrl" { };
ectoolPackage = lib.mkPackageOption pkgs "fw-ectool" { };
disableBatteryTempCheck = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Disable checking battery temperature sensor
'';
};
config = lib.mkOption {
default = { };
description = ''
Additional config entries for the fw-fanctrl service (documentation: <https://github.com/TamtamHero/fw-fanctrl/blob/main/doc/configuration.md>)
'';
type = lib.types.submodule {
freeformType = lib.types.attrsOf configFormat.type;
options = {
defaultStrategy = lib.mkOption {
type = lib.types.str;
default = "lazy";
description = "Default strategy to use";
};
strategyOnDischarging = lib.mkOption {
type = lib.types.str;
default = "";
description = "Default strategy on discharging";
};
strategies = lib.mkOption {
default = { };
description = ''
Additional strategies which can be used by fw-fanctrl
'';
type = lib.types.attrsOf (
lib.types.submodule {
options = {
fanSpeedUpdateFrequency = lib.mkOption {
type = lib.types.ints.unsigned;
default = 5;
description = "How often the fan speed should be updated in seconds";
};
movingAverageInterval = lib.mkOption {
type = lib.types.ints.unsigned;
default = 25;
description = "Interval (seconds) of the last temperatures to use to calculate the average temperature";
};
speedCurve = lib.mkOption {
default = [ ];
description = "How should the speed curve look like";
type = lib.types.listOf (
lib.types.submodule {
options = {
temp = lib.mkOption {
type = lib.types.int;
default = 0;
description = "Temperature in °C at which the fan speed should be changed";
};
speed = lib.mkOption {
type = lib.types.ints.between 0 100;
default = 0;
description = "Percent how fast the fan should run at";
};
};
}
);
};
};
}
);
};
};
};
};
};
config =
let
defaultConfig = builtins.fromJSON (builtins.readFile "${cfg.package}/share/fw-fanctrl/config.json");
finalConfig = lib.attrsets.recursiveUpdate defaultConfig cfg.config;
configFile = configFormat.generate "custom.json" finalConfig;
in
lib.mkIf cfg.enable {
environment.systemPackages = [
cfg.package
cfg.ectoolPackage
];
systemd.services.fw-fanctrl = {
description = "Framework Fan Controller";
after = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
Restart = "always";
ExecStart = "${lib.getExe cfg.package} --output-format JSON run --config ${configFile} --silent ${lib.optionalString cfg.disableBatteryTempCheck "--no-battery-sensors"}";
ExecStopPost = "${lib.getExe cfg.ectoolPackage} autofanctrl";
};
wantedBy = [ "multi-user.target" ];
};
# Create suspend config
environment.etc."systemd/system-sleep/fw-fanctrl-suspend.sh".source =
"${cfg.package}/share/fw-fanctrl/fw-fanctrl-suspend";
};
meta = {
maintainers = [ lib.maintainers.Svenum ];
};
}
|