1 { config, lib, writeScript, buildFHSUserEnv, steam, glxinfo-i686
2 , steam-runtime-wrapped, steam-runtime-wrapped-i686 ? null
3 , extraPkgs ? pkgs: [ ] # extra packages to add to targetPkgs
4 , extraLibraries ? pkgs: [ ] # extra packages to add to multiPkgs
5 , extraProfile ? "" # string to append to profile
6 , extraArgs ? "" # arguments to always pass to steam
12 , withJava ? config.steam.java or false
13 , withPrimus ? config.steam.primus or false
17 commonTargetPkgs = pkgs: with pkgs;
19 # Needed for operating system detection until
20 # https://github.com/ValveSoftware/steam-for-linux/issues/5909 is resolved
22 # Errors in output without those
27 # Needed by gdialog, including in the steam-runtime
38 # electron based launchers need newer versions of these libraries than what runtime provides
41 ] ++ lib.optional withJava jdk8 # TODO: upgrade https://github.com/NixOS/nixpkgs/pull/89731
42 ++ lib.optional withPrimus primus
45 ldPath = lib.optionals stdenv.is64bit [ "/lib64" ]
47 ++ map (x: "/steamrt/${steam-runtime-wrapped.arch}/" + x) steam-runtime-wrapped.libs
48 ++ lib.optionals (steam-runtime-wrapped-i686 != null) (map (x: "/steamrt/${steam-runtime-wrapped-i686.arch}/" + x) steam-runtime-wrapped-i686.libs);
50 # Zachtronics and a few other studios expect STEAM_LD_LIBRARY_PATH to be present
52 export LD_LIBRARY_PATH=${lib.concatStringsSep ":" ldPath}''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
53 export STEAM_LD_LIBRARY_PATH="$STEAM_LD_LIBRARY_PATH''${STEAM_LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"
56 # bootstrap.tar.xz has 444 permissions, which means that simple deletes fail
57 # and steam will not be able to start
59 if [ -r $HOME/.local/share/Steam/bootstrap.tar.xz ]; then
60 chmod +w $HOME/.local/share/Steam/bootstrap.tar.xz
64 in buildFHSUserEnv rec {
67 targetPkgs = pkgs: with pkgs; [
71 ] ++ commonTargetPkgs pkgs;
73 multiPkgs = pkgs: with pkgs; [
74 # These are required by steam with proper errors
90 # Not formally in runtime but needed by some games
92 at-spi2-core # CrossCode
94 gst_all_1.gst-plugins-ugly
95 gst_all_1.gst-plugins-base
96 json-glib # paradox launcher (Stellaris)
98 libxkbcommon # paradox launcher
99 libvorbis # Dead Cells
103 xorg.libXScrnSaver # Dead Cells
104 udev # shadow of the tomb raider
105 icu # dotnet runtime, e.g. stardew valley
107 # screeps dependencies
117 # friends options won't display "Launch Game" without it
120 # called by steam's setup.sh
136 # dependencies for mesa drivers, needed inside pressure-vessel
137 mesa.llvmPackages.llvm.lib
152 # Without these it silently fails
170 # Only libraries are needed from those two
173 # Verified games requirements
184 # Other things from runtime
212 ++ steamPackages.steam-runtime-wrapped.overridePkgs
213 ++ extraLibraries pkgs;
215 extraInstallCommands = ''
216 mkdir -p $out/share/applications
217 ln -s ${steam}/share/icons $out/share
218 ln -s ${steam}/share/pixmaps $out/share
219 ln -s ${steam}/share/applications/steam.desktop $out/share/applications/steam.desktop
223 # Workaround for issue #44254 (Steam cannot connect to friends network)
224 # https://github.com/NixOS/nixpkgs/issues/44254
225 if [ -z ''${TZ+x} ]; then
226 new_TZ="$(readlink -f /etc/localtime | grep -P -o '(?<=/zoneinfo/).*$')"
227 if [ $? -eq 0 ]; then
232 # udev event notifications don't work reliably inside containers.
233 # SDL2 already tries to automatically detect flatpak and pressure-vessel
234 # and falls back to inotify-based discovery [1]. We make SDL2 do the
235 # same by telling it explicitly.
237 # [1] <https://github.com/libsdl-org/SDL/commit/8e2746cfb6e1f1a1da5088241a1440fd2535e321>
238 export SDL_JOYSTICK_DISABLE_UDEV=1
241 runScript = writeScript "steam-wrapper.sh" ''
243 if [ -f /host/etc/NIXOS ]; then # Check only useful on NixOS
244 ${glxinfo-i686}/bin/glxinfo >/dev/null 2>&1
245 # If there was an error running glxinfo, we know something is wrong with the configuration
246 if [ $? -ne 0 ]; then
247 cat <<EOF > /dev/stderr
249 WARNING: Steam is not set up. Add the following options to /etc/nixos/configuration.nix
250 and then run \`sudo nixos-rebuild switch\`:
252 hardware.opengl.driSupport32Bit = true;
253 hardware.pulseaudio.support32Bit = true;
262 exec steam ${extraArgs} "$@"
265 inherit (steam) meta;
267 # allows for some gui applications to share IPC
268 # this fixes certain issues where they don't render correctly
271 # Some applications such as Natron need access to MIT-SHM or other
272 # shared memory mechanisms. Unsharing the pid namespace
273 # breaks the ability for application to reference shared memory.
276 passthru.run = buildFHSUserEnv {
279 targetPkgs = commonTargetPkgs;
280 inherit multiPkgs profile extraInstallCommands;
282 inherit unshareIpc unsharePid;
284 runScript = writeScript "steam-run" ''
287 if [ "$run" = "" ]; then
288 echo "Usage: steam-run command-to-run args..." >&2
298 meta = steam.meta // {
299 description = "Run commands in the same FHS environment that is used for Steam";