2021-05-18 00:31:45 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.gamemode;
|
2024-09-28 14:56:57 +00:00
|
|
|
settingsFormat = pkgs.formats.ini { listsAsDuplicateKeys = true; };
|
2021-05-18 00:31:45 +00:00
|
|
|
configFile = settingsFormat.generate "gamemode.ini" cfg.settings;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
programs.gamemode = {
|
2024-04-17 11:37:58 +00:00
|
|
|
enable = lib.mkEnableOption "GameMode to optimise system performance on demand";
|
2021-05-18 00:31:45 +00:00
|
|
|
|
2024-04-17 11:37:58 +00:00
|
|
|
enableRenice =
|
|
|
|
lib.mkEnableOption "CAP_SYS_NICE on gamemoded to support lowering process niceness"
|
|
|
|
// {
|
2021-05-18 00:31:45 +00:00
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
2024-04-17 11:37:58 +00:00
|
|
|
settings = lib.mkOption {
|
2021-05-18 00:31:45 +00:00
|
|
|
type = settingsFormat.type;
|
2023-12-07 13:52:08 +00:00
|
|
|
default = { };
|
2021-05-18 00:31:45 +00:00
|
|
|
description = ''
|
|
|
|
System-wide configuration for GameMode (/etc/gamemode.ini).
|
|
|
|
See gamemoded(8) man page for available settings.
|
|
|
|
'';
|
2024-04-17 11:37:58 +00:00
|
|
|
example = lib.literalExpression ''
|
2021-05-18 00:31:45 +00:00
|
|
|
{
|
|
|
|
general = {
|
|
|
|
renice = 10;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Warning: GPU optimisations have the potential to damage hardware
|
|
|
|
gpu = {
|
|
|
|
apply_gpu_optimisations = "accept-responsibility";
|
|
|
|
gpu_device = 0;
|
|
|
|
amd_performance_level = "high";
|
|
|
|
};
|
|
|
|
|
|
|
|
custom = {
|
|
|
|
start = "''${pkgs.libnotify}/bin/notify-send 'GameMode started'";
|
|
|
|
end = "''${pkgs.libnotify}/bin/notify-send 'GameMode ended'";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-04-17 11:37:58 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2021-05-18 00:31:45 +00:00
|
|
|
environment = {
|
|
|
|
systemPackages = [ pkgs.gamemode ];
|
|
|
|
etc."gamemode.ini".source = configFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
security = {
|
|
|
|
polkit.enable = true;
|
2024-04-17 11:37:58 +00:00
|
|
|
wrappers = lib.mkIf cfg.enableRenice {
|
2021-05-18 00:31:45 +00:00
|
|
|
gamemoded = {
|
2021-09-12 16:53:48 +00:00
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
2021-05-18 00:31:45 +00:00
|
|
|
source = "${pkgs.gamemode}/bin/gamemoded";
|
|
|
|
capabilities = "cap_sys_nice+ep";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd = {
|
|
|
|
packages = [ pkgs.gamemode ];
|
|
|
|
user.services.gamemoded = {
|
|
|
|
# The upstream service already defines this, but doesn't get applied.
|
|
|
|
# See https://github.com/NixOS/nixpkgs/issues/81138
|
|
|
|
wantedBy = [ "default.target" ];
|
|
|
|
|
|
|
|
# Use pkexec from the security wrappers to allow users to
|
|
|
|
# run libexec/cpugovctl & libexec/gpuclockctl as root with
|
|
|
|
# the the actions defined in share/polkit-1/actions.
|
|
|
|
#
|
|
|
|
# This uses a link farm to make sure other wrapped executables
|
|
|
|
# aren't included in PATH.
|
2024-04-17 11:37:58 +00:00
|
|
|
environment.PATH = lib.mkForce (
|
|
|
|
pkgs.linkFarm "pkexec" [
|
2021-05-18 00:31:45 +00:00
|
|
|
{
|
|
|
|
name = "pkexec";
|
|
|
|
path = "${config.security.wrapperDir}/pkexec";
|
|
|
|
}
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2024-04-17 11:37:58 +00:00
|
|
|
serviceConfig.ExecStart = lib.mkIf cfg.enableRenice [
|
2021-05-18 00:31:45 +00:00
|
|
|
"" # Tell systemd to clear the existing ExecStart list, to prevent appending to it.
|
|
|
|
"${config.security.wrapperDir}/gamemoded"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2024-01-18 22:44:01 +00:00
|
|
|
|
|
|
|
users.groups.gamemode = { };
|
2021-05-18 00:31:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
meta = {
|
2024-04-17 11:37:58 +00:00
|
|
|
maintainers = with lib.maintainers; [ kira-bruneau ];
|
2021-05-18 00:31:45 +00:00
|
|
|
};
|
|
|
|
}
|