summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorSandro <sandro.jaeckel@gmail.com>2021-06-06 02:13:02 +0200
committerGitHub <noreply@github.com>2021-06-06 02:13:02 +0200
commit0c85b23e25165a04db7bd8155d2d1dcbad924ff7 (patch)
tree99b17a8c48fe7d708890201420b2bd5476c4c8ff /pkgs
parent2854b52437f708cd5d3a1f97207e740c9f7a1f41 (diff)
parentcaac437b9b486e4e5271066c9eec049e3b7cb3ce (diff)
downloadnixpkgs-0c85b23e25165a04db7bd8155d2d1dcbad924ff7.tar
nixpkgs-0c85b23e25165a04db7bd8155d2d1dcbad924ff7.tar.gz
nixpkgs-0c85b23e25165a04db7bd8155d2d1dcbad924ff7.tar.bz2
nixpkgs-0c85b23e25165a04db7bd8155d2d1dcbad924ff7.tar.lz
nixpkgs-0c85b23e25165a04db7bd8155d2d1dcbad924ff7.tar.xz
nixpkgs-0c85b23e25165a04db7bd8155d2d1dcbad924ff7.tar.zst
nixpkgs-0c85b23e25165a04db7bd8155d2d1dcbad924ff7.zip
Merge pull request #123433 from kira-bruneau/gamemode
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/tools/games/gamemode/default.nix104
-rw-r--r--pkgs/tools/games/gamemode/preload-nix-workaround.patch12
-rw-r--r--pkgs/top-level/all-packages.nix4
3 files changed, 120 insertions, 0 deletions
diff --git a/pkgs/tools/games/gamemode/default.nix b/pkgs/tools/games/gamemode/default.nix
new file mode 100644
index 00000000000..e9fdec59220
--- /dev/null
+++ b/pkgs/tools/games/gamemode/default.nix
@@ -0,0 +1,104 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, fetchpatch
+, libgamemode32
+, meson
+, ninja
+, pkg-config
+, dbus
+, inih
+, systemd
+, appstream
+}:
+
+stdenv.mkDerivation rec {
+  pname = "gamemode";
+  version = "1.6.1";
+
+  src = fetchFromGitHub {
+    owner = "FeralInteractive";
+    repo = pname;
+    rev = version;
+    sha256 = "sha256-P00OnZiPZyxBu9zuG+3JNorXHBhJZy+cKPjX+duZrJ0=";
+  };
+
+  outputs = [ "out" "dev" "lib" "man" "static" ];
+
+  patches = [
+    # Run executables from PATH instead of /usr/bin
+    # See https://github.com/FeralInteractive/gamemode/pull/323
+    (fetchpatch {
+      url = "https://github.com/FeralInteractive/gamemode/commit/be44b7091baa33be6dda60392e4c06c2f398ee72.patch";
+      sha256 = "TlDUETs4+N3pvrVd0FQGlGmC+6ByhJ2E7gKXa7suBtE=";
+    })
+
+    # Fix loading shipped config when using a prefix other than /usr
+    # See https://github.com/FeralInteractive/gamemode/pull/324
+    (fetchpatch {
+      url = "https://github.com/FeralInteractive/gamemode/commit/b29aa903ce5acc9141cfd3960c98ccb047eca872.patch";
+      sha256 = "LwBzBJQ7dfm2mFVSOSPjJP+skgV5N6h77i66L1Sq+ZM=";
+    })
+
+    # Add @libraryPath@ template variable to fix loading the PRELOAD library
+    ./preload-nix-workaround.patch
+  ];
+
+  postPatch = ''
+    substituteInPlace data/gamemoderun \
+      --subst-var-by libraryPath ${lib.makeLibraryPath ([
+        (placeholder "lib")
+      ] ++ lib.optionals (stdenv.hostPlatform.system == "x86_64-linux") [
+        # Support wrapping 32bit applications on a 64bit linux system
+        libgamemode32
+      ])}
+  '';
+
+  nativeBuildInputs = [
+    meson
+    ninja
+    pkg-config
+  ];
+
+  buildInputs = [
+    dbus
+    inih
+    systemd
+  ];
+
+  mesonFlags = [
+    # libexec is just a way to package binaries without including them
+    # in PATH. It doesn't make sense to install them to $lib
+    # (the default behaviour in the meson hook).
+    "--libexecdir=${placeholder "out"}/libexec"
+
+    "-Dwith-systemd-user-unit-dir=lib/systemd/user"
+  ];
+
+  doCheck = true;
+  checkInputs = [
+    appstream
+  ];
+
+  # Move static libraries to $static so $lib only contains dynamic libraries.
+  postInstall = ''
+    moveToOutput lib/*.a "$static"
+  '';
+
+  # Add $lib/lib to gamemoded & gamemode-simulate-game's rpath since
+  # they use dlopen to load libgamemode. Can't use makeWrapper since
+  # it would break the security wrapper in the NixOS module.
+  postFixup = ''
+    for bin in "$out/bin/gamemoded" "$out/bin/gamemode-simulate-game"; do
+      patchelf --set-rpath "$lib/lib:$(patchelf --print-rpath "$bin")" "$bin"
+    done
+  '';
+
+  meta = with lib; {
+    description = "Optimise Linux system performance on demand";
+    homepage = "https://github.com/FeralInteractive/GameMode";
+    license = licenses.bsd3;
+    maintainers = with maintainers; [ kira-bruneau ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/pkgs/tools/games/gamemode/preload-nix-workaround.patch b/pkgs/tools/games/gamemode/preload-nix-workaround.patch
new file mode 100644
index 00000000000..06989ff984a
--- /dev/null
+++ b/pkgs/tools/games/gamemode/preload-nix-workaround.patch
@@ -0,0 +1,12 @@
+diff --git a/data/gamemoderun b/data/gamemoderun
+index 573b3e4..6f2799e 100755
+--- a/data/gamemoderun
++++ b/data/gamemoderun
+@@ -5,5 +5,6 @@ GAMEMODEAUTO_NAME="libgamemodeauto.so.0"
+ 
+ # ld will find the right path to load the library, including for 32-bit apps.
+ LD_PRELOAD="${GAMEMODEAUTO_NAME}${LD_PRELOAD:+:$LD_PRELOAD}"
++LD_LIBRARY_PATH="@libraryPath@${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
+ 
+-exec env LD_PRELOAD="${LD_PRELOAD}" $GAMEMODERUNEXEC "$@"
++exec env LD_PRELOAD="${LD_PRELOAD}" LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" $GAMEMODERUNEXEC "$@"
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index f77be988934..530ba52493e 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -858,6 +858,10 @@ in
 
   amidst = callPackage ../tools/games/amidst { };
 
+  gamemode = callPackage ../tools/games/gamemode {
+    libgamemode32 = pkgsi686Linux.gamemode.lib;
+  };
+
   gfshare = callPackage ../tools/security/gfshare { };
 
   gobgp = callPackage ../tools/networking/gobgp { };