Steam: Difference between revisions

imported>Fadenb
m Syntax highlighting
 
(101 intermediate revisions by 56 users not shown)
Line 1: Line 1:
{{outdated}}
{{Expansion|See notes in ->}}
This page is intended to describe the current state of Steam under Nixos and to discuss what the problems are in packaging it and how we can approach solving them.


== I want to play ==
This page is intended to explain how to run [[Steam]], [[Steam]] games as well as proprietary DRM-free games under NixOS.
For 64-bit systems it's important to have <syntaxhighlight lang="nix" inline>hardware.opengl.driSupport32Bit = true</syntaxhighlight> in your NixOS configuration. You'll also need <syntaxhighlight lang="nix" inline>hardware.pulseaudio.support32Bit = true</syntaxhighlight> if you are using PulseAudio - this will enable 32bit ALSA apps integration.
Steam on NixOS is very easy to install and use - it just works. But you may need to be aware of the limitations when trying to run a native Linux install of a game. It's often better to run the emulated Windows version via [https://en.m.wikipedia.org/wiki/Proton_(software) Proton].
A dedicated [[Games]] page lists games and reports on their successful execution on NixOS.  


== Master/Unstable branch ==
== Install ==
Install "steam" package. Run "steam". Many of the games will just work.


== Stable branch ==
To install the [[Steam]] package and enable all the system options necessary to allow it to run:
Install "steam" and "steamChrootEnv" packages. Run:
 
<syntaxhighlight lang="bash">
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
sudo init-steam-chrootenv
# There have been amdgpu issues in 6.10 so you maybe need to revert on the default lts kernel.
sudo mount-steam-chrootenv
# boot.kernelPackages = pkgs.linuxPackages;
load-steam-chrootenv
programs.steam = {
steam
  enable = true;
</syntaxhighlight>
  remotePlay.openFirewall = true; # Open ports in the firewall for Steam Remote Play
To destroy the chroot env, run:
  dedicatedServer.openFirewall = true; # Open ports in the firewall for Source Dedicated Server
<syntaxhighlight lang="bash">
};
sudo umount-steam-chrootenv
</nowiki>}}
sudo destroy-steam-chrootenv
 
</syntaxhighlight>
[https://news.ycombinator.com/item?id=41549030 Anecdata on 6.10 issues]
 
 
 
{{note|Enabling [[steam]] installs several unfree packages. If you are using <code>allowUnfreePredicate</code> you will need to ensure that your configurations permit all of them.
<syntaxHighlight lang=nix>
{
  nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
    "steam"
    "steam-unwrapped"
    "steam-original"
    "steam-run"
  ];
}
</syntaxHighlight>
}}
 
=== Gamescope Compositor / "Boot to Steam Deck" ===
Gamescope can function as a minimal desktop environment, meaning you can launch it from a TTY and have an experience very similar to the Steam Deck hardware console.
 
<syntaxhighlight lang="nix">#Clean Quiet Boot
boot.kernelParams = [ "quiet" "splash" "console=/dev/null" ];
plymouth.enable = true;
 
programs = {
  gamescope = {
    enable = true;
    capSysNice = true;
  };
  steam = {
    enable = true;
    gamescopeSession.enable = true;
  };
};
 
#Gamescope Auto Boot
  services.xserver.enable = false;
  services.getty.autologinUser = "USERNAME_HERE";
 
  services.greetd = {
    enable = true;
    settings = {
      default_session = {
        command = "${pkgs.gamescope}/bin/gamescope -W 1920 -H 1080 -f -e --xwayland-count 2 --hdr-enabled  --hdr-itm-enabled -- steam -pipewire-dmabuf -gamepadui -steamos > /dev/null 2>&1";
        user = "USERNAME_HERE";
      };
    };
  };</syntaxhighlight>
=== steam-tui ===
If you want the steam-tui client you'll have to install it, but since it relies on <code>steamcmd</code> being set up, you'll have to set that up, just to generate the right files.
<syntaxHighlight lang=nix>
nix-shell -p steamcmd --run steamcmd
</syntaxHighlight>
And then log in: <syntaxHighlight>login <username> <password> <steam 2fa password></syntaxHighlight>
After that, steam-tui should start fine.
 
=== FHS environment only ===
This will only make partial installation - provide the script, which creates the typical environment expected by proprietary games and software on regular Linux, allowing to run such software without patching. Useful if you plan to run games downloaded from the internet.


== Description of the package ==
Note that this is not necessary for clients installed from Nixpkgs (like Minigalaxy or Itch), which already use the FHS environment.
Steam is distributed as a .deb file, for now only as an i686 package (the amd64 package only has documentation). When unpacked, it has a script called steam that in ubuntu (their target distro) would go to /usr/bin. When run for the first time, this script copies some files to the user's home, which include another script that is the ultimate responsible for launching the steam binary, which is also in $HOME.


== Nix problems and constraints ==
There are two options to install the FHS environment. The first is to install <syntaxhighlight lang="nix" inline>steam-run</syntaxhighlight>.
* We don't have /bin/bash and many scripts point there. Similarly for /usr/bin/python, for some functionality.
* We don't have the dynamic loader in /lib
* The steam.sh script in $HOME could not be patched last I tried, as it is checked and rewritten by steam
* The steam binary cannot be patched, it's also checked


== Approaches ==
Example snippet of <code>configuration.nix</code>:
=== chroot ===
<syntaxHighlight lang=nix>
This is the current approach, documented here: http://sandervanderburg.blogspot.nl/2013/09/composing-fhs-compatible-chroot.html
  environment.systemPackages = with pkgs; [
* Pros:
    steam-run
** it would allow us to have binaries in the expected paths without disrupting the system
  ];
** Steam itself, as well as Valve games and perhaps others like to checksum their executables, so patching does not work
</syntaxHighlight>
* Cons: performance?


=== Link bash to /bin and glibc/lib to /lib and be happy ===
Another option, in case you need more flexibility, is to directly reference the part of [[steam]] metapackage.
* Pros: easy, works
* Cons: not very nix-compliant


=== Workaround the scripts and launch steam directly ===
Example snippet of <code>configuration.nix</code>:
* Pros: not so hard
<syntaxHighlight lang=nix>
* Cons: this only solves the part concerned with running steam. What about the games? We can patch some of them, but at least Team Fortress is checked and rewritten if modified
  environment.systemPackages = with pkgs; [
    (steam.override { /* Your overrides here */ }).run
  ];
</syntaxHighlight>


This is the approach that I (page) took in my github branch: https://github.com/cpages/nixpkgs/tree/steam
Install the game by setting the executable attribute on the installer and then running it via <code>steam-run ./your_installer.sh</code>. After installation, edit the "~/.local/share/applications/your_game.desktop" and replace the exec line from <code>Exec="/home/user/game/start.sh" ""</code> with <code>Exec="steam-run" "/home/user/game/start.sh"</code>.


=== Intercept Steam's calls with LD_PRELOAD or the like ===
== Adding missing dependencies ==
* Pros: more robust
* Cons: difficult to achieve and may be broken by changes in the binary


aszlig started working in this in his branch: https://github.com/aszlig/nixpkgs/tree/steam
In some cases, you may need to override [[steam]] to provide missing dependencies.
Use the <code>programs.steam.package</code> for this.


=== But what about the games? ===
=== Bumblebee and Primus ===
You can install any of the games normally, but they will fail to start. From this step on, you're in the unsupported realm. Some games can be patchelfed:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="bash">
  programs.steam.package = pkgs.steam.override {
patchelf --set-interpreter /path/to/ld.so game_binary (you can get the path to an x86 ld.so looking at the steam script in the store, for me /nix/store/xh0q23rgqbjfrh3zfv4jyxvcvjnxqh64-glibc-2.15.0/lib/ld-linux.so.2)
    withPrimus = true;
    extraPackages = [ bumblebee glxinfo ];
  };
</syntaxhighlight>
</syntaxhighlight>
You might also need patching some scripts. That all depends on each one. You can then press play from steam and if you're lucky that'll be it!


=== Java ===
<syntaxHighlight lang=nix>
  programs.java.enable = true;
  programs.steam.package = pkgs.steam.override { withJava = true; };
</syntaxHighlight>
== gamescope ==
To use the [https://github.com/ValveSoftware/gamescope gamescope] compositor, which enables features such as resolution upscaling and stretched aspect ratios (such as 4:3), set
<syntaxHighlight lang=nix>
programs.steam.gamescopeSession.enable = true;
</syntaxHighlight>
in your system configuration.


== Troubleshooting ==
== Troubleshooting ==
I was sure you would reach this part.
 
For all issues: first run <code>steam -dev -console</code> through the terminal and read the output.


=== Steam fails to start. What do I do? ===
=== Steam fails to start. What do I do? ===
strace is your friend.
Run <code>strace steam -dev -console 2> steam.logs</code> in the terminal. In the case of a missing <code>strace</code> installation, you can temporarily install it using <code>nix-shell -p strace</code> or <code>nix run nixpkgs#strace -- steam -dev -console 2> steam.logs</code>, if [[Flakes]] are enabled. After that, create a bug report. <!-- This is vague. Where should the user create a bug report?  -->
 
=== Steam is not updated ===
 
When you restart [[Steam]] after an update, it starts the old version. ([https://github.com/NixOS/nixpkgs/issues/181904 #181904])
 
A workaround is to remove the user files in <code>/home/<USER>/.local/share/Steam/userdata</code>. This can be done with <code>rm -rf /home/<USER>/.local/share/Steam/userdata</code> in the terminal or with your file manager. After that, Steam can be setup again by restarting.


=== Game X fails to start ===
=== Game fails to start ===
Games may fail to start because they lack dependencies (this should be added to the script, for now), or because they cannot be patched. The steps to launch a game directly are:
Games may fail to start because they lack dependencies (this should be added to the script, for now), or because they cannot be patched. The steps to launch a game directly are:
* Patch the script/binary if you can
* Patch the script/binary if you can
Line 75: Line 148:
* Using the LD_LIBRARY_PATH from the nix/store steam script, with some additions, launch the game binary
* Using the LD_LIBRARY_PATH from the nix/store steam script, with some additions, launch the game binary
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
  LD_LIBRARY_PATH=~/.steam/bin32:$LD_LIBRARY_PATH:/nix/store/pfsa... blabla ...curl-7.29.0/lib:. ./Osmos.bin32 (if you could not patchelf the game, call ld.so directly with the binary as param)
  LD_LIBRARY_PATH=~/.steam/bin32:$LD_LIBRARY_PATH:/nix/store/pfsa... blabla ...curl-7.29.0/lib:. ./Osmos.bin32 (if you could not patchelf the game, call ld.so directly with the binary as parameter)
</syntaxhighlight>
 
Note: If a game gets stuck on Installing scripts, check for a DXSETUP.EXE process and run it manually, then restart the game launch.
 
==== Changing the driver on AMD GPUs <!-- this is not recommended due radv drivers performing better and generally more stable than amdvlk. My suggestion remove this section. source: https://forums.guru3d.com/threads/the-mesa-radv-amdvlk-thread.449774/ -->====
{{note|This is not recommended because radv drivers tend to perform better and are generally more stable than amdvlk.}}
 
Sometimes, changing the driver on AMD GPUs helps. To try this, first, install multiple drivers such as radv and amdvlk:
 
<syntaxHighlight lang=nix>
hardware.graphics = {
  ## radv: an open-source Vulkan driver from freedesktop
  enable32Bit = true;
 
  ## amdvlk: an open-source Vulkan driver from AMD
  extraPackages = [ pkgs.amdvlk ];
  extraPackages32 = [ pkgs.driversi686Linux.amdvlk ];
};
</syntaxHighlight>
 
In the presence of both drivers, [[Steam]] will default to amdvlk. The amdvlk driver can be considered more correct regarding Vulkan specification implementation, but less performant than radv. However, this tradeoff between correctness and performance can sometimes make or break the gaming experience.
 
To "reset" your driver to radv when both radv and amdvlk are installed, set either <code>AMD_VULKAN_ICD = "RADV"</code> or <code>VK_ICD_FILENAMES = "/run/opengl-driver/share/vulkan/icd.d/radeon_icd.x86_64.json"</code> environment variable. For example, if you start [[Steam]] from the shell, you can enable radv for the current session by running <code>AMD_VULKAN_ICD="RADV" steam</code>. If you are unsure which driver you currently use, you can launch a game with [https://github.com/flightlessmango/MangoHud MangoHud] enabled, which has the capability to show what driver is currently in use.
 
=== SteamVR ===
 
The setcap issue at SteamVR start can be fixed with:
 
<code>sudo setcap CAP_SYS_NICE+ep ~/.local/share/Steam/steamapps/common/SteamVR/bin/linux64/vrcompositor-launcher</code>
 
=== Gamescope fails to launch when used within Steam ===
Gamescope may fail to start due to missing Xorg libraries. ([https://github.com/NixOS/nixpkgs/issues/214275 #214275]) To resolve this override the steam package to add them:<syntaxhighlight lang="nix">
programs.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
    ];
};
</syntaxhighlight>
</syntaxhighlight>
With this technique, I can play many games directly from steam. Others, like Team Fortress, cannot be patched so I only managed to run them from the cmd line.


=== Using the FOSS Radeon drivers ===
=== Udev rules for additional Gamepads ===
The open source radeon drivers need a newer libc++ than is provided by the default runtime, which leads to acrash on launch. Use
In specific scenarios gamepads, might require some additional configuration in order to function properly in the form of udev rules. This can be achieved with <code>services.udev.extraRules</code>.
 
The following example is for the 8bitdo Ultimate Bluetooth controller, different controllers will require knowledge of the vendor and product ID for the device:
 
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
(steamPackages.override { newLibcpp = true; }).steam-chrootenv
  services.udev.extraRules = ''
    SUBSYSTEM=="input", ATTRS{idVendor}=="2dc8", ATTRS{idProduct}=="3106", MODE="0660", GROUP="input"
  '';
</syntaxhighlight>
</syntaxhighlight>
[https://github.com/NixOS/nixpkgs/pull/12404 in your config] if you get an error like


libGL error: unable to load driver: radeonsi_dri.so
To find the vendor and product ID of a device [https://search.nixos.org/packages?channel=unstable&show=usbutils&from=0&size=50&sort=relevance&type=packages&query=usbutils usbutils] might be useful
libGL error: driver pointer missing
libGL error: failed to load driver: radeonsi
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast


=== Known issues ===
=== Known issues ===
# No java in steam chrootenv. Games affected: Towns:
"Project Zomboid" may report "couldn't determine 32/64 bit of java". This is not related to java at all, it carries its own outdated java binary that refuses to start if path contains non-Latin characters. Check for errors by directly starting local java binary within <code>steam-run bash</code>.
<syntaxhighlight lang="console">
 
/home/foo/.local/share/Steam/SteamApps/common/towns/towns.sh: line 1: java: command not found
Resetting your password through the [[Steam]] app may fail at the CAPTCHA step repeatedly, with [[Steam]] itself reporting that the CAPTCHA was not correct, even though the CAPTCHA UI shows success. Resetting password through the [[Steam]] website should work around that.
 
== Steam hardware ==
If you are using a Steam Controller or a Valve Index, you will want to add <code>hardware.steam-hardware.enable = true;</code> to your configuration.
 
Note that this is already enabled with <code>programs.steam.enable = true;</code>.
 
 
 
== Proton ==
 
You should be able to play most games with Proton. If there is a Linux native version you have to activate a custom compatibility layer to use the emulated Windows version. Native Linux versions may not even start due to the way NixOS work.
 
=== Custom Proton versions ===
 
By default, [[Steam]] looks for custom Proton versions such as GE-Proton in <code>~/.steam/root/compatibilitytools.d</code>. Additionally the environment variable <code>STEAM_EXTRA_COMPAT_TOOLS_PATHS</code> can be set to change or add to the paths which [[steam]] searches for custom Proton versions.
<syntaxhighlight lang="nix">
programs.steam.extraCompatPackages = with pkgs; [ proton-ge-bin ];
</syntaxhighlight>
</syntaxhighlight>
=== Install Proton versions by GUI ===
The main disadvantage of using the proton-ge-bin package is: it's only one version. For using steam it may be better not to use the declarative approach and manually install several versions of proton via protonup-qt GUI (like GloriousEggroll version GE_Proton).
<syntaxHighlight lang=nix>
  environment.systemPackages = with pkgs; [
    protonup-qt
  ];
</syntaxHighlight>
== GameMode ==
Consider activating [[GameMode]].
== See also ==
[[Explaining the current Steam Package build]]
[[VR]]
[[Category:Applications]]
[[Category:Gaming]]