diff --git a/nixos/modules/services/hardware/monado.nix b/nixos/modules/services/hardware/monado.nix index 9f9c6c39a0b49..dae6ac4f8bc24 100644 --- a/nixos/modules/services/hardware/monado.nix +++ b/nixos/modules/services/hardware/monado.nix @@ -4,10 +4,8 @@ , ... }: let - inherit (lib) mkDefault mkEnableOption mkIf mkOption mkPackageOption types; - + inherit (lib) mkAliasOptionModule mkDefault mkEnableOption mkIf mkOption mkPackageOption types; cfg = config.services.monado; - in { options.services.monado = { @@ -15,22 +13,20 @@ in package = mkPackageOption pkgs "monado" { }; - defaultRuntime = mkOption { - type = types.bool; - description = '' - Whether to enable Monado as the default OpenXR runtime on the system. + 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 = false; - example = true; - }; + runtime in a writable XDG_CONFIG_DIRS location like `~/.config` + '' // { default = true; }; - highPriority = mkEnableOption "high priority capability for monado-service" - // mkOption { default = true; }; + highPriority = mkEnableOption "high priority capability for monado-service" // mkOption { default = true; }; }; + imports = [ + (mkAliasOptionModule ["services" "monado" "environment"] ["systemd" "user" "services" "monado" "environment"]) + ]; + config = mkIf cfg.enable { security.wrappers."monado-service" = mkIf cfg.highPriority { setuid = false; @@ -41,24 +37,12 @@ in source = lib.getExe' cfg.package "monado-service"; }; - services.udev.packages = with pkgs; [ xr-hardware ]; - systemd.user = { services.monado = { description = "Monado XR runtime service module"; requires = [ "monado.socket" ]; conflicts = [ "monado-dev.service" ]; - unitConfig.ConditionUser = "!root"; - - environment = { - # Default options - # https://gitlab.freedesktop.org/monado/monado/-/blob/4548e1738591d0904f8db4df8ede652ece889a76/src/xrt/targets/service/monado.in.service#L12 - XRT_COMPOSITOR_LOG = mkDefault "debug"; - XRT_PRINT_OPTIONS = mkDefault "on"; - IPC_EXIT_ON_DISCONNECT = mkDefault "off"; - }; - serviceConfig = { ExecStart = if cfg.highPriority @@ -66,35 +50,41 @@ in else lib.getExe' cfg.package "monado-service"; Restart = "no"; }; - restartTriggers = [ cfg.package ]; }; sockets.monado = { description = "Monado XR service module connection socket"; conflicts = [ "monado-dev.service" ]; - unitConfig.ConditionUser = "!root"; - socketConfig = { ListenStream = "%t/monado_comp_ipc"; RemoveOnStop = true; - # If Monado crashes while starting up, we want to close incoming OpenXR connections FlushPending = true; }; - restartTriggers = [ cfg.package ]; - wantedBy = [ "sockets.target" ]; }; }; - environment.systemPackages = [ cfg.package ]; - environment.pathsToLink = [ "/share/openxr" ]; + services = { + monado.environment = { + # Default options + # https://gitlab.freedesktop.org/monado/monado/-/blob/4548e1738591d0904f8db4df8ede652ece889a76/src/xrt/targets/service/monado.in.service#L12 + XRT_COMPOSITOR_LOG = mkDefault "debug"; + XRT_PRINT_OPTIONS = mkDefault "on"; + IPC_EXIT_ON_DISCONNECT = mkDefault "off"; + }; + udev.packages = with pkgs; [ xr-hardware ]; + }; - environment.etc."xdg/openxr/1/active_runtime.json" = mkIf cfg.defaultRuntime { - source = "${cfg.package}/share/openxr/1/openxr_monado.json"; + environment = { + systemPackages = [ cfg.package ]; + pathsToLink = [ "/share/openxr" ]; + etc."xdg/openxr/1/active_runtime.json" = mkIf cfg.defaultRuntime { + source = "${cfg.package}/share/openxr/1/openxr_monado.json"; + }; }; };