nixos/corectrl: nixfmt and refactor

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2024-10-29 18:53:31 +01:00
parent 0269ce97e6
commit 4c7ab52fcb
No known key found for this signature in database
GPG Key ID: E13DFD4B47127951

View File

@ -1,23 +1,35 @@
{ config, pkgs, lib, ... }: {
config,
pkgs,
lib,
...
}:
let let
inherit (lib)
mkEnableOption
mkIf
mkOption
mkPackageOption
;
cfg = config.programs.corectrl; cfg = config.programs.corectrl;
in in
{ {
options.programs.corectrl = { options.programs.corectrl = {
enable = lib.mkEnableOption '' enable = mkEnableOption ''
CoreCtrl, a tool to overclock amd graphics cards and processors. CoreCtrl, 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 Add your user to the corectrl group to run corectrl without needing to enter your password
''; '';
package = lib.mkPackageOption pkgs "corectrl" { package = mkPackageOption pkgs "corectrl" {
extraDescription = "Useful for overriding the configuration options used for the package."; extraDescription = "Useful for overriding the configuration options used for the package.";
}; };
gpuOverclock = { gpuOverclock = {
enable = lib.mkEnableOption '' enable = mkEnableOption ''
GPU overclocking GPU overclocking
''; '';
ppfeaturemask = lib.mkOption { ppfeaturemask = mkOption {
type = lib.types.str; type = lib.types.str;
default = "0xfffd7fff"; default = "0xfffd7fff";
example = "0xffffffff"; example = "0xffffffff";
@ -31,33 +43,34 @@ in
}; };
}; };
config = lib.mkIf cfg.enable (lib.mkMerge [ config = mkIf cfg.enable {
{ environment.systemPackages = [ cfg.package ];
environment.systemPackages = [ cfg.package ];
services.dbus.packages = [ cfg.package ]; services.dbus.packages = [ cfg.package ];
users.groups.corectrl = { }; users.groups.corectrl = { };
security.polkit.extraConfig = '' security.polkit.extraConfig = ''
polkit.addRule(function(action, subject) { polkit.addRule(function(action, subject) {
if ((action.id == "org.corectrl.helper.init" || if ((action.id == "org.corectrl.helper.init" ||
action.id == "org.corectrl.helperkiller.init") && action.id == "org.corectrl.helperkiller.init") &&
subject.local == true && subject.local == true &&
subject.active == true && subject.active == true &&
subject.isInGroup("corectrl")) { subject.isInGroup("corectrl")) {
return polkit.Result.YES; 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
# 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
# The overdrive bit boot.kernelParams = mkIf cfg.gpuOverclock.enable [
boot.kernelParams = [ "amdgpu.ppfeaturemask=${cfg.gpuOverclock.ppfeaturemask}" ]; "amdgpu.ppfeaturemask=${cfg.gpuOverclock.ppfeaturemask}"
}) ];
]); };
meta.maintainers = with lib.maintainers; [ artturin Scrumplex ]; meta.maintainers = with lib.maintainers; [
artturin
Scrumplex
];
} }