NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.31k stars 13.54k forks source link

gamescope: Does not work with lutris #292620

Open musjj opened 6 months ago

musjj commented 6 months ago

Describe the bug

When trying to use gamescope from inside lutris (Configure -> System options -> Enable Gamescope), the game will simply not start.

Steps To Reproduce

Lutris isn't providing any gamescope logs, so I tried to run it manually from inside the fshenv via the built-in terminal (Open Bash terminal):

gamescope -f -- \
  gamemoderun \
    ~/.local/share/lutris/runners/wine/wine-ge-8-26-x86_64/bin/wine \
    ~/Games/foo/bar.exe

And I got this error:

failed to inherit capabilities: Operation not permitted

This is my gamescope & gamemode config:

programs = {
  gamescope = {
    enable = true; 
    capSysNice = true;
  };
  gamemode = {
    enable = true;
    enableRenice = true;
  };
};

Expected behavior

Games in Lutris should be able to run with gamescope.

Notify maintainers

@kira-bruneau @nrdxp @Madouura

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.79, NixOS, 24.05 (Uakari), 24.05.20240226.13aff9b`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/store/1gpgihsi21bni03hy6i5ccw9lfrhnbqi-source`

Add a :+1: reaction to issues you find important.

MordragT commented 6 months ago

I get the same error in steam. As both are inside a fhsenv maybe it is worth investigating bwrap ? I saw that in steam there is a security wrapper for setuid bit. But that doesnt seem to be sufficient

sleyfuse commented 5 months ago

I created an account just to share this. Extremely hacky and unsafe but this allows lutris to work with gamescope with capSysNice enabled.

myLutrisPkg = let hackedPkgs = pkgs.extend (final: prev: { buildFHSEnv = args: prev.buildFHSEnv (args // { extraBwrapArgs = (args.extraBwrapArgs or []) ++ [ "--cap-add ALL" ]; }); }); in hackedPkgs.lutris;

Basically I overrode the package to add an extra bwrap argument of "--cap-add ALL" which fixes the issues with lutris not being able to get permission to set niceness in the FHS env. Add that to top of file and add myLutrisPkg instead of lutris in your systemPackages. This works with gamemode niceness enabled and gamescope capSysNice.

sleyfuse commented 5 months ago

I haven't experienced any issues, however I did notice there was an issue with vkCreateDevice obtaining a high priority queue so not sure if the niceness actually is working, but it bypassed the error and gamescope doesn't state that it doesn't have cap_sys_nice... This could be due to my use of chaotic nyx mesa_git or my older polaris card.

anthr76 commented 5 months ago

I'm facing this when trying to set launch options on a game with steam for example:

gamescope -W 3840 -H 2160 -r 60 -- %command%

Results in:

failed to inherit capabilities: Operation not permittedUploaded AppInterfaceStats to Steam

MordragT commented 5 months ago

I haven't experienced any issues, however I did notice there was an issue with vkCreateDevice obtaining a high priority queue so not sure if the niceness actually is working, but it bypassed the error and gamescope doesn't state that it doesn't have cap_sys_nice... This could be due to my use of chaotic nyx mesa_git or my older polaris card.

Thanks for ure workaround I am pretty confident that the vkCreateDevice is from mesa-git I got that same error also on mesa git. I am wondering whether it would be sufficient to add the renice capability instead of all, have you tried that ? Otherwise I will try that in the following days when I find time

sleyfuse commented 5 months ago

I did try just adding —cap-add sys_nice I think it was however that didn’t resolve the issue so I just added all the capabilities. It’s just an issue with using bubblewrap for lutris that you don’t have the necessary permissions in the namespace. I also initially tried overriding the bwrap executable used in the module with a wrapped one (tried setuid and just set cap) but that didn’t work.

kik4444 commented 3 months ago

Not sure if this would fix your issue with Lutris, but I recently had a similar issue with running gamescope from steam (e.g. gamescope -- %command% in the game's launch options). Running steam from the terminal allowed me to see what the issue is. First it was something about failed to inherit capabilities, after disabling cap_sys_nice it said something about missing libraries. Ultimately this is the config that fixed it for me:

programs = {
    steam.enable = true;
    # Fixes using gamescope in steam
    steam.package = pkgs.steam.override {
      extraPkgs = pkgs:
        with pkgs; [
          xorg.libXcursor
          xorg.libXi
          xorg.libXinerama
          xorg.libXScrnSaver
          libpng
          libpulseaudio
          libvorbis
          stdenv.cc.cc.lib
          libkrb5
          keyutils
        ];
    };

    gamescope.enable = true;
    gamescope.capSysNice = false; # Breaks gamescope in steam

};
nixos-discourse commented 1 month ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/unable-to-activate-gamescope-capsysnice-option/37843/6