Skip to content

Commit

Permalink
nixos/wivrn: init module
Browse files Browse the repository at this point in the history
  • Loading branch information
PassiveLemon committed Mar 16, 2024
1 parent e2c45a4 commit 3950c1f
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nixos/doc/manual/release-notes/rl-2405.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m

- [TuxClocker](https://github.com/Lurkki14/tuxclocker), a hardware control and monitoring program. Available as [programs.tuxclocker](#opt-programs.tuxclocker.enable).

- [ALVR](https://github.com/alvr-org/alvr), a VR desktop streamer. Available as [programs.alvr](#opt-programs.alvr.enable)
- [ALVR](https://github.com/alvr-org/alvr), a VR desktop streamer. Available as [programs.alvr](#opt-programs.alvr.enable).

- [WiVRn](https://github.com/Meumeu/WiVRn), an OpenXR streaming application. Available as [services.wivrn](#opt-services.wivrn.enable).

- [RustDesk](https://rustdesk.com), a full-featured open source remote control alternative for self-hosting and security with minimal configuration. Alternative to TeamViewer.

Expand Down
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,7 @@
./services/video/mediamtx.nix
./services/video/unifi-video.nix
./services/video/v4l2-relayd.nix
./services/video/wivrn.nix
./services/wayland/cage.nix
./services/web-apps/akkoma.nix
./services/web-apps/alps.nix
Expand Down
105 changes: 105 additions & 0 deletions nixos/modules/services/video/wivrn.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{ config, pkgs, lib, ... }:

let
cfg = config.services.wivrn;
inherit (lib) mkIf mkEnableOption mkPackageOption mkOption mkDefault mdDoc types getExe' maintainers;
in
{
options = {
services.wivrn = {
enable = mkEnableOption "WiVRn, an OpenXR streaming application";

package = mkPackageOption pkgs "wivrn" { };

openFirewall = mkEnableOption "the default ports in the firewall for the WiVRn server";

defaultRuntime = mkEnableOption ''
WiVRn Monado as the default OpenXR runtime on the system. The config can be found at `/etc/xdg/openxr/1/active_runtime.json`.
Note that applications can bypass this option by setting an active
runtime in a writable XDG_CONFIG_DIRS location like `~/.config`
'' // { default = true; };

highPriority = mkEnableOption "high priority capability for wivrn-server" // { default = true; };

monadoEnvironment = mkOption {
type = types.attrsOf types.str;
description = mdDoc "Environment variables passed to Monado.";
# Default options
# https://gitlab.freedesktop.org/monado/monado/-/blob/4548e1738591d0904f8db4df8ede652ece889a76/src/xrt/targets/service/monado.in.service#L12
default = {
XRT_COMPOSITOR_LOG = "debug";
XRT_PRINT_OPTIONS = "on";
IPC_EXIT_ON_DISCONNECT = "off";
};
};
};
};

config = mkIf cfg.enable {
security.wrappers."wivrn-server" = mkIf cfg.highPriority {
setuid = false;
owner = "root";
group = "root";
# cap_sys_nice needed for asynchronous reprojection
capabilities = "cap_sys_nice+eip";
source = getExe' cfg.package "wivrn-server";
};

systemd.user = {
services.wivrn = {
description = "WiVRn XR runtime service module";
requires = [ "wivrn.socket" ];
unitConfig.ConditionUser = "!root";
environment = cfg.monadoEnvironment;
serviceConfig = {
ExecStart =
if cfg.highPriority
then "${config.security.wrapperDir}/wivrn-server"
else getExe' cfg.package "wivrn-server";
Restart = "no";
};
restartTriggers = [ cfg.package ];
wantedBy = [ "sockets.target" ];
};

sockets.wivrn = {
description = "WiVRn XR service module connection socket";
unitConfig.ConditionUser = "!root";
socketConfig = {
ListenStream = "%t/wivrn_comp_ipc";
RemoveOnStop = true;
# If WiVRn crashes while starting up, we want to close incoming OpenXR connections
FlushPending = true;
};
restartTriggers = [ cfg.package ];
wantedBy = [ "sockets.target" ];
};
};

services = {
udev.packages = with pkgs; [ xr-hardware ];
avahi = {
enable = true;
publish = {
enable = true;
userServices = true;
};
};
};

networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [ 9757 ];
allowedUDPPorts = [ 9757 ];
};

environment = {
systemPackages = [ cfg.package ];
pathsToLink = [ "/share/openxr" ];
etc."xdg/openxr/1/active_runtime.json" = mkIf cfg.defaultRuntime {
source = "${cfg.package}/share/openxr/1/openxr_wivrn.json";
};
};
};
meta.maintainers = with maintainers; [ passivelemon ];
}

0 comments on commit 3950c1f

Please sign in to comment.