17 cfg = config.services.monado;
19 runtimeManifest = "${cfg.package}/share/openxr/1/openxr_monado.json";
22 options.services.monado = {
23 enable = mkEnableOption "Monado user service";
25 package = mkPackageOption pkgs "monado" { };
27 defaultRuntime = mkOption {
30 Whether to enable Monado as the default OpenXR runtime on the system.
32 Note that applications can bypass this option by setting an active
33 runtime in a writable XDG_CONFIG_DIRS location like `~/.config`.
39 forceDefaultRuntime = mkOption {
42 Whether to ensure that Monado is the active runtime set for the current
45 This replaces the file `XDG_CONFIG_HOME/openxr/1/active_runtime.json`
46 when starting the service.
53 mkEnableOption "high priority capability for monado-service"
54 // mkOption { default = true; };
57 config = mkIf cfg.enable {
58 security.wrappers."monado-service" = mkIf cfg.highPriority {
62 # cap_sys_nice needed for asynchronous reprojection
63 capabilities = "cap_sys_nice+eip";
64 source = lib.getExe' cfg.package "monado-service";
67 services.udev.packages = with pkgs; [ xr-hardware ];
71 description = "Monado XR runtime service module";
72 requires = [ "monado.socket" ];
73 conflicts = [ "monado-dev.service" ];
75 unitConfig.ConditionUser = "!root";
79 # https://gitlab.freedesktop.org/monado/monado/-/blob/4548e1738591d0904f8db4df8ede652ece889a76/src/xrt/targets/service/monado.in.service#L12
80 XRT_COMPOSITOR_LOG = mkDefault "debug";
81 XRT_PRINT_OPTIONS = mkDefault "on";
82 IPC_EXIT_ON_DISCONNECT = mkDefault "off";
85 preStart = mkIf cfg.forceDefaultRuntime ''
86 XDG_CONFIG_HOME="''${XDG_CONFIG_HOME:-$HOME/.config}"
87 targetDir="$XDG_CONFIG_HOME/openxr/1"
88 activeRuntimePath="$targetDir/active_runtime.json"
90 echo "Note: Replacing active runtime at '$activeRuntimePath'"
91 mkdir --parents "$targetDir"
92 ln --symbolic --force ${runtimeManifest} "$activeRuntimePath"
97 if cfg.highPriority then
98 "${config.security.wrapperDir}/monado-service"
100 lib.getExe' cfg.package "monado-service";
104 restartTriggers = [ cfg.package ];
108 description = "Monado XR service module connection socket";
109 conflicts = [ "monado-dev.service" ];
111 unitConfig.ConditionUser = "!root";
114 ListenStream = "%t/monado_comp_ipc";
117 # If Monado crashes while starting up, we want to close incoming OpenXR connections
121 restartTriggers = [ cfg.package ];
123 wantedBy = [ "sockets.target" ];
127 environment.systemPackages = [ cfg.package ];
128 environment.pathsToLink = [ "/share/openxr" ];
130 hardware.graphics.extraPackages = [ pkgs.monado-vulkan-layers ];
132 environment.etc."xdg/openxr/1/active_runtime.json" = mkIf cfg.defaultRuntime {
133 source = runtimeManifest;
137 meta.maintainers = with lib.maintainers; [ Scrumplex ];