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