1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 cfg = config.services.throttled;
9in
10{
11 options = {
12 services.throttled = {
13 enable = lib.mkEnableOption "fix for Intel CPU throttling";
14
15 extraConfig = lib.mkOption {
16 type = lib.types.str;
17 default = "";
18 description = "Alternative configuration";
19 };
20 };
21 };
22
23 config = lib.mkIf cfg.enable {
24 systemd.packages = [ pkgs.throttled ];
25 # The upstream package has this in Install, but that's not enough, see the NixOS manual
26 systemd.services.throttled.wantedBy = [ "multi-user.target" ];
27
28 environment.etc."throttled.conf".source =
29 if cfg.extraConfig != "" then
30 pkgs.writeText "throttled.conf" cfg.extraConfig
31 else
32 "${pkgs.throttled}/etc/throttled.conf";
33
34 hardware.cpu.x86.msr.enable = true;
35 # Kernel 5.9 spams warnings whenever userspace writes to CPU MSRs.
36 # See https://github.com/erpalma/throttled/issues/215
37 hardware.cpu.x86.msr.settings.allow-writes =
38 lib.mkIf (lib.versionAtLeast config.boot.kernelPackages.kernel.version "5.9") "on";
39 };
40}