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