1 { config, lib, pkgs, ... }:
6 cfg = config.programs.gamemode;
7 settingsFormat = pkgs.formats.ini { };
8 configFile = settingsFormat.generate "gamemode.ini" cfg.settings;
13 enable = mkEnableOption (lib.mdDoc "GameMode to optimise system performance on demand");
15 enableRenice = mkEnableOption (lib.mdDoc "CAP_SYS_NICE on gamemoded to support lowering process niceness") // {
20 type = settingsFormat.type;
22 description = lib.mdDoc ''
23 System-wide configuration for GameMode (/etc/gamemode.ini).
24 See gamemoded(8) man page for available settings.
26 example = literalExpression ''
32 # Warning: GPU optimisations have the potential to damage hardware
34 apply_gpu_optimisations = "accept-responsibility";
36 amd_performance_level = "high";
40 start = "''${pkgs.libnotify}/bin/notify-send 'GameMode started'";
41 end = "''${pkgs.libnotify}/bin/notify-send 'GameMode ended'";
49 config = mkIf cfg.enable {
51 systemPackages = [ pkgs.gamemode ];
52 etc."gamemode.ini".source = configFile;
57 wrappers = mkIf cfg.enableRenice {
61 source = "${pkgs.gamemode}/bin/gamemoded";
62 capabilities = "cap_sys_nice+ep";
68 packages = [ pkgs.gamemode ];
69 user.services.gamemoded = {
70 # The upstream service already defines this, but doesn't get applied.
71 # See https://github.com/NixOS/nixpkgs/issues/81138
72 wantedBy = [ "default.target" ];
74 # Use pkexec from the security wrappers to allow users to
75 # run libexec/cpugovctl & libexec/gpuclockctl as root with
76 # the the actions defined in share/polkit-1/actions.
78 # This uses a link farm to make sure other wrapped executables
79 # aren't included in PATH.
80 environment.PATH = mkForce (pkgs.linkFarm "pkexec" [
83 path = "${config.security.wrapperDir}/pkexec";
87 serviceConfig.ExecStart = mkIf cfg.enableRenice [
88 "" # Tell systemd to clear the existing ExecStart list, to prevent appending to it.
89 "${config.security.wrapperDir}/gamemoded"
96 maintainers = with maintainers; [ kira-bruneau ];