Merge pull request #123433 from kira-bruneau/gamemode

authored by Sandro and committed by GitHub 0c85b23e 2854b524

+217
+1
nixos/modules/module-list.nix
··· 139 ./programs/flexoptix-app.nix 140 ./programs/freetds.nix 141 ./programs/fuse.nix 142 ./programs/geary.nix 143 ./programs/gnome-disks.nix 144 ./programs/gnome-documents.nix
··· 139 ./programs/flexoptix-app.nix 140 ./programs/freetds.nix 141 ./programs/fuse.nix 142 + ./programs/gamemode.nix 143 ./programs/geary.nix 144 ./programs/gnome-disks.nix 145 ./programs/gnome-documents.nix
+96
nixos/modules/programs/gamemode.nix
···
··· 1 + { config, lib, pkgs, ... }: 2 + 3 + with lib; 4 + 5 + let 6 + cfg = config.programs.gamemode; 7 + settingsFormat = pkgs.formats.ini { }; 8 + configFile = settingsFormat.generate "gamemode.ini" cfg.settings; 9 + in 10 + { 11 + options = { 12 + programs.gamemode = { 13 + enable = mkEnableOption "GameMode to optimise system performance on demand"; 14 + 15 + enableRenice = mkEnableOption "CAP_SYS_NICE on gamemoded to support lowering process niceness" // { 16 + default = true; 17 + }; 18 + 19 + settings = mkOption { 20 + type = settingsFormat.type; 21 + default = {}; 22 + description = '' 23 + System-wide configuration for GameMode (/etc/gamemode.ini). 24 + See gamemoded(8) man page for available settings. 25 + ''; 26 + example = literalExample '' 27 + { 28 + general = { 29 + renice = 10; 30 + }; 31 + 32 + # Warning: GPU optimisations have the potential to damage hardware 33 + gpu = { 34 + apply_gpu_optimisations = "accept-responsibility"; 35 + gpu_device = 0; 36 + amd_performance_level = "high"; 37 + }; 38 + 39 + custom = { 40 + start = "''${pkgs.libnotify}/bin/notify-send 'GameMode started'"; 41 + end = "''${pkgs.libnotify}/bin/notify-send 'GameMode ended'"; 42 + }; 43 + } 44 + ''; 45 + }; 46 + }; 47 + }; 48 + 49 + config = mkIf cfg.enable { 50 + environment = { 51 + systemPackages = [ pkgs.gamemode ]; 52 + etc."gamemode.ini".source = configFile; 53 + }; 54 + 55 + security = { 56 + polkit.enable = true; 57 + wrappers = mkIf cfg.enableRenice { 58 + gamemoded = { 59 + source = "${pkgs.gamemode}/bin/gamemoded"; 60 + capabilities = "cap_sys_nice+ep"; 61 + }; 62 + }; 63 + }; 64 + 65 + systemd = { 66 + packages = [ pkgs.gamemode ]; 67 + user.services.gamemoded = { 68 + # The upstream service already defines this, but doesn't get applied. 69 + # See https://github.com/NixOS/nixpkgs/issues/81138 70 + wantedBy = [ "default.target" ]; 71 + 72 + # Use pkexec from the security wrappers to allow users to 73 + # run libexec/cpugovctl & libexec/gpuclockctl as root with 74 + # the the actions defined in share/polkit-1/actions. 75 + # 76 + # This uses a link farm to make sure other wrapped executables 77 + # aren't included in PATH. 78 + environment.PATH = mkForce (pkgs.linkFarm "pkexec" [ 79 + { 80 + name = "pkexec"; 81 + path = "${config.security.wrapperDir}/pkexec"; 82 + } 83 + ]); 84 + 85 + serviceConfig.ExecStart = mkIf cfg.enableRenice [ 86 + "" # Tell systemd to clear the existing ExecStart list, to prevent appending to it. 87 + "${config.security.wrapperDir}/gamemoded" 88 + ]; 89 + }; 90 + }; 91 + }; 92 + 93 + meta = { 94 + maintainers = with maintainers; [ kira-bruneau ]; 95 + }; 96 + }
+104
pkgs/tools/games/gamemode/default.nix
···
··· 1 + { lib 2 + , stdenv 3 + , fetchFromGitHub 4 + , fetchpatch 5 + , libgamemode32 6 + , meson 7 + , ninja 8 + , pkg-config 9 + , dbus 10 + , inih 11 + , systemd 12 + , appstream 13 + }: 14 + 15 + stdenv.mkDerivation rec { 16 + pname = "gamemode"; 17 + version = "1.6.1"; 18 + 19 + src = fetchFromGitHub { 20 + owner = "FeralInteractive"; 21 + repo = pname; 22 + rev = version; 23 + sha256 = "sha256-P00OnZiPZyxBu9zuG+3JNorXHBhJZy+cKPjX+duZrJ0="; 24 + }; 25 + 26 + outputs = [ "out" "dev" "lib" "man" "static" ]; 27 + 28 + patches = [ 29 + # Run executables from PATH instead of /usr/bin 30 + # See https://github.com/FeralInteractive/gamemode/pull/323 31 + (fetchpatch { 32 + url = "https://github.com/FeralInteractive/gamemode/commit/be44b7091baa33be6dda60392e4c06c2f398ee72.patch"; 33 + sha256 = "TlDUETs4+N3pvrVd0FQGlGmC+6ByhJ2E7gKXa7suBtE="; 34 + }) 35 + 36 + # Fix loading shipped config when using a prefix other than /usr 37 + # See https://github.com/FeralInteractive/gamemode/pull/324 38 + (fetchpatch { 39 + url = "https://github.com/FeralInteractive/gamemode/commit/b29aa903ce5acc9141cfd3960c98ccb047eca872.patch"; 40 + sha256 = "LwBzBJQ7dfm2mFVSOSPjJP+skgV5N6h77i66L1Sq+ZM="; 41 + }) 42 + 43 + # Add @libraryPath@ template variable to fix loading the PRELOAD library 44 + ./preload-nix-workaround.patch 45 + ]; 46 + 47 + postPatch = '' 48 + substituteInPlace data/gamemoderun \ 49 + --subst-var-by libraryPath ${lib.makeLibraryPath ([ 50 + (placeholder "lib") 51 + ] ++ lib.optionals (stdenv.hostPlatform.system == "x86_64-linux") [ 52 + # Support wrapping 32bit applications on a 64bit linux system 53 + libgamemode32 54 + ])} 55 + ''; 56 + 57 + nativeBuildInputs = [ 58 + meson 59 + ninja 60 + pkg-config 61 + ]; 62 + 63 + buildInputs = [ 64 + dbus 65 + inih 66 + systemd 67 + ]; 68 + 69 + mesonFlags = [ 70 + # libexec is just a way to package binaries without including them 71 + # in PATH. It doesn't make sense to install them to $lib 72 + # (the default behaviour in the meson hook). 73 + "--libexecdir=${placeholder "out"}/libexec" 74 + 75 + "-Dwith-systemd-user-unit-dir=lib/systemd/user" 76 + ]; 77 + 78 + doCheck = true; 79 + checkInputs = [ 80 + appstream 81 + ]; 82 + 83 + # Move static libraries to $static so $lib only contains dynamic libraries. 84 + postInstall = '' 85 + moveToOutput lib/*.a "$static" 86 + ''; 87 + 88 + # Add $lib/lib to gamemoded & gamemode-simulate-game's rpath since 89 + # they use dlopen to load libgamemode. Can't use makeWrapper since 90 + # it would break the security wrapper in the NixOS module. 91 + postFixup = '' 92 + for bin in "$out/bin/gamemoded" "$out/bin/gamemode-simulate-game"; do 93 + patchelf --set-rpath "$lib/lib:$(patchelf --print-rpath "$bin")" "$bin" 94 + done 95 + ''; 96 + 97 + meta = with lib; { 98 + description = "Optimise Linux system performance on demand"; 99 + homepage = "https://github.com/FeralInteractive/GameMode"; 100 + license = licenses.bsd3; 101 + maintainers = with maintainers; [ kira-bruneau ]; 102 + platforms = platforms.linux; 103 + }; 104 + }
+12
pkgs/tools/games/gamemode/preload-nix-workaround.patch
···
··· 1 + diff --git a/data/gamemoderun b/data/gamemoderun 2 + index 573b3e4..6f2799e 100755 3 + --- a/data/gamemoderun 4 + +++ b/data/gamemoderun 5 + @@ -5,5 +5,6 @@ GAMEMODEAUTO_NAME="libgamemodeauto.so.0" 6 + 7 + # ld will find the right path to load the library, including for 32-bit apps. 8 + LD_PRELOAD="${GAMEMODEAUTO_NAME}${LD_PRELOAD:+:$LD_PRELOAD}" 9 + +LD_LIBRARY_PATH="@libraryPath@${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" 10 + 11 + -exec env LD_PRELOAD="${LD_PRELOAD}" $GAMEMODERUNEXEC "$@" 12 + +exec env LD_PRELOAD="${LD_PRELOAD}" LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" $GAMEMODERUNEXEC "$@"
+4
pkgs/top-level/all-packages.nix
··· 858 859 amidst = callPackage ../tools/games/amidst { }; 860 861 gfshare = callPackage ../tools/security/gfshare { }; 862 863 gobgp = callPackage ../tools/networking/gobgp { };
··· 858 859 amidst = callPackage ../tools/games/amidst { }; 860 861 + gamemode = callPackage ../tools/games/gamemode { 862 + libgamemode32 = pkgsi686Linux.gamemode.lib; 863 + }; 864 + 865 gfshare = callPackage ../tools/security/gfshare { }; 866 867 gobgp = callPackage ../tools/networking/gobgp { };