1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6 cfg = config.programs.corectrl;
7in
8{
9 options.programs.corectrl = {
10 enable = mkEnableOption (lib.mdDoc ''
11 A tool to overclock amd graphics cards and processors.
12 Add your user to the corectrl group to run corectrl without needing to enter your password
13 '');
14
15 gpuOverclock = {
16 enable = mkEnableOption (lib.mdDoc ''
17 true
18 '');
19 ppfeaturemask = mkOption {
20 type = types.str;
21 default = "0xfffd7fff";
22 example = "0xffffffff";
23 description = lib.mdDoc ''
24 Sets the `amdgpu.ppfeaturemask` kernel option.
25 In particular, it is used here to set the overdrive bit.
26 Default is `0xfffd7fff` as it is less likely to cause flicker issues.
27 Setting it to `0xffffffff` enables all features.
28 '';
29 };
30 };
31 };
32
33 config = mkIf cfg.enable (lib.mkMerge [
34 {
35 environment.systemPackages = [ pkgs.corectrl ];
36
37 services.dbus.packages = [ pkgs.corectrl ];
38
39 users.groups.corectrl = { };
40
41 security.polkit.extraConfig = ''
42 polkit.addRule(function(action, subject) {
43 if ((action.id == "org.corectrl.helper.init" ||
44 action.id == "org.corectrl.helperkiller.init") &&
45 subject.local == true &&
46 subject.active == true &&
47 subject.isInGroup("corectrl")) {
48 return polkit.Result.YES;
49 }
50 });
51 '';
52 }
53
54 (lib.mkIf cfg.gpuOverclock.enable {
55 # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/amd/include/amd_shared.h#n169
56 # The overdrive bit
57 boot.kernelParams = [ "amdgpu.ppfeaturemask=${cfg.gpuOverclock.ppfeaturemask}" ];
58 })
59 ]);
60
61 meta.maintainers = with lib.maintainers; [ artturin ];
62}