Jump to content

Steam/zh: Difference between revisions

From Official NixOS Wiki
RhenCloud (talk | contribs)
Created page with "2. 如果您需要更大的灵活性,或者想要使用已覆盖的 Steam 包的 FHS 环境:"
Tags: Mobile edit Mobile web edit
RhenCloud (talk | contribs)
Created page with "默认情况下,Steam 还会在 <code>~/.steam/root/compatibilitytools.d</code> 中查找自定义 Proton 版本。可以通过设置环境变量 <code>STEAM_EXTRA_COMPAT_TOOLS_PATHS</code> 来添加其他搜索路径。"
Line 131: Line 131:
</syntaxhighlight>
</syntaxhighlight>
=== Proton ===
=== Proton ===
<div lang="en" dir="ltr" class="mw-content-ltr">
您应该可以使用 Proton 运行大多数 Windows 游戏。如果某个游戏有原生 Linux 版本,但在 NixOS 上会出现问题,您可以通过在 Steam 的游戏兼容性设置中选择特定的 Proton 版本来强制使用 Proton
You should be able to play most Windows games using Proton. If a game has a native Linux version that causes issues on NixOS, you can force the use of Proton by selecting a specific Proton version in the game's compatibility settings in Steam.
默认情况下,Steam 还会在 <code>~/.steam/root/compatibilitytools.d</code> 中查找自定义 Proton 版本。可以通过设置环境变量 <code>STEAM_EXTRA_COMPAT_TOOLS_PATHS</code> 来添加其他搜索路径。
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
By default, Steam also looks for custom Proton versions in <code>~/.steam/root/compatibilitytools.d</code>. The environment variable <code>STEAM_EXTRA_COMPAT_TOOLS_PATHS</code> can be set to add other search paths.
</div>
自定义 Proton 版本的声明式安装(例如 GE-Proton):
自定义 Proton 版本的声明式安装(例如 GE-Proton):
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">

Revision as of 14:27, 11 February 2026

Steam is a digital distribution platform for video games, offering a vast library for purchase, download, and management. On NixOS, Steam is generally easy to install and use, often working "out-of-the-box". It supports running many Windows games on Linux through its compatibility layer, Proton.[1]

安装

Shell

要在 shell 环境中临时使用 Steam 相关工具,例如 steam-run(用于 FHS 环境)或 steamcmd(用于服务器管理或 steam-tui 设置等工具),可以运行以下命令。

nix-shell -p steam-run # For FHS environment
nix-shell -p steamcmd  # For steamcmd

这样就可以在当前 shell 中使用这些工具,而无需将其添加到系统配置中。为了使 steamcmd 能够正确执行某些任务(例如初始化 steam-tui),您可能需要运行一次 steamcmd 来生成必要的文件,如 `steam-tui` 部分所示。

系统设置

要安装 Steam 软件包并启用所有必要的系统选项以使其运行,请将以下内容添加到您的 /etc/nixos/configuration.nix 中:

# Example for /etc/nixos/configuration.nix
programs.steam = {
  enable = true;
  remotePlay.openFirewall = true; # Open ports in the firewall for Steam Remote Play
  dedicatedServer.openFirewall = true; # Open ports in the firewall for Source Dedicated Server
};

# Optional: If you encounter amdgpu issues with newer kernels (e.g., 6.10+ reported issues),
# you might consider using the LTS kernel or a known stable version.
# boot.kernelPackages = pkgs.linuxPackages_lts; # Example for LTS
Note: Enabling steam installs several unfree packages. If you are using allowUnfreePredicate you will need to ensure that your configurations permit all of them.
{
  nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
    "steam"
    "steam-unwrapped"
  ];
}

配置

基本 Steam 功能可以直接在 programs.steam 属性集中启用:

programs.steam = {
  enable = true; # Master switch, already covered in installation
  remotePlay.openFirewall = true;  # For Steam Remote Play
  dedicatedServer.openFirewall = true; # For Source Dedicated Server hosting
  # Other general flags if available can be set here.
};
# Tip: For improved gaming performance, you can also enable GameMode:
# programs.gamemode.enable = true;

如果您使用的是 Steam 控制器或 Valve Index,请确保已启用 Steam 硬件支持。这通常由 programs.steam.enable = true; ` 隐式地设置,该设置会同时启用 hardware.steam-hardware.enable = true; 。如有需要,您可以验证或显式地进行设置:

hardware.steam-hardware.enable = true;

提示和技巧

Gamescope Compositor / "启动至 Steam Deck"

Gamescope 可以作为最小桌面环境运行,这意味着您可以从 TTY 启动它,并获得与 Steam Deck 硬件控制台非常相似的体验。

# Clean Quiet Boot
boot.kernelParams = [ "quiet" "splash" "console=/dev/null" ];
boot.plymouth.enable = true;

programs.gamescope = {
  enable = true;
  capSysNice = true;
};
programs.steam.gamescopeSession.enable = true; # Integrates with programs.steam

# Gamescope Auto Boot from TTY (example)
services.xserver.enable = false; # Assuming no other Xserver needed
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 -steamdeck -steamos3 > /dev/null 2>&1";
      user = "USERNAME_HERE";
    };
  };
};

steam-tui

如果您想使用 steam-tui 客户端,则需要自行安装。它依赖于 steamcmd 的设置,因此您需要运行一次 steamcmd 来生成必要的配置文件。 首先,确保 steamcmd 可用(例如,运行 nix-shell -p steamcmd 或将其添加到 environment.systemPackages ),然后运行:

steamcmd +quit # This initializes steamcmd's directory structure

然后安装并运行 `steam-tui`。如果 `steam-tui` 出现问题,您可能需要先在 `steamcmd` 中登录:

# (Inside steamcmd prompt, if needed for full login before steam-tui)
# login <username> <password> <steam_2fa_code>
# quit

安装完成后, steam-tui (例如通过 home.packagesenvironment.systemPackages 安装)应该可以正常启动。

仅 FHS 环境

要运行需要标准 Linux 文件系统层次结构标准 (FHS) 的专有游戏或从互联网下载的软件,可以使用 steam-run 。它提供了一个类似 FHS 的环境,而无需对软件进行任何修改。 请注意,对于从 Nixpkgs 安装的客户端(如 Minigalaxy 或 Itch),这并非必要,因为它们已经根据需要使用 FHS 环境。 有两种方法可以实现 steam-run 功能: 1. 安装 steam-run ,可选择系统级安装或用户级安装:

# In /etc/nixos/configuration.nix
environment.systemPackages = with pkgs; [
  steam-run
];

2. 如果您需要更大的灵活性,或者想要使用已覆盖的 Steam 包的 FHS 环境:

# In /etc/nixos/configuration.nix
environment.systemPackages = with pkgs; [
  (steam.override { /* Your overrides here */ }).run
];

Proton

您应该可以使用 Proton 运行大多数 Windows 游戏。如果某个游戏有原生 Linux 版本,但在 NixOS 上会出现问题,您可以通过在 Steam 的游戏兼容性设置中选择特定的 Proton 版本来强制使用 Proton。 默认情况下,Steam 还会在 ~/.steam/root/compatibilitytools.d 中查找自定义 Proton 版本。可以通过设置环境变量 STEAM_EXTRA_COMPAT_TOOLS_PATHS 来添加其他搜索路径。 自定义 Proton 版本的声明式安装(例如 GE-Proton):

programs.steam.extraCompatPackages = with pkgs; [
  proton-ge-bin
];

可使用 ProtonUp-Qt 手动管理多个 Proton 版本:

environment.systemPackages = with pkgs; [
  protonup-qt
];

覆盖 Steam 软件包

In some cases, you may need to override the default Steam package to provide missing dependencies or modify its build. Use the programs.steam.package option for this. Steam on NixOS runs many games in an FHS environment, but the Steam client itself or certain tools might need extra libraries.

Example: Adding Bumblebee and Primus (for NVIDIA Optimus):

programs.steam.package = pkgs.steam.override {
  extraPkgs = pkgs': with pkgs'; [ bumblebee primus ];
};

# For 32-bit applications with Steam, if using steamFull:
# programs.steam.package = pkgs.steamFull.override { extraPkgs = pkgs': with pkgs'; [ bumblebee primus ]; };

Example: Adding Xorg libraries for Gamescope (when used within Steam):

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 # Provides libstdc++.so.6
    libkrb5
    keyutils
    # Add other libraries as needed
  ];
};

Fix missing icons for games in GNOME dock and activities overview

GNOME uses the window class to determine the icon associated with a window. Steam currently doesn't set the required key for this in its .desktop files[2], but you can fix this manually by editing the StartupWMClass key for each game's .desktop file, found under ~/.local/share/applications/.

For games running through Proton, the value should be steam_app_<game_id> (where <game_id> matches the value after steam://rungameid/ on the Exec line).

For games running natively, the value should match the game's main executable.

For example, the modified .desktop file for Valheim looks like this:

[Desktop Entry]
Name=Valheim
Comment=Play this game on Steam
Exec=steam steam://rungameid/892970
Icon=steam_icon_892970
Terminal=false
Type=Application
Categories=Game;
StartupWMClass=valheim.x86_64

故障排除

For all issues: first run steam -dev -console through the terminal and read the output.

Steam 无法启动。我该怎么办?

Run strace steam -dev -console 2> steam.logs in the terminal. If strace is not installed, temporarily install it using nix-shell -p strace or nix run nixpkgs#strace -- steam -dev -console 2> steam.logs (if using Flakes). After that, create a bug report.

Steam 未更新

When you restart Steam after an update, it starts the old version. (#181904) A workaround is to remove the user files in /home/<USER>/.local/share/Steam/userdata. This can be done with rm -rf /home/<USER>/.local/share/Steam/userdata in the terminal or with your file manager. After that, Steam can be set up again by restarting.

游戏无法启动

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
  • Add a file named steam_appid.txt in the binary folder, with the appid as contents (it can be found in the stdout from steam)
  • Using the LD_LIBRARY_PATH from the nix/store steam script, with some additions, launch the game binary
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)

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

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:

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 ];
};

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 AMD_VULKAN_ICD = "RADV" or VK_ICD_FILENAMES = "/run/opengl-driver/share/vulkan/icd.d/radeon_icd.x86_64.json" environment variable. For example, if you start Steam from the shell, you can enable radv for the current session by running AMD_VULKAN_ICD="RADV" steam. If you are unsure which driver you currently use, you can launch a game with 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: sudo setcap CAP_SYS_NICE+ep ~/.local/share/Steam/steamapps/common/SteamVR/bin/linux64/vrcompositor-launcher

与 Steam 使用时 Gamescope 无法启动

Gamescope may fail to start due to missing Xorg libraries. (#214275) To resolve this override the steam package to add them:

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 # Provides libstdc++.so.6
    libkrb5
    keyutils
    # Add other libraries as needed
  ];
};

额外游戏手柄的 udev 规则

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 services.udev.extraRules.

The following example is for the 8bitdo Ultimate Bluetooth controller, different controllers will require knowledge of the vendor and product ID for the device:

  services.udev.extraRules = ''
    SUBSYSTEM=="input", ATTRS{idVendor}=="2dc8", ATTRS{idProduct}=="3106", MODE="0660", GROUP="input"
  '';

To find the vendor and product ID of a device usbutils might be useful

已知问题

"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 steam-run bash.

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.

参考