-
-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2c45a4
commit 3950c1f
Showing
3 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ]; | ||
} |