Jump to content

Steam/zh: Difference between revisions

From Official NixOS Wiki
FuzzyBot (talk | contribs)
Updating to match new version of source page
FuzzyBot (talk | contribs)
Updating to match new version of source page
 
(40 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<div lang="en" dir="ltr" class="mw-content-ltr">
[https://store.steampowered.com/ Steam] 是一个数字游戏发行平台,提供庞大的游戏库供用户购买、下载和管理。在 NixOS 系统上,Steam 通常易于安装和使用,很多时候都能“开箱即用”。它通过兼容层 [[#Proton|Proton]] 支持在 Linux 上运行许多 Windows 游戏。<ref>https://store.steampowered.com/</ref>
[https://store.steampowered.com/ 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.<ref>https://store.steampowered.com/</ref>
</div>


<span id="Installation"></span>
<span id="Installation"></span>
Line 9: Line 7:
==== Shell ====
==== Shell ====


<div lang="en" dir="ltr" class="mw-content-ltr">
要在 shell 环境中临时使用 Steam 相关工具,例如 <code>steam-run</code>(用于 FHS 环境)或 <code>steamcmd</code>(用于服务器管理或 steam-tui 设置等工具),可以运行以下命令。
To temporarily use Steam-related tools like <code>steam-run</code> (for FHS environments) or <code>steamcmd</code> (for server management or tools like steam-tui setup) in a shell environment, you can run:
 
</div>
<syntaxhighlight lang="console">
<syntaxhighlight lang="bash">
$ nix-shell -p steam-run # For FHS environment
nix-shell -p steam-run # For FHS environment
$ nix-shell -p steamcmd  # For steamcmd
nix-shell -p steamcmd  # For steamcmd
</syntaxhighlight>
</syntaxhighlight>
<div lang="en" dir="ltr" class="mw-content-ltr">
 
This provides the tools in your current shell without adding them to your system configuration. For <code>steamcmd</code> to work correctly for some tasks (like initializing for steam-tui), you might need to run it once to generate necessary files, as shown in the `steam-tui` section.
这样就可以在当前 shell 中使用这些工具,而无需将其添加到系统配置中。为了使 <code>steamcmd</code> 能够正确执行某些任务(例如初始化 steam-tui),您可能需要运行一次 steamcmd 来生成必要的文件,如 [[#steam-tui| steam-tui]] 部分所示。
</div>


<span id="System_setup"></span>
<span id="System_setup"></span>
==== 系统设置 ====
==== 系统设置 ====


<div lang="en" dir="ltr" class="mw-content-ltr">
要安装 [[Special:MyLanguage/Steam|Steam]] 软件包并启用所有必要的系统选项以使其运行,请将以下内容添加到您的系统配置中:
To install the [[Steam]] package and enable all the system options necessary to allow it to run, add the following to your <code>/etc/nixos/configuration.nix</code>:
 
</div>
{{file|/etc/nixos/configuration.nix|nix|
<syntaxhighlight lang="nix">
<nowiki>
# Example for /etc/nixos/configuration.nix
programs.steam = {
programs.steam = {
   enable = true;
   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
};
};


Line 37: Line 30:
# you might consider using the LTS kernel or a known stable version.
# you might consider using the LTS kernel or a known stable version.
# boot.kernelPackages = pkgs.linuxPackages_lts; # Example for LTS
# boot.kernelPackages = pkgs.linuxPackages_lts; # Example for LTS
</syntaxhighlight>
</nowiki>
<div lang="en" dir="ltr" class="mw-content-ltr">
}}
[https://news.ycombinator.com/item?id=41549030 Anecdata on kernel 6.10 issues]
 
</div>
[https://news.ycombinator.com/item?id=41549030 关于内核 6.10 问题的轶事]
 
{{note|1=启用 [[Special:MyLanguage/Steam|Steam]] 会安装多个[[Special:MyLanguage/unfree software|非自由软件包]]。如果您使用了 <code>allowUnfreePredicate</code>,则需要确保您的配置允许安装所有这些软件包。


{{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">
<syntaxhighlight lang="nix">
{
   nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
   nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
     "steam"
     "steam"
     "steam-unwrapped"
     "steam-unwrapped"
   ];
   ];
}
</syntaxhighlight>}}
</syntaxhighlight>
}}


<span id="Configuration"></span>
<span id="Configuration"></span>
== 配置 ==
== 配置 ==


<div lang="en" dir="ltr" class="mw-content-ltr">
基本 Steam 功能可以直接在 {{nixos:option|programs.steam}} 属性集中启用:
Basic Steam features can be enabled directly within the <code>programs.steam</code> attribute set:
 
</div>
{{file|/etc/nixos/configuration.nix|nix|
<syntaxhighlight lang="nix">
<nowiki>
programs.steam = {
programs.steam = {
   enable = true; # Master switch, already covered in installation
   enable = true; # Master switch, already covered in installation
   remotePlay.openFirewall = true;  # For Steam Remote Play
   remotePlay.openFirewall = true;  # Open ports in the firewall for Steam Remote Play
   dedicatedServer.openFirewall = true; # For Source Dedicated Server hosting
   dedicatedServer.openFirewall = true; # Open ports for Source Dedicated Server hosting
   # Other general flags if available can be set here.
   # Other general flags if available can be set here.
};
};
# Tip: For improved gaming performance, you can also enable GameMode:
# Tip: For improved gaming performance, you can also enable GameMode:
# programs.gamemode.enable = true;
# programs.gamemode.enable = true;
</syntaxhighlight>
</nowiki>
<div lang="en" dir="ltr" class="mw-content-ltr">
}}
If you are using a Steam Controller or a Valve Index, ensure Steam hardware support is enabled. This is typically handled by <code>programs.steam.enable = true;</code> which sets <code>hardware.steam-hardware.enable = true;</code> implicitly. You can verify or explicitly set it if needed:
 
</div>
{{note|如果您使用的是 Steam 控制器或 Valve Index,Steam 硬件支持会通过设置 <code>programs.steam.enable {{=}} true;</code> 将{{nixos:option|hardware.steam-hardware.enable}} 选项同步设置为 true 来隐性启用}}
<syntaxhighlight lang="nix">
 
hardware.steam-hardware.enable = true;
</syntaxhighlight>
<span id="Tips_and_tricks"></span>
<span id="Tips_and_tricks"></span>
== 提示和技巧 ==
== 提示和技巧 ==
Line 80: Line 69:
<span id="Gamescope_Compositor_/_&quot;Boot_to_Steam_Deck&quot;"></span>
<span id="Gamescope_Compositor_/_&quot;Boot_to_Steam_Deck&quot;"></span>
=== Gamescope Compositor / "启动至 Steam Deck" ===
=== Gamescope Compositor / "启动至 Steam Deck" ===
<div lang="en" dir="ltr" class="mw-content-ltr">
 
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.
Gamescope 可以作为最小桌面环境运行,这意味着您可以从 TTY 启动它,并获得与 Steam Deck 硬件控制台非常相似的体验。
</div>
 
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# Clean Quiet Boot
# Clean Quiet Boot
boot.kernelParams = [ "quiet" "splash" "console=/dev/null" ];
boot = {
boot.plymouth.enable = true;
  kernelParams = [
    "quiet"
    "splash"
    "console=/dev/null"
  ];
  plymouth.enable = true;
};


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


# Gamescope Auto Boot from TTY (example)
# Gamescope Auto Boot from TTY (example)
services.xserver.enable = false; # Assuming no other Xserver needed
services = {
services.getty.autologinUser = "USERNAME_HERE";
  xserver.enable = false; # Assuming no other Xserver needed
  getty.autologinUser = <"USERNAME_HERE">;
  greetd = {
    enable = true;
    settings = {
      default_session = {
        command = "${lib.getExe pkgs.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">;
      };
    };
  };
};
</syntaxhighlight>
 
=== Gamescope HDR ===
 
要使 HDR 在 gamescope 中工作,您需要在启用 <code>gamescope</code> 程序的同时,单独安装 <code>gamescope-wsi</code> 软件包。


services.greetd = {
<syntaxhighlight lang="nix">
programs.gamescope = {
   enable = true;
   enable = true;
   settings = {
   capSysNice = false;
    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";
    };
  };
};
};
environment.systemPackages = with pkgs; [
  gamescope-wsi # HDR won't work without this
];
</syntaxhighlight>
此外,在 Steam 中配置游戏启动选项时,可能需要使用参数 <code>--hdr-debug-force-output</code> 以在 gamescope 中强制启用 HDR(参考以下示例)。
<syntaxhighlight lang="bash">
gamescope -W 3840 -H 2160 -r 120 -f --adaptive-sync --hdr-enabled --hdr-debug-force-output --mangoapp -- %command%
</syntaxhighlight>
</syntaxhighlight>


=== steam-tui ===
=== steam-tui ===
<div lang="en" dir="ltr" class="mw-content-ltr">
 
If you want the steam-tui client, you'll have to install it. It relies on <code>steamcmd</code> being set up, so you'll need to run <code>steamcmd</code> once to generate the necessary configuration files.
如果您想使用 steam-tui 客户端,则需要自行安装。它依赖于 <code>steamcmd</code> 的设置,因此您需要运行一次 <code>steamcmd</code> 来生成必要的配置文件。
First, ensure <code>steamcmd</code> is available (e.g., via <code>nix-shell -p steamcmd</code> or by adding it to <code>environment.systemPackages</code>), then run:
首先,确保 <code>steamcmd</code> 可用(例如,运行 <code>nix-shell -p steamcmd</code> 或将其添加到 <code>environment.systemPackages</code> ),然后运行:
</div>
 
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
steamcmd +quit # This initializes steamcmd's directory structure
steamcmd +quit # This initializes steamcmd's directory structure
</syntaxhighlight>
</syntaxhighlight>
<div lang="en" dir="ltr" class="mw-content-ltr">
 
Then install and run `steam-tui`. You may need to log in within `steamcmd` first if `steam-tui` has issues:
然后安装并运行 <code>steam-tui</code>。如果 <code>steamcmd</code> 出现问题,您可能需要先在 <code>steam-tui</code> 中登录:
</div>
 
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
# (Inside steamcmd prompt, if needed for full login before steam-tui)
# (Inside steamcmd prompt, if needed for full login before steam-tui)
Line 125: Line 143:
# quit
# quit
</syntaxhighlight>
</syntaxhighlight>
<div lang="en" dir="ltr" class="mw-content-ltr">
 
After setup, <code>steam-tui</code> (if installed e.g. via <code>home.packages</code> or <code>environment.systemPackages</code>) should start fine.
安装完成后, <code>steam-tui</code> (例如通过 <code>home.packages</code> <code>environment.systemPackages</code> 安装)应该可以正常启动。
</div>


<span id="FHS_environment_only"></span>
<span id="FHS_environment_only"></span>
=== 仅 FHS 环境 ===
=== 仅 FHS 环境 ===
<div lang="en" dir="ltr" class="mw-content-ltr">
 
To run proprietary games or software downloaded from the internet that expect a typical Linux Filesystem Hierarchy Standard (FHS), you can use <code>steam-run</code>. This provides an FHS-like environment without needing to patch the software.
要运行需要标准 Linux 文件系统层次结构标准 (FHS) 的专有游戏或从互联网下载的软件,可以使用 <code>steam-run</code> 。它提供了一个类似 FHS 的环境,而无需对软件进行任何修改。
Note that this is not necessary for clients installed from Nixpkgs (like Minigalaxy or Itch), which already use the FHS environment as needed.
请注意,对于从 Nixpkgs 安装的客户端(如 Minigalaxy Itch),这并非必要,因为它们已经根据需要使用 FHS 环境。
There are two options to make <code>steam-run</code> available:
有两种方法可以实现 <code>steam-run</code> 功能:
1. Install <code>steam-run</code> system-wide or user-specifically:
1. 安装 <code>steam-run</code> ,可选择系统级安装或用户级安装:
</div>
 
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# In /etc/nixos/configuration.nix
# In /etc/nixos/configuration.nix
Line 143: Line 160:
];
];
</syntaxhighlight>
</syntaxhighlight>
<div lang="en" dir="ltr" class="mw-content-ltr">
 
2. If you need more flexibility or want to use an overridden Steam package's FHS environment:
2. 如果您需要更大的灵活性,或者想要使用已覆盖的 Steam 包的 FHS 环境:
</div>
 
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# In /etc/nixos/configuration.nix
# In /etc/nixos/configuration.nix
Line 152: Line 169:
];
];
</syntaxhighlight>
</syntaxhighlight>
=== Proton ===
=== Proton ===
<div lang="en" dir="ltr" class="mw-content-ltr">
 
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.
您应该可以使用 Proton 运行大多数 Windows 游戏。如果某个游戏有原生 Linux 版本,但在 NixOS 上会出现问题,您可以通过在 Steam 的游戏兼容性设置中选择特定的 Proton 版本来强制使用 Proton
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
默认情况下,Steam 还会在 <code>~/.steam/root/compatibilitytools.d</code> 中查找自定义 Proton 版本。可以通过设置环境变量 <code>STEAM_EXTRA_COMPAT_TOOLS_PATHS</code> 来添加其他搜索路径。
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">
programs.steam.extraCompatPackages = with pkgs; [
programs.steam.extraCompatPackages = with pkgs; [
Line 165: Line 183:
];
];
</syntaxhighlight>
</syntaxhighlight>
可使用 ProtonUp-Qt 手动管理多个 Proton 版本:
可使用 ProtonUp-Qt 手动管理多个 Proton 版本:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
environment.systemPackages = with pkgs; [
environment.systemPackages = with pkgs; [
Line 171: Line 191:
];
];
</syntaxhighlight>
</syntaxhighlight>
<span id="Overriding_the_Steam_package"></span>
<span id="Overriding_the_Steam_package"></span>
=== 覆盖 Steam 软件包 ===
=== 覆盖 Steam 软件包 ===
<div lang="en" dir="ltr" class="mw-content-ltr">
 
In some cases, you may need to override the default Steam package to provide missing dependencies or modify its build. Use the <code>programs.steam.package</code> 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.
在某些情况下,您可能需要覆盖默认的 Steam 程序包以提供缺失的依赖项或修改其构建。为此,请使用 <code>programs.steam.package</code> 选项。NixOS 上的 Steam 会在 FHS 环境下运行许多游戏,但 Steam 客户端本身或某些工具可能需要额外的库。
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
示例:添加 Bumblebee Primus(适用于 NVIDIA Optimus):
Example: Adding Bumblebee and Primus (for NVIDIA Optimus):
 
</div>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
programs.steam.package = pkgs.steam.override {
programs.steam.package = pkgs.steam.override {
Line 188: Line 208:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
示例:为 Gamescope 添加 Xorg 库(在 Steam 中使用时):
Example: Adding Xorg libraries for Gamescope (when used within Steam):
 
</div>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
programs.steam.package = pkgs.steam.override {
programs.steam.package = pkgs.steam.override {
   extraPkgs = pkgs': with pkgs'; [
   extraPkgs = pkgs': with pkgs'; [
     xorg.libXcursor
     libXcursor
     xorg.libXi
     libXi
     xorg.libXinerama
     libXinerama
     xorg.libXScrnSaver
     libXScrnSaver
     libpng
     libpng
     libpulseaudio
     libpulseaudio
Line 209: Line 228:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Fix_missing_icons_for_games_in_GNOME_dock_and_activities_overview"></span>
=== Fix missing icons for games in GNOME dock and activities overview ===
=== 修复 GNOME Dock 栏和活动概览中游戏图标缺失的问题 ===
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
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<ref>https://github.com/ValveSoftware/steam-for-linux/issues/12207</ref>, but you can fix this manually by editing the <code>StartupWMClass</code> key for each game's .desktop file, found under <code>~/.local/share/applications/</code>.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
GNOME 使用窗口类来确定与窗口关联的图标。Steam 目前在其 .desktop 文件中没有设置所需的键值<ref>https://github.com/ValveSoftware/steam-for-linux/issues/12207</ref>,但您可以通过编辑每个游戏的 .desktop 文件中的 <code>StartupWMClass</code> 键值来手动修复此问题,该文件位于 <code>~/.local/share/applications/</code> 目录下。
For games running through Proton, the value should be <code>steam_app_<game_id></code> (where <code><game_id></code> matches the value after steam://rungameid/ on the <code>Exec</code> line).
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
对于通过 Proton 运行的游戏,该值应为 <code>steam_app_<game_id></code> (在哪里<code><game_id></code>与 <code>Exec</code> 行中 steam://rungameid/ 之后的值匹配)。
For games running natively, the value should match the game's main executable.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
对于原生运行的游戏,该值应与游戏的主可执行文件匹配。
For example, the modified .desktop file for Valheim looks like this:
 
</div>
例如,Valheim 的修改后的 .desktop 文件如下所示:


<syntaxhighlight lang="desktop">
<syntaxhighlight lang="desktop">
Line 239: Line 250:
StartupWMClass=valheim.x86_64
StartupWMClass=valheim.x86_64
</syntaxhighlight>
</syntaxhighlight>
<span id="Troubleshooting"></span>
<span id="Troubleshooting"></span>
== 故障排除 ==
== 故障排除 ==


<div lang="en" dir="ltr" class="mw-content-ltr">
对于所有问题:首先通过终端运行 <code>steam -dev -console</code> 并读取输出。
For all issues: first run <code>steam -dev -console</code> through the terminal and read the output.
</div>


<span id="Steam_fails_to_start._What_do_I_do?"></span>
<span id="Steam_fails_to_start._What_do_I_do?"></span>
=== Steam 无法启动。我该怎么办? ===
=== Steam 无法启动。我该怎么办? ===
<div lang="en" dir="ltr" class="mw-content-ltr">
 
Run <code>strace steam -dev -console 2> steam.logs</code> in the terminal. If <code>strace</code> is not installed, temporarily install it using <code>nix-shell -p strace</code> or <code>nix run nixpkgs#strace -- steam -dev -console 2> steam.logs</code> (if using Flakes). After that, create a bug report. <!-- This is vague. Where should the user create a bug report?  -->
至少在 <code>x86-64</code> 平台上,导致 Steam 无法启动的一个常见问题是未在  <code>/etc/nixos/hardware-configuration.nix</code> 文件中启用以下选项:
</div>
 
<syntaxhighlight lang="nix">
{
  hardware.graphics.enable = true;
  hardware.graphics.enable32Bit = true;
}
</syntaxhighlight>
 
如果您已设置这些选项(或者 32 位不适用于您的系统/平台),但仍然无法运行 Steam,请在终端运行 <code>strace steam -dev -console 2> steam.logs</code> 命令。如果未安装 <code>strace</code> ,请使用 <code>nix-shell -p strace</code> <code>nix run nixpkgs#strace -- steam -dev -console 2> steam.logs</code> (如果使用 Flakes 版本)临时安装。之后,请提交错误报告。


<span id="Steam_is_not_updated"></span>
<span id="Steam_is_not_updated"></span>
=== Steam 未更新 ===
=== Steam 未更新 ===
<div lang="en" dir="ltr" class="mw-content-ltr">
 
When you restart [[Steam]] after an update, it starts the old version. ([https://github.com/NixOS/nixpkgs/issues/181904 #181904])
更新后重启 [[Special:MyLanguage/Steam|Steam]] 时,它会启动旧版本。([https://github.com/NixOS/nixpkgs/issues/181904 #181904])
A workaround is to remove the user files in <code>/home/&lt;USER&gt;/.local/share/Steam/userdata</code>. This can be done with <code>rm -rf /home/&lt;USER&gt;/.local/share/Steam/userdata</code> in the terminal or with your file manager. After that, Steam can be set up again by restarting.
一个解决方法是删除 <code>/home/&lt;USER&gt;/.local/share/Steam/userdata</code> 目录下的用户文件。您可以在终端中使用 <code>rm -rf /home/&lt;USER&gt;/.local/share/Steam/userdata</code> 命令或文件管理器来完成此操作。之后,重启 Steam 即可重新生成配置。
</div>


<span id="Game_fails_to_start"></span>
<span id="Game_fails_to_start"></span>
=== 游戏无法启动 ===
=== 游戏无法启动 ===
<div lang="en" dir="ltr" class="mw-content-ltr">
 
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)
* 在二进制文件夹中添加一个名为 steam_appid.txt 的文件,内容为 appid(可在 Steam 的标准输出中找到)。
* Using the LD_LIBRARY_PATH from the nix/store steam script, with some additions, launch the game binary
* 使用来自 nix/store steam 脚本的 LD_LIBRARY_PATH,启动游戏二进制文件
</div>
 
<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 parameter)
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>
</syntaxhighlight>
<div lang="en" dir="ltr" class="mw-content-ltr">
Note: If a game gets stuck on Installing scripts, check for a DXSETUP.EXE process and run it manually, then restart the game launch.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
注意:如果游戏卡在“正在安装脚本”界面,请检查是否存在 DXSETUP.EXE 进程并手动运行它,然后重新启动游戏。
==== 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/ -->====
 
</div>
<span id="Changing_the_driver_on_AMD_GPUs"></span>
{{note|This is not recommended because radv drivers tend to perform better and are generally more stable than amdvlk.}}
==== 更改 AMD GPU 的驱动程序 ====
<div lang="en" dir="ltr" class="mw-content-ltr">
 
Sometimes, changing the driver on AMD GPUs helps. To try this, first, install multiple drivers such as radv and amdvlk:
{{note|不建议这样做,因为 radv 驱动程序往往性能更好,而且通常比 amdvlk 驱动程序更稳定。}}
</div>
 
有时,更换 AMD GPU 的驱动程序会有帮助。要尝试此方法,首先,安装多个驱动程序,例如 radv amdvlk
 
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
hardware.graphics = {
hardware.graphics = {
Line 291: Line 307:
};
};
</syntaxhighlight>
</syntaxhighlight>
<div lang="en" dir="ltr" class="mw-content-ltr">
 
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.
如果两个驱动程序都存在,[[Special:MyLanguage/Steam|Steam]] 将默认使用 amdvlk。amdvlk 驱动程序在 Vulkan 规范实现方面更准确,但性能不如 radv。然而,这种在正确性和性能之间的权衡有时会直接影响游戏体验。
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
如果同时安装了 radv 和 amdvlk,要将驱动程序“重置”为 radv,请设置环境变量 <code>AMD_VULKAN_ICD = "RADV"</code> <code>VK_ICD_FILENAMES = "/run/opengl-driver/share/vulkan/icd.d/radeon_icd.x86_64.json"</code> 。例如,如果您从 shell 启动 Steam,则可以通过运行 <code>AMD_VULKAN_ICD="RADV" steam</code> 为当前会话启用 radv。如果您不确定当前使用的是哪个驱动程序,可以启动一个启用了 [https://github.com/flightlessmango/MangoHud MangoHud] 的游戏,MangoHud 可以显示当前正在使用的驱动程序。
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.
 
</div>
=== SteamVR ===
=== SteamVR ===
<div lang="en" dir="ltr" class="mw-content-ltr">
 
The setcap issue at SteamVR start can be fixed with:
SteamVR 启动时的 setcap 问题可以通过以下方法解决:
<code>sudo setcap CAP_SYS_NICE+ep ~/.local/share/Steam/steamapps/common/SteamVR/bin/linux64/vrcompositor-launcher</code>
<code>sudo setcap CAP_SYS_NICE+ep ~/.local/share/Steam/steamapps/common/SteamVR/bin/linux64/vrcompositor-launcher</code>
</div>
 
<span id="Gamescope_fails_to_launch_when_used_within_Steam"></span>
<span id="Gamescope_fails_to_launch_when_used_within_Steam"></span>
=== 与 Steam 使用时 Gamescope 无法启动 ===
=== 与 Steam 使用时 Gamescope 无法启动 ===
<div lang="en" dir="ltr" class="mw-content-ltr">
 
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:
Gamescope 可能由于缺少 Xorg 库而无法启动。([https://github.com/NixOS/nixpkgs/issues/214275 #214275]) 要解决此问题,请添加以下内容覆盖 steam 包:
</div>
 
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
programs.steam.package = pkgs.steam.override {
programs.steam.package = pkgs.steam.override {
   extraPkgs = pkgs': with pkgs'; [
   extraPkgs = pkgs': with pkgs'; [
     xorg.libXcursor
     libXcursor
     xorg.libXi
     libXi
     xorg.libXinerama
     libXinerama
     xorg.libXScrnSaver
     libXScrnSaver
     libpng
     libpng
     libpulseaudio
     libpulseaudio
Line 324: Line 339:
};
};
</syntaxhighlight>
</syntaxhighlight>
<span id="Udev_rules_for_additional_Gamepads"></span>
<span id="Udev_rules_for_additional_Gamepads"></span>
=== 额外游戏手柄的 udev 规则 ===
=== 额外游戏手柄的 udev 规则 ===
<div lang="en" dir="ltr" class="mw-content-ltr">
 
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>.
在某些特定情况下,游戏手柄可能需要一些额外的配置才能正常工作,这些配置以 udev 规则的形式表示。这可以通过 <code>services.udev.extraRules</code> 来配置。
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
以下示例适用于 8bitdo Ultimate 蓝牙控制器,不同的控制器需要知道设备的供应商和产品 ID
The following example is for the 8bitdo Ultimate Bluetooth controller, different controllers will require knowledge of the vendor and product ID for the device:
 
</div>
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
   services.udev.extraRules = ''
   services.udev.extraRules = ''
Line 337: Line 352:
   '';
   '';
</syntaxhighlight>
</syntaxhighlight>
<div lang="en" dir="ltr" class="mw-content-ltr">
 
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
要查找设备的供应商和产品 ID[https://search.nixos.org/packages?channel=unstable&show=usbutils&from=0&size=50&sort=relevance&type=packages&query=usbutils usbutils] 可能有用。
</div>
 
<span id="Known_issues"></span>
<span id="Known_issues"></span>
=== 已知问题 ===
=== 已知问题 ===
<div lang="en" dir="ltr" class="mw-content-ltr">
"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>.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
“Project Zomboid”可能会报告“无法确定Java是32位还是64位”。这与Java本身无关,是由其使用自身过时的Java二进制文件解析路径时,其中包含非拉丁字符导致的。请通过在<code>steam-run bash</code>中直接启动本地Java二进制文件来解决错误。
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.
 
</div>
通过 [[Special:MyLanguage/Steam|Steam]] 应用重置密码可能会反复在验证码环节失败,即使验证码界面显示成功,[[Special:MyLanguage/Steam|Steam]] 本身也会提示验证码错误。通过 [[Special:MyLanguage/Steam|Steam]] 网站重置密码应该可以解决这个问题。
 
<span id="References"></span>
<span id="References"></span>
== 参考 ==
== 参考 ==

Latest revision as of 10:35, 8 March 2026

Steam 是一个数字游戏发行平台,提供庞大的游戏库供用户购买、下载和管理。在 NixOS 系统上,Steam 通常易于安装和使用,很多时候都能“开箱即用”。它通过兼容层 Proton 支持在 Linux 上运行许多 Windows 游戏。[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
programs.steam = {
  enable = true;
};

# 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

关于内核 6.10 问题的轶事

Note: 启用 Steam 会安装多个非自由软件包。如果您使用了 allowUnfreePredicate,则需要确保您的配置允许安装所有这些软件包。
  nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
    "steam"
    "steam-unwrapped"
  ];

配置

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

❄︎ /etc/nixos/configuration.nix
programs.steam = {
  enable = true; # Master switch, already covered in installation
  remotePlay.openFirewall = true;  # Open ports in the firewall for Steam Remote Play
  dedicatedServer.openFirewall = true; # Open ports 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;
Note: 如果您使用的是 Steam 控制器或 Valve Index,Steam 硬件支持会通过设置 programs.steam.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"
  ];
  plymouth.enable = true;
};

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

# Gamescope Auto Boot from TTY (example)
services = {
  xserver.enable = false; # Assuming no other Xserver needed
  getty.autologinUser = <"USERNAME_HERE">;
  greetd = {
    enable = true;
    settings = {
      default_session = {
        command = "${lib.getExe pkgs.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">;
      };
    };
  };
};

Gamescope HDR

要使 HDR 在 gamescope 中工作,您需要在启用 gamescope 程序的同时,单独安装 gamescope-wsi 软件包。

programs.gamescope = {
  enable = true;
  capSysNice = false;
};
environment.systemPackages = with pkgs; [
  gamescope-wsi # HDR won't work without this
];

此外,在 Steam 中配置游戏启动选项时,可能需要使用参数 --hdr-debug-force-output 以在 gamescope 中强制启用 HDR(参考以下示例)。

gamescope -W 3840 -H 2160 -r 120 -f --adaptive-sync --hdr-enabled --hdr-debug-force-output --mangoapp -- %command%

steam-tui

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

steamcmd +quit # This initializes steamcmd's directory structure

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

# (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 软件包

在某些情况下,您可能需要覆盖默认的 Steam 程序包以提供缺失的依赖项或修改其构建。为此,请使用 programs.steam.package 选项。NixOS 上的 Steam 会在 FHS 环境下运行许多游戏,但 Steam 客户端本身或某些工具可能需要额外的库。

示例:添加 Bumblebee 和 Primus(适用于 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 ]; };

示例:为 Gamescope 添加 Xorg 库(在 Steam 中使用时):

programs.steam.package = pkgs.steam.override {
  extraPkgs = pkgs': with pkgs'; [
    libXcursor
    libXi
    libXinerama
    libXScrnSaver
    libpng
    libpulseaudio
    libvorbis
    stdenv.cc.cc.lib # Provides libstdc++.so.6
    libkrb5
    keyutils
    # Add other libraries as needed
  ];
};

修复 GNOME Dock 栏和活动概览中游戏图标缺失的问题

GNOME 使用窗口类来确定与窗口关联的图标。Steam 目前在其 .desktop 文件中没有设置所需的键值[2],但您可以通过编辑每个游戏的 .desktop 文件中的 StartupWMClass 键值来手动修复此问题,该文件位于 ~/.local/share/applications/ 目录下。

对于通过 Proton 运行的游戏,该值应为 steam_app_<game_id> (在哪里<game_id>Exec 行中 steam://rungameid/ 之后的值匹配)。

对于原生运行的游戏,该值应与游戏的主可执行文件匹配。

例如,Valheim 的修改后的 .desktop 文件如下所示:

[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

故障排除

对于所有问题:首先通过终端运行 steam -dev -console 并读取输出。

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

至少在 x86-64 平台上,导致 Steam 无法启动的一个常见问题是未在 /etc/nixos/hardware-configuration.nix 文件中启用以下选项:

 {
   hardware.graphics.enable = true;
   hardware.graphics.enable32Bit = true;
 }

如果您已设置这些选项(或者 32 位不适用于您的系统/平台),但仍然无法运行 Steam,请在终端运行 strace steam -dev -console 2> steam.logs 命令。如果未安装 strace ,请使用 nix-shell -p stracenix run nixpkgs#strace -- steam -dev -console 2> steam.logs (如果使用 Flakes 版本)临时安装。之后,请提交错误报告。

Steam 未更新

更新后重启 Steam 时,它会启动旧版本。(#181904) 一个解决方法是删除 /home/<USER>/.local/share/Steam/userdata 目录下的用户文件。您可以在终端中使用 rm -rf /home/<USER>/.local/share/Steam/userdata 命令或文件管理器来完成此操作。之后,重启 Steam 即可重新生成配置。

游戏无法启动

游戏可能无法启动,原因可能是缺少依赖项(目前应将此添加到脚本中),或者无法进行补丁更新。直接启动游戏的步骤如下: 如果可以,请修补脚本/二进制文件。

  • 在二进制文件夹中添加一个名为 steam_appid.txt 的文件,内容为 appid(可在 Steam 的标准输出中找到)。
  • 使用来自 nix/store steam 脚本的 LD_LIBRARY_PATH,启动游戏二进制文件
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)

注意:如果游戏卡在“正在安装脚本”界面,请检查是否存在 DXSETUP.EXE 进程并手动运行它,然后重新启动游戏。

更改 AMD GPU 的驱动程序

Note: 不建议这样做,因为 radv 驱动程序往往性能更好,而且通常比 amdvlk 驱动程序更稳定。

有时,更换 AMD GPU 的驱动程序会有帮助。要尝试此方法,首先,安装多个驱动程序,例如 radv 和 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 ];
};

如果两个驱动程序都存在,Steam 将默认使用 amdvlk。amdvlk 驱动程序在 Vulkan 规范实现方面更准确,但性能不如 radv。然而,这种在正确性和性能之间的权衡有时会直接影响游戏体验。

如果同时安装了 radv 和 amdvlk,要将驱动程序“重置”为 radv,请设置环境变量 AMD_VULKAN_ICD = "RADV"VK_ICD_FILENAMES = "/run/opengl-driver/share/vulkan/icd.d/radeon_icd.x86_64.json" 。例如,如果您从 shell 启动 Steam,则可以通过运行 AMD_VULKAN_ICD="RADV" steam 为当前会话启用 radv。如果您不确定当前使用的是哪个驱动程序,可以启动一个启用了 MangoHud 的游戏,MangoHud 可以显示当前正在使用的驱动程序。

SteamVR

SteamVR 启动时的 setcap 问题可以通过以下方法解决: sudo setcap CAP_SYS_NICE+ep ~/.local/share/Steam/steamapps/common/SteamVR/bin/linux64/vrcompositor-launcher

与 Steam 使用时 Gamescope 无法启动

Gamescope 可能由于缺少 Xorg 库而无法启动。(#214275) 要解决此问题,请添加以下内容覆盖 steam 包:

programs.steam.package = pkgs.steam.override {
  extraPkgs = pkgs': with pkgs'; [
    libXcursor
    libXi
    libXinerama
    libXScrnSaver
    libpng
    libpulseaudio
    libvorbis
    stdenv.cc.cc.lib # Provides libstdc++.so.6
    libkrb5
    keyutils
    # Add other libraries as needed
  ];
};

额外游戏手柄的 udev 规则

在某些特定情况下,游戏手柄可能需要一些额外的配置才能正常工作,这些配置以 udev 规则的形式表示。这可以通过 services.udev.extraRules 来配置。

以下示例适用于 8bitdo Ultimate 蓝牙控制器,不同的控制器需要知道设备的供应商和产品 ID:

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

要查找设备的供应商和产品 ID,usbutils 可能有用。

已知问题

“Project Zomboid”可能会报告“无法确定Java是32位还是64位”。这与Java本身无关,是由其使用自身过时的Java二进制文件解析路径时,其中包含非拉丁字符导致的。请通过在steam-run bash中直接启动本地Java二进制文件来解决错误。

通过 Steam 应用重置密码可能会反复在验证码环节失败,即使验证码界面显示成功,Steam 本身也会提示验证码错误。通过 Steam 网站重置密码应该可以解决这个问题。

参考