acr-cli: init at 0.14 (#359508)
[NixPkgs.git] / pkgs / by-name / st / steam / package.nix
blobbc727e0ebfc53625f0d90adc0ec12040bc72d43b
2   lib,
3   steam-unwrapped,
4   buildFHSEnv,
5   writeShellScript,
6   extraPkgs ? pkgs: [ ], # extra packages to add to targetPkgs
7   extraLibraries ? pkgs: [ ], # extra packages to add to multiPkgs
8   extraProfile ? "", # string to append to profile
9   extraPreBwrapCmds ? "", # extra commands to run before calling bubblewrap
10   extraBwrapArgs ? [ ], # extra arguments to pass to bubblewrap (real default is at usage site)
11   extraArgs ? "", # arguments to always pass to steam
12   extraEnv ? { }, # Environment variables to pass to Steam
14 let
15   steamEnv = { name, runScript, passthru ? {}, meta ? {} }:
16   buildFHSEnv {
17     inherit name runScript passthru meta;
19     multiArch = true;
20     includeClosures = true;
22     # https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/blob/main/docs/distro-assumptions.md#command-line-tools
23     targetPkgs = pkgs: with pkgs; [
24       steam-unwrapped
26       bash
27       coreutils
28       file
29       lsb-release  # not documented, called from Big Picture
30       pciutils  # not documented, complains about lspci on startup
31       glibc_multi.bin
32       xz
33       zenity
35       # Steam expects it to be /sbin specifically
36       (pkgs.runCommand "sbin-ldconfig" {} ''
37         mkdir -p $out/sbin
38         ln -s /bin/ldconfig $out/sbin/ldconfig
39       '')
41       # crashes on startup if it can't find libX11 locale files
42       (pkgs.runCommand "xorg-locale" {} ''
43         mkdir -p $out
44         ln -s ${xorg.libX11}/share $out/share
45       '')
46     ] ++ extraPkgs pkgs;
48     # https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/blob/main/docs/distro-assumptions.md#shared-libraries
49     multiPkgs = pkgs: with pkgs; [
50       glibc
51       libxcrypt
52       libGL
54       libdrm
55       mesa  # for libgbm
56       udev
57       libudev0-shim
58       libva
59       vulkan-loader
61       networkmanager  # not documented, used for network status things in Big Picture
62                       # FIXME: figure out how to only build libnm?
63       libcap  # not documented, required by srt-bwrap
64     ] ++ extraLibraries pkgs;
66     extraInstallCommands = lib.optionalString (steam-unwrapped != null) ''
67       ln -s ${steam-unwrapped}/share $out/share
68     '';
70     profile = ''
71       # prevents log spam from SteamRT GTK trying to load host GIO modules
72       unset GIO_EXTRA_MODULES
74       # udev event notifications don't work reliably inside containers.
75       # SDL2 already tries to automatically detect flatpak and pressure-vessel
76       # and falls back to inotify-based discovery [1]. We make SDL2 do the
77       # same by telling it explicitly.
78       #
79       # [1] <https://github.com/libsdl-org/SDL/commit/8e2746cfb6e1f1a1da5088241a1440fd2535e321>
80       export SDL_JOYSTICK_DISABLE_UDEV=1
82       # This is needed for IME (e.g. iBus, fcitx5) to function correctly on non-CJK locales
83       # https://github.com/ValveSoftware/steam-for-linux/issues/781#issuecomment-2004757379
84       export GTK_IM_MODULE='xim'
86       # See https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/blob/main/docs/distro-assumptions.md#graphics-driver
87       export LIBGL_DRIVERS_PATH=/run/opengl-driver/lib/dri:/run/opengl-driver-32/lib/dri
88       export __EGL_VENDOR_LIBRARY_DIRS=/run/opengl-driver/share/glvnd/egl_vendor.d:/run/opengl-driver-32/share/glvnd/egl_vendor.d
89       export LIBVA_DRIVERS_PATH=/run/opengl-driver/lib/dri:/run/opengl-driver-32/lib/dri
90       export VDPAU_DRIVER_PATH=/run/opengl-driver/lib/vdpau:/run/opengl-driver-32/lib/vdpau
92       set -a
93       ${lib.toShellVars extraEnv}
94       set +a
96       ${extraProfile}
97     '';
99     privateTmp = true;
101     inherit extraPreBwrapCmds;
103     extraBwrapArgs = [
104       # Steam will dump crash reports here, make those more accessible
105       "--bind-try /tmp/dumps /tmp/dumps"
106     ] ++ extraBwrapArgs;
107   };
108 in steamEnv {
109   name = "steam";
111   runScript = writeShellScript "steam-wrapped" ''
112     exec steam ${extraArgs} "$@"
113   '';
115   passthru.run = steamEnv {
116     name = "steam-run";
118     runScript = writeShellScript "steam-run" ''
119       if [ $# -eq 0 ]; then
120         echo "Usage: steam-run command-to-run args..." >&2
121         exit 1
122       fi
124       exec "$@"
125     '';
127     meta = (steam-unwrapped.meta or {}) // {
128       description = "Run commands in the same FHS environment that is used for Steam";
129       mainProgram = "steam-run";
130       name = "steam-run";
131       # steam-run itself is just a script that lives in nixpkgs (which is licensed under MIT).
132       # steam is a dependency and already unfree, so normal steam-run will not install without
133       # allowing unfree packages or appropriate `allowUnfreePredicate` rules.
134       license = lib.licenses.mit;
135     };
136   };
138   meta = (steam-unwrapped.meta or {}) // {
139     description = "Steam dependencies (dummy package, do not use)";
140   };