Jump to content

VR/zh: Difference between revisions

From NixOS Wiki
Ardenet (talk | contribs)
Created page with "==== 作为 NixOS 内核补丁进行应用 ===="
 
Ardenet (talk | contribs)
Tags: Mobile edit Mobile web edit
 
(35 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<div lang="en" dir="ltr" class="mw-content-ltr">
== Monado ==
== Monado ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
[https://monado.freedesktop.org/ Monado] 是一个开源的 OpenXR 运行时。它使用内置驱动程序支持各种硬件,使其可以运行任何 OpenXR 程序,并且在 OpenComposite 的帮助下,还可以运行大多数 OpenVR 应用程序。
[https://monado.freedesktop.org/ Monado] is an open source OpenXR runtime. It offers support for a variety of hardware using its built-in drivers and can be used to run any OpenXR and, with the help of OpenComposite, most OpenVR applications.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
可以使用其 NixOS 选项 {{Nixos:option|services.monado.enable}} 配置 Monado:
Monado can be configured using its NixOS options {{Nixos:option|services.monado.enable}}:
</div>


{{file|/etc/nixos/configuration.nix|nix|3=services.monado = {
{{file|/etc/nixos/configuration.nix|nix|3=services.monado = {
Line 16: Line 10:
};}}
};}}


<div lang="en" dir="ltr" class="mw-content-ltr">
为了配置 Monado,您可能需要添加其他环境变量:
In order to configure Monado, you might want to add additional environment variables:
</div>


{{file|/etc/nixos/configuration.nix|nix|3=systemd.user.services.monado.environment = {
{{file|/etc/nixos/configuration.nix|nix|3=systemd.user.services.monado.environment = {
Line 25: Line 17:
};}}
};}}


<div lang="en" dir="ltr" class="mw-content-ltr">
配置完成后,Monado 可以在 [[Special:MyLanguage/systemd|systemd]] 用户会话中启动和停止。
Once configured, Monado can be started and stopped in a [[systemd]] user session.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
例如,以下命令将启动 Monado,然后打印其日志输出:
For example, the following commands will start Monado and then follow its log output:
</div>


{{Commands|
{{Commands|
Line 38: Line 26:
}}
}}


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Hand_Tracking"></span>
=== Hand Tracking ===
=== 手部追踪 ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
您可能会注意到,由于缺少手部追踪数据,运行 <code>monado-services</code> 会失败。有两种方法可以解决这个问题:完全禁用手部追踪,或下载手部追踪数据。
You may notice that running <code>monado-services</code> will fail due to the lack of hand tracking data.  There are 2 ways to remedy this, either disable hand tracking altogether, or download the hand tracking data.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
要禁用手部追踪,请修改环境变量以包含 <code>WMR_HANDTRACKING = "0";</code>,使其如下所示。
To disable hand tracking, modify the environment variable to include <code>WMR_HANDTRACKING = "0";</code>, so that it will look like this.
</div>


{{file|/etc/nixos/configuration.nix|nix|3=systemd.user.services.monado.environment = {
{{file|/etc/nixos/configuration.nix|nix|3=systemd.user.services.monado.environment = {
Line 56: Line 39:
};}}
};}}


<div lang="en" dir="ltr" class="mw-content-ltr">
要使手部追踪功能正常工作,您需要启用 <code>git-lfs</code>。启用 <code>git-lfs</code> 的标准方法是通过以下配置
To get hand tracking to work, you require <code>git-lfs</code> to be enabled.  The standard way of enabling <code>git-lfs</code> is through the configuration below
</div>


{{file|/etc/nixos/configuration.nix|nix|3=programs.git = {
{{file|/etc/nixos/configuration.nix|nix|3=programs.git = {
Line 65: Line 46:
};}}
};}}


<div lang="en" dir="ltr" class="mw-content-ltr">
确保 <code>git-lfs</code> 功能启用后,运行以下命令并重新启动 <code>monado-service</code>
After making sure <code>git-lfs</code> is enabled, run these commands and restart <code>monado-service</code>
</div>


{{Commands|
{{Commands|
Line 75: Line 54:
}}
}}


<div lang="en" dir="ltr" class="mw-content-ltr">
有关可用环境变量和调整的更多信息,请参阅 [https://lvra.gitlab.io/docs/fossvr/monado/ Linux VR Adventures wiki] [https://monado.freedesktop.org/getting-started.html#environment-variables Monado 文档关于环境变量的部分]
For further information about available environment variables and tweaks, read the [https://lvra.gitlab.io/docs/fossvr/monado/ Linux VR Adventures wiki] and the [https://monado.freedesktop.org/getting-started.html#environment-variables Monado documentation about environment variables]
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
== OpenComposite ==
== OpenComposite ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
[https://gitlab.com/znixian/OpenOVR OpenComposite] 是一个兼容层,用于在 Monado 等 OpenXR 运行时上运行 OpenVR 应用程序。它与 DXVK vkd3d 等工具类似,但用于将 OpenVR 调用转换为 OpenXR
[https://gitlab.com/znixian/OpenOVR OpenComposite] is a compatibility layer for running OpenVR applications on an OpenXR runtime like Monado. It is comparable to tools like DXVK or vkd3d, but for translating OpenVR calls to OpenXR.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
为了在 SteamVR 以外的任何平台上运行 OpenVR 游戏,您需要配置 <code>~/.config/openvr/openvrpaths.vrpath</code> 中定义的 OpenVR 运行时路径。一个可靠的方法是使用 [[Special:MyLanguage/Home Manager|Home Manager]] 创建此文件。
In order to run OpenVR games on anything other than SteamVR, you need to configure the OpenVR runtime path defined in <code>~/.config/openvr/openvrpaths.vrpath</code>. A reliable way to do this is to use [[Home Manager]] to create this file.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
{{Warning|旧版本的 Proton 将始终查询当前的 OpenVR OpenXR 运行时。如果您使用 OpenComposite,并且它无法初始化 OpenXR 环境,Proton 将无法启动。解决方法是删除 ~/.config/openvr/openvrpaths.vrpath 文件,然后重试启动游戏。}}
{{Warning|Older versions of Proton will always query the current OpenVR and OpenXR runtime. If you use OpenComposite, and it fails to initialize an OpenXR context, Proton will fail to launch. A workaround is to delete the ~/.config/openvr/openvrpaths.vrpath file and then retry launching the game.}}
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
如果此文件未设置为只读,SteamVR 将添加其运行时路径,因此可以使用 Home Manager
If this file is not set to read-only, SteamVR will add its runtime path back, hence the use for Home Manager.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
启用 OpenComposite 的示例配置可能如下所示:
An example configuration for enabling OpenComposite may look like this:
</div>


{{file|~/.config/home-manager/home.nix|nix|3=# For Monado:
{{file|~/.config/home-manager/home.nix|nix|3=# For Monado:
Line 130: Line 94:
'';}}
'';}}


<div lang="en" dir="ltr" class="mw-content-ltr">
如果您计划在 Steam 上玩任何 OpenVR 游戏或通过 Proton 游玩 OpenXR 游戏,则必须以这种方式使用 OpenComposite。在大多数情况下,您还必须允许 Steam 运行时访问您的 OpenXR 运行时的 Socket 路径,方法是使用以下 Steam XR 应用程序的启动选项:<code>env PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/monado_comp_ipc %command%</code>。此示例适用于 Monado,其他 XR 运行时可能有所不同。
If you are planning to play any OpenVR game on Steam or OpenXR games through Proton, you will have to use OpenComposite in this manner. In most cases you also have to allow access to the socket path of your OpenXR runtime to Steam's runtime, by using the following launch options for XR applications on Steam: <code>env PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/monado_comp_ipc %command%</code>. This example is for Monado, while other XR runtimes might differ.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
== WiVRn ==
== WiVRn ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
WiVRn 是一款基于 Monado 构建的 OpenXR 流媒体应用程序。它能够将独立的 VR 头戴设备无线连接到 Linux 计算机。如果您的头戴设备不是无线的,请查阅 [[Special:MyLanguage/VR#Monado|Monado]]
WiVRn is an OpenXR streaming application built around Monado. It wirelessly connects a standalone VR headset to a Linux computer. If your headset is not wireless, look at [[VR#Monado|Monado]] instead.
WiVRn 模块的示例用法:
Example usage of the WiVRn module:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
{{Warning|WiVRn 0.23 版本开始,WiVRn 会自行管理 opencomposite 路径。仅在使用低于 v0.23 的版本时使用上述 opencomposite 配置。}}
{{Warning|As of WiVRn version 0.23, WiVRn now manages the opencomposite paths itself. Only use the above opencomposite configuration when using versions below v0.23.}}
</div>


{{File|/etc/nixos/configuration.nix|nix|3=services.wivrn = {
{{File|/etc/nixos/configuration.nix|nix|3=services.wivrn = {
Line 182: Line 138:
};}}
};}}


<div lang="en" dir="ltr" class="mw-content-ltr">
Monado 一样,您还须添加 WiVRn 的启动参数以允许访问 Socket:<code>PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/wivrn/comp_ipc %command%</code>
Like Monado, you will also have to add the launch argument for WiVRn to allow access to the socket: <code>PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/wivrn/comp_ipc %command%</code>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
== Envision ==
== Envision ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
Envision 是用于 FOSS VR 程序栈的编排器(Orchestrator)。它负责构建和配置 Monado、WiVRn、OpenComposite 以及 FOSS VR 程序栈的其他实用程序,例如 Lighthouse 驱动程序、OpenHMD、Survive 和 WMR。您可以使用 Envision 模块启用它:
Envision is an orchestrator for the FOSS VR stack. It handles the building and configuration of Monado, WiVRn, OpenComposite, and other utilities of the FOSS VR stack such as the Lighthouse driver, OpenHMD, Survive, and WMR. You can enable it with the Envision module:
</div>


{{File|/etc/nixos/configuration.nix|nix|3=programs.envision = {
{{File|/etc/nixos/configuration.nix|nix|3=programs.envision = {
Line 199: Line 149:
};}}
};}}


<div lang="en" dir="ltr" class="mw-content-ltr">
== SteamVR ==
== SteamVR ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
[https://store.steampowered.com/app/250820/SteamVR/ SteamVR] 是一个专有的 OpenVR 运行时,兼容 OpenXR。它是 [[Special:MyLanguage/Steam|Steam]] 的一部分,除了启用 Steam 之外,在 NixOS 上无需进行任何其他设置。
[https://store.steampowered.com/app/250820/SteamVR/ SteamVR] is a proprietary OpenVR runtime with compatibility for OpenXR. It is part of [[Steam]] and doesn't need any additional setup on NixOS apart from enabling Steam.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
通过 Steam 安装 SteamVR 并插入兼容 SteamVR 的耳机后,SteamVR 应该就可以正常工作。
After installing SteamVR through Steam and plugging in a SteamVR-compatible headset, SteamVR should work for the most part.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
在初始设置时,SteamVR 会请求提升权限,以便为其某个二进制文件设置文件能力(file capability)。这是使异步再投影技术正常工作所必需的。客户端需要拥有 <code>CAP_SYS_NICE</code> 授权来获取高优先级环境,这是异步再投影技术的必要条件。
On initial setup, SteamVR will ask for elevated permissions, to set up a file capability for one of its binaries. This is needed to allow asynchronous reprojection to work. Clients need the <code>CAP_SYS_NICE</code> capability to acquire a high-priority context, which is a requirement for asynchronous reprojection.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
{{Note|Steam 在基于 bubblewrap FHS 环境中运行。此环境在用户命名空间中运行 Steam,这阻止它使用任何能力(capabilities)或为二进制文件 setuid。这意味着除非修补内核以完全消除这些限制或修改用于运行 Steam 的 bubblewrap 二进制文件以消除这些功能保护,否则异步再投影技术无法在 NixOS 上使用。这两种解决方法都有各自的安全隐患。请参阅此 [https://github.com/NixOS/nixpkgs/issues/217119 Nixpkgs 问题]}}
{{Note|Steam is run in a bubblewrap-based FHS environment. This environment runs Steam in a user namespace, which prevents it from using any capabilities or setuid binaries. This means that asynchronous reprojection can not be used on NixOS, without patching the kernel to remove these restrictions completely. See this [https://github.com/NixOS/nixpkgs/issues/217119 Nixpkgs issue]}}
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Patching_AMDGPU_to_allow_high_priority_queues"></span>
=== Patching AMDGPU to allow high priority queues ===
=== 修补 AMDGPU 以允许高优先级队列 ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
通过应用 [https://github.com/Frogging-Family/community-patches/blob/a6a468420c0df18d51342ac6864ecd3f99f7011e/linux61-tkg/cap_sys_nice_begone.mypatch 此补丁],AMDGPU 内核驱动程序将忽略进程权限并允许任何应用程序创建高优先级环境(high priority contexts)。
By applying [https://github.com/Frogging-Family/community-patches/blob/a6a468420c0df18d51342ac6864ecd3f99f7011e/linux61-tkg/cap_sys_nice_begone.mypatch this patch], the AMDGPU kernel driver will ignore process privileges and allow any application to create high priority contexts.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
{{Warning|这将移除内核中特意设置的限制,并可能导致调度问题。虽然目前尚未收到导致问题的报告,但这应被视为不受支持的配置。}}
{{Warning|This removes intentional restrictions from the kernel, and it could cause scheduling issues. While it has not been reported that it does cause issues, this should be considered an unsupported configuration.}}
</div>


<span id="Applying_as_a_NixOS_kernel_patch"></span>
<span id="Applying_as_a_NixOS_kernel_patch"></span>
==== 作为 NixOS 内核补丁进行应用 ====
==== 作为 NixOS 内核补丁进行应用 ====


<div lang="en" dir="ltr" class="mw-content-ltr">
为了解决 <code>CAP_SYS_NICE</code> 要求,我们可以使用以下 NixOS 配置片段应用内核补丁:
To workaround the <code>CAP_SYS_NICE</code> requirement, we can apply a kernel patch using the following NixOS configuration snippet:
</div>


{{file|/etc/nixos/configuration.nix|nix|3=boot.kernelPatches = [
{{file|/etc/nixos/configuration.nix|nix|3=boot.kernelPatches = [
Line 250: Line 183:
}}
}}


<div lang="en" dir="ltr" class="mw-content-ltr">
也可以只修补 amdgpu 并将其构建为树外模块(out-of-tree module),如 [[Special:MyLanguage/Linux_kernel#Patching_a_single_In-tree_kernel_module|Pacthing a single In-tree Kernel Module]] 中所述
It is also possible to just patch amdgpu and build it as an out-of-tree module, as described in [[Linux_kernel#Patching_a_single_In-tree_kernel_module]]
 
</div>
<span id="Patching_bubblewrap_to_allow_capabilities"></span>
=== 修补 bubblewrap 以允许启用能力(capabilities) ===
 
通过修改用于运行 Steam 的 bubblewrap 二进制文件,您可以允许该 FHS 环境中的进程获取能力。这样就无需直接修补内核了。
 
{{Warning|这绕过了 bubblewrap 中预设的安全机制,并允许所有其他由 steam 启动或通过 steam-run 运行的软件也获得这些能力。}}
 
{{file|/etc/nixos/configuration.nix|nix|3=programs.steam = let
  patchedBwrap = pkgs.bubblewrap.overrideAttrs (o: {
    patches = (o.patches or []) ++ [
      ./bwrap.patch
    ];
  });
in {
  enable = true;
  package = pkgs.steam.override {
    buildFHSEnv = (args: ((pkgs.buildFHSEnv.override {
      bubblewrap = patchedBwrap;
    }) (args // {
      extraBwrapArgs = (args.extraBwrapArgs or []) ++ [ "--cap-add ALL" ];
    })));
  };
};
}}
{{file|/etc/nixos/bwrap.patch|diff|3=diff --git a/bubblewrap.c b/bubblewrap.c
index 8322ea0..4e20262 100644
--- a/bubblewrap.c
+++ b/bubblewrap.c
@@ -868,13 +868,6 @@ acquire_privs (void)
      /* Keep only the required capabilities for setup */
      set_required_caps ();
    }
-  else if (real_uid != 0 && has_caps ())
-    {
-      /* We have some capabilities in the non-setuid case, which should not happen.
-         Probably caused by the binary being setcap instead of setuid which we
-         don't support anymore */
-      die ("Unexpected capabilities but not setuid, old file caps config?");
-   }
  else if (real_uid == 0)
    {
      /* If our uid is 0, default to inheriting all caps; the caller
}}
 
作为额外的更改,您可能还需要用指向修改后的 bwrap 二进制文件的符号链接替换 ​​Steam 自己的 bwrap 二进制文件,该链接位于 <code>~/.local/share/Steam/ubuntu12_32/steam-runtime/usr/libexec/steam-runtime-tools-0/srt-bwrap</code>
 
当 steam-runtime 更新时,Steam 会定期用自己的二进制文件替换此修改,因此您可能需要在功能异常时,重新应用此修改。


== wlx-overlay-s ==
== wlx-overlay-s ==


<div lang="en" dir="ltr" class="mw-content-ltr">
[https://github.com/galister/wlx-overlay-s wlx-overlay-s] 是一个轻量级的 OpenXR/OpenVR 覆盖层,适用于 Wayland X11 桌面。它原生兼容 SteamVR 以及 Monado/WiVRn
[https://github.com/galister/wlx-overlay-s wlx-overlay-s] is a lightweight OpenXR/OpenVR overlay for Wayland and X11 desktops. It works with SteamVR as well as Monado/WiVRn natively.
</div>


<span id="SteamVR_autostart"></span>
<span id="SteamVR_autostart"></span>
==== SteamVR 自动启动 ====
==== SteamVR 自动启动 ====


<div lang="en" dir="ltr" class="mw-content-ltr">
在 SteamVR(或任何 OpenVR 合成器)中启动 wlx-overlay-s 时,它会注册一个自动启动清单。目前,此清单将引用 wlx-overlay-s 的 Nix 存储路径,该路径可能会在重建 NixOS/Nix 配置文件后被垃圾回收。一种解决方法是定期运行以下命令来更新清单的存储路径:
When launching wlx-overlay-s in SteamVR (or any OpenVR compositor) it will register an autostart manifest. Currently, this manifest will reference a Nix store path of wlx-overlay-s, which might get garbage collected after rebuilds of your NixOS/Nix profile. A workaround is to regularly run the following command to update the manifest's store path:{{Commands|
 
# Run wlx-overlay-s and replace any running instance
{{Commands|
# 运行 wlx-overlay-s 并替换任何正在运行的实例
$ wlx-overlay-s --replace}}
$ wlx-overlay-s --replace}}
</div>


<span id="See_also"></span>
<span id="See_also"></span>
== 另见 ==
== 另见 ==


<div lang="en" dir="ltr" class="mw-content-ltr">
* [https://lvra.gitlab.io Linux VR Adventures Wiki]
* [https://lvra.gitlab.io Linux VR Adventures Wiki]
[[Category:Video]]
 
[[Category:Hardware]]
[[Category:Video/zh|分类:视频]]
[[Category:Desktop]]
[[Category:Hardware/zh|分类:硬件]]
[[Category:Gaming]]
[[Category:Desktop/zh|分类:桌面]]
</div>
[[Category:Gaming/zh|分类:游戏]]

Latest revision as of 14:44, 10 October 2025

Monado

Monado 是一个开源的 OpenXR 运行时。它使用内置驱动程序支持各种硬件,使其可以运行任何 OpenXR 程序,并且在 OpenComposite 的帮助下,还可以运行大多数 OpenVR 应用程序。

可以使用其 NixOS 选项 services.monado.enable 配置 Monado:

❄︎ /etc/nixos/configuration.nix
services.monado = {
  enable = true;
  defaultRuntime = true; # Register as default OpenXR runtime
};

为了配置 Monado,您可能需要添加其他环境变量:

❄︎ /etc/nixos/configuration.nix
systemd.user.services.monado.environment = {
  STEAMVR_LH_ENABLE = "1";
  XRT_COMPOSITOR_COMPUTE = "1";
};

配置完成后,Monado 可以在 systemd 用户会话中启动和停止。

例如,以下命令将启动 Monado,然后打印其日志输出:

$ systemctl --user start monado.service
$ journalctl --user --follow --unit monado.service

手部追踪

您可能会注意到,由于缺少手部追踪数据,运行 monado-services 会失败。有两种方法可以解决这个问题:完全禁用手部追踪,或下载手部追踪数据。

要禁用手部追踪,请修改环境变量以包含 WMR_HANDTRACKING = "0";,使其如下所示。

❄︎ /etc/nixos/configuration.nix
systemd.user.services.monado.environment = {
  STEAMVR_LH_ENABLE = "1";
  XRT_COMPOSITOR_COMPUTE = "1";
  WMR_HANDTRACKING = "0";
};

要使手部追踪功能正常工作,您需要启用 git-lfs。启用 git-lfs 的标准方法是通过以下配置

❄︎ /etc/nixos/configuration.nix
programs.git = {
  enable = true;
  lfs.enable = true;
};

确保 git-lfs 功能启用后,运行以下命令并重新启动 monado-service

$ mkdir -p ~/.local/share/monado
$ cd ~/.local/share/monado
$ git clone https://gitlab.freedesktop.org/monado/utilities/hand-tracking-models

有关可用环境变量和调整的更多信息,请参阅 Linux VR Adventures wikiMonado 文档关于环境变量的部分

OpenComposite

OpenComposite 是一个兼容层,用于在 Monado 等 OpenXR 运行时上运行 OpenVR 应用程序。它与 DXVK 或 vkd3d 等工具类似,但用于将 OpenVR 调用转换为 OpenXR。

为了在 SteamVR 以外的任何平台上运行 OpenVR 游戏,您需要配置 ~/.config/openvr/openvrpaths.vrpath 中定义的 OpenVR 运行时路径。一个可靠的方法是使用 Home Manager 创建此文件。

⚠︎
Warning: 旧版本的 Proton 将始终查询当前的 OpenVR 和 OpenXR 运行时。如果您使用 OpenComposite,并且它无法初始化 OpenXR 环境,Proton 将无法启动。解决方法是删除 ~/.config/openvr/openvrpaths.vrpath 文件,然后重试启动游戏。

如果此文件未设置为只读,SteamVR 将添加其运行时路径,因此可以使用 Home Manager。

启用 OpenComposite 的示例配置可能如下所示:

❄︎ ~/.config/home-manager/home.nix
# For Monado:
xdg.configFile."openxr/1/active_runtime.json".source = "${pkgs.monado}/share/openxr/1/openxr_monado.json";

# For WiVRn v0.22 and below:
xdg.configFile."openxr/1/active_runtime.json".source = "${pkgs.wivrn}/share/openxr/1/openxr_wivrn.json";

xdg.configFile."openvr/openvrpaths.vrpath".text = ''
  {
    "config" :
    [
      "${config.xdg.dataHome}/Steam/config"
    ],
    "external_drivers" : null,
    "jsonid" : "vrpathreg",
    "log" :
    [
      "${config.xdg.dataHome}/Steam/logs"
    ],
    "runtime" :
    [
      "${pkgs.opencomposite}/lib/opencomposite"
    ],
    "version" : 1
  }
'';

如果您计划在 Steam 上玩任何 OpenVR 游戏或通过 Proton 游玩 OpenXR 游戏,则必须以这种方式使用 OpenComposite。在大多数情况下,您还必须允许 Steam 运行时访问您的 OpenXR 运行时的 Socket 路径,方法是使用以下 Steam 上 XR 应用程序的启动选项:env PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/monado_comp_ipc %command%。此示例适用于 Monado,其他 XR 运行时可能有所不同。

WiVRn

WiVRn 是一款基于 Monado 构建的 OpenXR 流媒体应用程序。它能够将独立的 VR 头戴设备无线连接到 Linux 计算机。如果您的头戴设备不是无线的,请查阅 Monado。 WiVRn 模块的示例用法:

⚠︎
Warning: 从 WiVRn 0.23 版本开始,WiVRn 会自行管理 opencomposite 路径。仅在使用低于 v0.23 的版本时使用上述 opencomposite 配置。
❄︎ /etc/nixos/configuration.nix
services.wivrn = {
  enable = true;
  openFirewall = true;

  # Write information to /etc/xdg/openxr/1/active_runtime.json, VR applications
  # will automatically read this and work with WiVRn (Note: This does not currently
  # apply for games run in Valve's Proton)
    defaultRuntime = true;

  # Run WiVRn as a systemd service on startup
  autoStart = true;

  # Config for WiVRn (https://github.com/WiVRn/WiVRn/blob/master/docs/configuration.md)
  config = {
    enable = true;
    json = {
      # 1.0x foveation scaling
      scale = 1.0;
      # 100 Mb/s
      bitrate = 100000000;
      encoders = [
        {
          encoder = "vaapi";
          codec = "h265";
          # 1.0 x 1.0 scaling
          width = 1.0;
          height = 1.0;
          offset_x = 0.0;
          offset_y = 0.0;
        }
      ];
    };
  };
};

与 Monado 一样,您还须添加 WiVRn 的启动参数以允许访问 Socket:PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/wivrn/comp_ipc %command%

Envision

Envision 是用于 FOSS VR 程序栈的编排器(Orchestrator)。它负责构建和配置 Monado、WiVRn、OpenComposite 以及 FOSS VR 程序栈的其他实用程序,例如 Lighthouse 驱动程序、OpenHMD、Survive 和 WMR。您可以使用 Envision 模块启用它:

❄︎ /etc/nixos/configuration.nix
programs.envision = {
  enable = true;
  openFirewall = true; # This is set true by default
};

SteamVR

SteamVR 是一个专有的 OpenVR 运行时,兼容 OpenXR。它是 Steam 的一部分,除了启用 Steam 之外,在 NixOS 上无需进行任何其他设置。

通过 Steam 安装 SteamVR 并插入兼容 SteamVR 的耳机后,SteamVR 应该就可以正常工作。

在初始设置时,SteamVR 会请求提升权限,以便为其某个二进制文件设置文件能力(file capability)。这是使异步再投影技术正常工作所必需的。客户端需要拥有 CAP_SYS_NICE 授权来获取高优先级环境,这是异步再投影技术的必要条件。

Note: Steam 在基于 bubblewrap 的 FHS 环境中运行。此环境在用户命名空间中运行 Steam,这阻止它使用任何能力(capabilities)或为二进制文件 setuid。这意味着除非修补内核以完全消除这些限制或修改用于运行 Steam 的 bubblewrap 二进制文件以消除这些功能保护,否则异步再投影技术无法在 NixOS 上使用。这两种解决方法都有各自的安全隐患。请参阅此 Nixpkgs 问题

修补 AMDGPU 以允许高优先级队列

通过应用 此补丁,AMDGPU 内核驱动程序将忽略进程权限并允许任何应用程序创建高优先级环境(high priority contexts)。

⚠︎
Warning: 这将移除内核中特意设置的限制,并可能导致调度问题。虽然目前尚未收到导致问题的报告,但这应被视为不受支持的配置。

作为 NixOS 内核补丁进行应用

为了解决 CAP_SYS_NICE 要求,我们可以使用以下 NixOS 配置片段应用内核补丁:

❄︎ /etc/nixos/configuration.nix
boot.kernelPatches = [
  {
    name = "amdgpu-ignore-ctx-privileges";
    patch = pkgs.fetchpatch {
      name = "cap_sys_nice_begone.patch";
      url = "https://github.com/Frogging-Family/community-patches/raw/master/linux61-tkg/cap_sys_nice_begone.mypatch";
      hash = "sha256-Y3a0+x2xvHsfLax/uwycdJf3xLxvVfkfDVqjkxNaYEo=";
    };
  }
];

也可以只修补 amdgpu 并将其构建为树外模块(out-of-tree module),如 Pacthing a single In-tree Kernel Module 中所述

修补 bubblewrap 以允许启用能力(capabilities)

通过修改用于运行 Steam 的 bubblewrap 二进制文件,您可以允许该 FHS 环境中的进程获取能力。这样就无需直接修补内核了。

⚠︎
Warning: 这绕过了 bubblewrap 中预设的安全机制,并允许所有其他由 steam 启动或通过 steam-run 运行的软件也获得这些能力。
❄︎ /etc/nixos/configuration.nix
programs.steam = let
  patchedBwrap = pkgs.bubblewrap.overrideAttrs (o: {
    patches = (o.patches or []) ++ [
      ./bwrap.patch
    ];
  });
in {
  enable = true;
  package = pkgs.steam.override {
    buildFHSEnv = (args: ((pkgs.buildFHSEnv.override {
      bubblewrap = patchedBwrap;
    }) (args // {
      extraBwrapArgs = (args.extraBwrapArgs or []) ++ [ "--cap-add ALL" ];
    })));
  };
};
≡︎ /etc/nixos/bwrap.patch
diff --git a/bubblewrap.c b/bubblewrap.c
index 8322ea0..4e20262 100644
--- a/bubblewrap.c
+++ b/bubblewrap.c
@@ -868,13 +868,6 @@ acquire_privs (void)
       /* Keep only the required capabilities for setup */
       set_required_caps ();
     }
-  else if (real_uid != 0 && has_caps ())
-    {
-      /* We have some capabilities in the non-setuid case, which should not happen.
-         Probably caused by the binary being setcap instead of setuid which we
-         don't support anymore */
-      die ("Unexpected capabilities but not setuid, old file caps config?");
-    }
   else if (real_uid == 0)
     {
       /* If our uid is 0, default to inheriting all caps; the caller

作为额外的更改,您可能还需要用指向修改后的 bwrap 二进制文件的符号链接替换 ​​Steam 自己的 bwrap 二进制文件,该链接位于 ~/.local/share/Steam/ubuntu12_32/steam-runtime/usr/libexec/steam-runtime-tools-0/srt-bwrap

当 steam-runtime 更新时,Steam 会定期用自己的二进制文件替换此修改,因此您可能需要在功能异常时,重新应用此修改。

wlx-overlay-s

wlx-overlay-s 是一个轻量级的 OpenXR/OpenVR 覆盖层,适用于 Wayland 和 X11 桌面。它原生兼容 SteamVR 以及 Monado/WiVRn。

SteamVR 自动启动

在 SteamVR(或任何 OpenVR 合成器)中启动 wlx-overlay-s 时,它会注册一个自动启动清单。目前,此清单将引用 wlx-overlay-s 的 Nix 存储路径,该路径可能会在重建 NixOS/Nix 配置文件后被垃圾回收。一种解决方法是定期运行以下命令来更新清单的存储路径:

# 运行 wlx-overlay-s 并替换任何正在运行的实例
$ wlx-overlay-s --replace

另见