Steam
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
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.packages 或 environment.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'; [
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
];
};
修復 GNOME Dock 欄和活動概覽中遊戲圖標缺失的問題
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/.
對於通過 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 無法啟動。我該怎麼辦?
在終端運行 strace steam -dev -console 2> steam.logs 命令。如果未安裝 strace ,請使用 nix-shell -p strace 或 nix run nixpkgs#strace -- steam -dev -console 2> steam.logs (如果使用 Flakes 版本)臨時安裝。之後,請提交錯誤報告。
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.
遊戲無法啟動
遊戲可能無法啟動,原因可能是缺少依賴項(目前應將此添加到腳本中),或者無法進行補丁更新。直接啟動遊戲的步驟如下: 如果可以,請修補腳本/二進制文件。
- 在二進制文件夾中添加一個名為 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 的驅動程序
有時,更換 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 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.