1 { lib, stdenv, writeShellScript, buildFHSEnv, 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 , extraBwrapArgs ? [ ] # extra arguments to pass to bubblewrap
7 , extraArgs ? "" # arguments to always pass to steam
8 , extraEnv ? { } # Environment variables to pass to Steam
9 , withGameSpecificLibraries ? true # include game specific libraries
13 commonTargetPkgs = pkgs: with pkgs; [
14 # Needed for operating system detection until
15 # https://github.com/ValveSoftware/steam-for-linux/issues/5909 is resolved
17 # Errors in output without those
22 # Needed by gdialog, including in the steam-runtime
33 # It tries to execute xdg-user-dir and spams the log with command not founds
36 # electron based launchers need newer versions of these libraries than what runtime provides
41 ldPath = lib.optionals stdenv.is64bit [ "/lib64" ]
43 ++ map (x: "/steamrt/${steam-runtime-wrapped.arch}/" + x) steam-runtime-wrapped.libs
44 ++ lib.optionals (steam-runtime-wrapped-i686 != null) (map (x: "/steamrt/${steam-runtime-wrapped-i686.arch}/" + x) steam-runtime-wrapped-i686.libs);
46 # Zachtronics and a few other studios expect STEAM_LD_LIBRARY_PATH to be present
48 export LD_LIBRARY_PATH=${lib.concatStringsSep ":" ldPath}''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
49 export STEAM_LD_LIBRARY_PATH="$STEAM_LD_LIBRARY_PATH''${STEAM_LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"
52 # bootstrap.tar.xz has 444 permissions, which means that simple deletes fail
53 # and steam will not be able to start
55 if [ -r $HOME/.local/share/Steam/bootstrap.tar.xz ]; then
56 chmod +w $HOME/.local/share/Steam/bootstrap.tar.xz
60 envScript = lib.toShellVars extraEnv;
65 # Steam still needs 32bit and various native games do too
68 targetPkgs = pkgs: with pkgs; [
72 ] ++ commonTargetPkgs pkgs;
74 multiPkgs = pkgs: with pkgs; [
75 # These are required by steam with proper errors
91 lsof # friends options won't display "Launch Game" without it
92 file # called by steam's setup.sh
94 # dependencies for mesa drivers, needed inside pressure-vessel
95 mesa.llvmPackages.llvm.lib
104 (lib.getLib elfutils)
106 # Without these it silently fails
123 gsettings-desktop-schemas
127 # Verified games requirements
146 # Other things from runtime
178 # required by coreutils stuff to run correctly
179 # Steam ends up with LD_LIBRARY_PATH=<bunch of runtime stuff>:/usr/lib:<etc>
180 # which overrides DT_RUNPATH in our binaries, so it tries to dynload the
181 # very old versions of stuff from the runtime.
182 # FIXME: how do we even fix this correctly
184 ] ++ lib.optionals withGameSpecificLibraries [
185 # Not formally in runtime but needed by some games
187 at-spi2-core # CrossCode
189 gst_all_1.gst-plugins-ugly
190 gst_all_1.gst-plugins-base
191 json-glib # paradox launcher (Stellaris)
193 libxkbcommon # paradox launcher
194 libvorbis # Dead Cells
195 libxcrypt # Alien Isolation, XCOM 2, Company of Heroes 2
197 ncurses # Crusader Kings III
201 xorg.libXScrnSaver # Dead Cells
202 icu # dotnet runtime, e.g. Stardew Valley
204 # screeps dependencies
220 # FIXME: Also requires openssl_1_1, which is EOL. Either find an alternative solution, or remove these dependencies (if not needed by other games)
226 # This needs to come from pkgs as the passed-in steam-runtime-wrapped may not be the same architecture
227 ++ pkgs.steamPackages.steam-runtime-wrapped.overridePkgs
228 ++ extraLibraries pkgs;
230 extraInstallCommands = lib.optionalString (steam != null) ''
231 mkdir -p $out/share/applications
232 ln -s ${steam}/share/icons $out/share
233 ln -s ${steam}/share/pixmaps $out/share
234 ln -s ${steam}/share/applications/steam.desktop $out/share/applications/steam.desktop
238 # Workaround for issue #44254 (Steam cannot connect to friends network)
239 # https://github.com/NixOS/nixpkgs/issues/44254
240 if [ -z ''${TZ+x} ]; then
241 new_TZ="$(readlink -f /etc/localtime | grep -P -o '(?<=/zoneinfo/).*$')"
242 if [ $? -eq 0 ]; then
247 # udev event notifications don't work reliably inside containers.
248 # SDL2 already tries to automatically detect flatpak and pressure-vessel
249 # and falls back to inotify-based discovery [1]. We make SDL2 do the
250 # same by telling it explicitly.
252 # [1] <https://github.com/libsdl-org/SDL/commit/8e2746cfb6e1f1a1da5088241a1440fd2535e321>
253 export SDL_JOYSTICK_DISABLE_UDEV=1
256 runScript = writeShellScript "steam-wrapper.sh" ''
257 if [ -f /host/etc/NIXOS ]; then # Check only useful on NixOS
258 ${glxinfo-i686}/bin/glxinfo >/dev/null 2>&1
259 # If there was an error running glxinfo, we know something is wrong with the configuration
260 if [ $? -ne 0 ]; then
261 cat <<EOF > /dev/stderr
263 WARNING: Steam is not set up. Add the following options to /etc/nixos/configuration.nix
264 and then run \`sudo nixos-rebuild switch\`:
266 hardware.opengl.driSupport32Bit = true;
267 hardware.pulseaudio.support32Bit = true;
277 set -o allexport # Export the following env vars
279 exec steam ${extraArgs} "$@"
282 inherit extraBwrapArgs;
287 steam.meta // lib.optionalAttrs (!withGameSpecificLibraries) {
288 description = steam.meta.description + " (without game specific libraries)";
291 description = "Steam dependencies (dummy package, do not use)";
294 passthru.run = buildFHSEnv {
297 targetPkgs = commonTargetPkgs;
298 inherit multiArch multiPkgs profile extraInstallCommands extraBwrapArgs;
300 runScript = writeShellScript "steam-run" ''
302 if [ "$run" = "" ]; then
303 echo "Usage: steam-run command-to-run args..." >&2
311 set -o allexport # Export the following env vars
316 meta = (steam.meta or {}) // {
317 description = "Run commands in the same FHS environment that is used for Steam";
318 mainProgram = "steam-run";