Nixpkgs: Feral Gamemode

Created on 8 Apr 2020  路  2Comments  路  Source: NixOS/nixpkgs

Project description

GameMode is a daemon/lib combo for Linux that allows games to request a set of optimisations be temporarily applied to the host OS and/or a game process.

Metadata

packaging request

Most helpful comment

I will just give a bit of input as I tried to package gamemode just recently.

inih was necessary as a new depenency

{ stdenv, lib, fetchFromGitHub
, meson
, ninja
, cmake
, pkg-config
}:

stdenv.mkDerivation rec {

  pname = "inih";
  version = "r48";

  src = fetchFromGitHub {
    owner = "benhoyt";
    repo = "inih";
    rev = "${version}";
    sha256 = "0517kxhvh6q39iyk1dj1dyp5anawdynlzv6zxx736x4mgf6i2f3k";
  };

  nativeBuildInputs = [ cmake meson ninja pkg-config ];

  configurePhase = "meson build --prefix=$out";
  buildPhase = "ninja -C build";
  installPhase = ''
    ninja -C build install
    '';

  meta = with lib; {
    description = "Simple .INI file parser in C, good for embedded systems.";
    platforms = platforms.linux;
  };
}

Then I followed the AUR packages and the nix wine packages:

packages.nix

{ stdenv_32bit, lib, pkgs, pkgsi686Linux, callPackage
}:

{
  gamemode32 = pkgsi686Linux.callPackage ./gamemode32.nix {
    pkgArches = [ pkgsi686Linux ];
    platforms = [ "i686-linux" "x86_64-linux" ];
  };
  gamemode = callPackage ./gamemode.nix {
    pkgArches = [ pkgs ];
    platforms = [ "x86_64-linux" ];
  };
}

64bit

{ stdenv, lib, fetchFromGitHub
, pkgArches
, platforms
, meson
, ninja
, cmake
, pkgconfig
, systemd
, polkit
, dbus
}:

let
  custompkgs = import <custompkgs> {};
in

stdenv.mkDerivation rec {

  pname = "gamemode";
  version = "1.5.1";

  src = fetchFromGitHub {
    owner = "FeralInteractive";
    repo = "gamemode";
    rev = "${version}";
    sha256 = "1gp480c8lqz2i576jibbg7gifibkli3rnhhp1k5yrqsbfbn4qxf7";
  };

  nativeBuildInputs = [ cmake meson ninja pkgconfig ];
  buildInputs = [ systemd dbus custompkgs.inih ];
  propagatedBuildInputs = [ polkit
                            systemd ];

  postPatch = ''
    substituteInPlace daemon/gamemode-tests.c --replace "/usr/bin/gamemoderun" $out/bin/gamemoderun
    '';

  configurePhase = "meson build --prefix=$out -Dwith-systemd-user-unit-dir=$out/lib/systemd/user --libexecdir $out/lib/gamemode";
  buildPhase = "ninja -C build";
  installPhase = ''
    ninja -C build install

    mkdir -p $out/share/doc/${pname}/example
    install -m644 -Dt $out/share/doc/${pname}/example example/gamemode.ini
    '';

  meta = with lib; {
    inherit platforms;
    description = "Optimise Linux system performance on demand.";
  };
}

32bit

{ stdenv, lib, fetchFromGitHub
, pkgArches
, platforms
, meson
, ninja
, cmake
, pkgconfig
, systemd
, polkit
, dbus
}:

let
  custompkgs = import <custompkgs> {};
in

stdenv.mkDerivation rec {

  pname = "gamemode32";
  version = "1.5.1";

  src = fetchFromGitHub {
    owner = "FeralInteractive";
    repo = "gamemode";
    rev = "${version}";
    sha256 = "1gp480c8lqz2i576jibbg7gifibkli3rnhhp1k5yrqsbfbn4qxf7";
  };

  nativeBuildInputs = [ cmake meson ninja pkgconfig ];
  buildInputs = [ systemd dbus custompkgs.inih ];
  propagatedBuildInputs = [ polkit
                            systemd ];

  configurePhase = "meson build --prefix=$out -Dwith-daemon=false -Dwith-examples=false -Dwith-systemd=false -Dwith-util=false --libdir lib32";
  buildPhase = "ninja -C build";
  installPhase = ''
    ninja -C build install
    '';

  meta = with lib; {
    inherit platforms;
    description = "Optimise Linux system performance on demand.";
  };
}

Then I added

systemd.packages = [ custompkgs.gamemode.gamemode ];

and, importantly, deactivated powerManagement.cpuFreqGovernor. Then I could run gamemoded -t and pass all tests. However, there are still some issues with the libraries.

gamemoderun lutris
...
ERROR: ld.so: object '/nix/store/mvcp6y1aq42c0lv51d2pczx3pmwfkcy5-gamemode-1.5.1/$LIB/libgamemodeauto.so.0' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
...

All 2 comments

I will just give a bit of input as I tried to package gamemode just recently.

inih was necessary as a new depenency

{ stdenv, lib, fetchFromGitHub
, meson
, ninja
, cmake
, pkg-config
}:

stdenv.mkDerivation rec {

  pname = "inih";
  version = "r48";

  src = fetchFromGitHub {
    owner = "benhoyt";
    repo = "inih";
    rev = "${version}";
    sha256 = "0517kxhvh6q39iyk1dj1dyp5anawdynlzv6zxx736x4mgf6i2f3k";
  };

  nativeBuildInputs = [ cmake meson ninja pkg-config ];

  configurePhase = "meson build --prefix=$out";
  buildPhase = "ninja -C build";
  installPhase = ''
    ninja -C build install
    '';

  meta = with lib; {
    description = "Simple .INI file parser in C, good for embedded systems.";
    platforms = platforms.linux;
  };
}

Then I followed the AUR packages and the nix wine packages:

packages.nix

{ stdenv_32bit, lib, pkgs, pkgsi686Linux, callPackage
}:

{
  gamemode32 = pkgsi686Linux.callPackage ./gamemode32.nix {
    pkgArches = [ pkgsi686Linux ];
    platforms = [ "i686-linux" "x86_64-linux" ];
  };
  gamemode = callPackage ./gamemode.nix {
    pkgArches = [ pkgs ];
    platforms = [ "x86_64-linux" ];
  };
}

64bit

{ stdenv, lib, fetchFromGitHub
, pkgArches
, platforms
, meson
, ninja
, cmake
, pkgconfig
, systemd
, polkit
, dbus
}:

let
  custompkgs = import <custompkgs> {};
in

stdenv.mkDerivation rec {

  pname = "gamemode";
  version = "1.5.1";

  src = fetchFromGitHub {
    owner = "FeralInteractive";
    repo = "gamemode";
    rev = "${version}";
    sha256 = "1gp480c8lqz2i576jibbg7gifibkli3rnhhp1k5yrqsbfbn4qxf7";
  };

  nativeBuildInputs = [ cmake meson ninja pkgconfig ];
  buildInputs = [ systemd dbus custompkgs.inih ];
  propagatedBuildInputs = [ polkit
                            systemd ];

  postPatch = ''
    substituteInPlace daemon/gamemode-tests.c --replace "/usr/bin/gamemoderun" $out/bin/gamemoderun
    '';

  configurePhase = "meson build --prefix=$out -Dwith-systemd-user-unit-dir=$out/lib/systemd/user --libexecdir $out/lib/gamemode";
  buildPhase = "ninja -C build";
  installPhase = ''
    ninja -C build install

    mkdir -p $out/share/doc/${pname}/example
    install -m644 -Dt $out/share/doc/${pname}/example example/gamemode.ini
    '';

  meta = with lib; {
    inherit platforms;
    description = "Optimise Linux system performance on demand.";
  };
}

32bit

{ stdenv, lib, fetchFromGitHub
, pkgArches
, platforms
, meson
, ninja
, cmake
, pkgconfig
, systemd
, polkit
, dbus
}:

let
  custompkgs = import <custompkgs> {};
in

stdenv.mkDerivation rec {

  pname = "gamemode32";
  version = "1.5.1";

  src = fetchFromGitHub {
    owner = "FeralInteractive";
    repo = "gamemode";
    rev = "${version}";
    sha256 = "1gp480c8lqz2i576jibbg7gifibkli3rnhhp1k5yrqsbfbn4qxf7";
  };

  nativeBuildInputs = [ cmake meson ninja pkgconfig ];
  buildInputs = [ systemd dbus custompkgs.inih ];
  propagatedBuildInputs = [ polkit
                            systemd ];

  configurePhase = "meson build --prefix=$out -Dwith-daemon=false -Dwith-examples=false -Dwith-systemd=false -Dwith-util=false --libdir lib32";
  buildPhase = "ninja -C build";
  installPhase = ''
    ninja -C build install
    '';

  meta = with lib; {
    inherit platforms;
    description = "Optimise Linux system performance on demand.";
  };
}

Then I added

systemd.packages = [ custompkgs.gamemode.gamemode ];

and, importantly, deactivated powerManagement.cpuFreqGovernor. Then I could run gamemoded -t and pass all tests. However, there are still some issues with the libraries.

gamemoderun lutris
...
ERROR: ld.so: object '/nix/store/mvcp6y1aq42c0lv51d2pczx3pmwfkcy5-gamemode-1.5.1/$LIB/libgamemodeauto.so.0' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
...

I am also trying to package this. I've noticed that the binary of gamemoded doesn't contain its own derivations lib directory in it's rpath which seems to be the main cause of the issue. Does anyone know how to resolve this? I can manually patch the source to load the library from a specific location, but this would disallow the loading of 32 bit libs dynamically.

I'm sure a package can't depend on itself but there must be some way to get the package to know about it's own lib directory. I'm a bit surprised that this is not default behavior.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

teto picture teto  路  3Comments

domenkozar picture domenkozar  路  3Comments

lverns picture lverns  路  3Comments

sid-kap picture sid-kap  路  3Comments

copumpkin picture copumpkin  路  3Comments