summary refs log tree commit diff
path: root/nixos/modules/hardware/corectrl.nix
blob: 3185f6486c71e5740200ebfb4d006f9cbb5b3a75 (plain) (blame)
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
{ config, pkgs, lib, ... }:

with lib;

let
  cfg = config.programs.corectrl;
in
{
  options.programs.corectrl = {
    enable = mkEnableOption ''
      A tool to overclock amd graphics cards and processors.
      Add your user to the corectrl group to run corectrl without needing to enter your password
    '';

    gpuOverclock = {
      enable = mkEnableOption ''
        true
      '';
      ppfeaturemask = mkOption {
        type = types.str;
        default = "0xfffd7fff";
        example = "0xffffffff";
        description = ''
          Sets the `amdgpu.ppfeaturemask` kernel option.
          In particular, it is used here to set the overdrive bit.
          Default is `0xfffd7fff` as it is less likely to cause flicker issues.
          Setting it to `0xffffffff` enables all features.
        '';
      };
    };
  };

  config = mkIf cfg.enable (lib.mkMerge [
    {
      environment.systemPackages = [ pkgs.corectrl ];

      services.dbus.packages = [ pkgs.corectrl ];

      users.groups.corectrl = { };

      security.polkit.extraConfig = ''
        polkit.addRule(function(action, subject) {
            if ((action.id == "org.corectrl.helper.init" ||
                 action.id == "org.corectrl.helperkiller.init") &&
                subject.local == true &&
                subject.active == true &&
                subject.isInGroup("corectrl")) {
                    return polkit.Result.YES;
            }
        });
      '';
    }

    (lib.mkIf cfg.gpuOverclock.enable {
      # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/amd/include/amd_shared.h#n169
      # The overdrive bit
      boot.kernelParams = [ "amdgpu.ppfeaturemask=${cfg.gpuOverclock.ppfeaturemask}" ];
    })
  ]);

  meta.maintainers = with lib.maintainers; [ artturin ];
}