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