diff --git a/nixos/modules/services/hardware/monado.nix b/nixos/modules/services/hardware/monado.nix index f7fdf421ac17..137b63c77420 100644 --- a/nixos/modules/services/hardware/monado.nix +++ b/nixos/modules/services/hardware/monado.nix @@ -16,6 +16,7 @@ let cfg = config.services.monado; + runtimeManifest = "${cfg.package}/share/openxr/1/openxr_monado.json"; in { options.services.monado = { @@ -35,6 +36,19 @@ in example = true; }; + forceDefaultRuntime = mkOption { + type = types.bool; + description = '' + Whether to ensure that Monado is the active runtime set for the current + user. + + This replaces the file `XDG_CONFIG_HOME/openxr/1/active_runtime.json` + when starting the service. + ''; + default = false; + example = true; + }; + highPriority = mkEnableOption "high priority capability for monado-service" // mkOption { default = true; }; @@ -68,6 +82,16 @@ in IPC_EXIT_ON_DISCONNECT = mkDefault "off"; }; + preStart = mkIf cfg.forceDefaultRuntime '' + XDG_CONFIG_HOME="''${XDG_CONFIG_HOME:-$HOME/.config}" + targetDir="$XDG_CONFIG_HOME/openxr/1" + activeRuntimePath="$targetDir/active_runtime.json" + + echo "Note: Replacing active runtime at '$activeRuntimePath'" + mkdir --parents "$targetDir" + ln --symbolic --force ${runtimeManifest} "$activeRuntimePath" + ''; + serviceConfig = { ExecStart = if cfg.highPriority then @@ -106,7 +130,7 @@ in hardware.graphics.extraPackages = [ pkgs.monado-vulkan-layers ]; environment.etc."xdg/openxr/1/active_runtime.json" = mkIf cfg.defaultRuntime { - source = "${cfg.package}/share/openxr/1/openxr_monado.json"; + source = runtimeManifest; }; }; diff --git a/nixos/tests/monado.nix b/nixos/tests/monado.nix index 2fb94468a2bb..9b7e636d1f66 100644 --- a/nixos/tests/monado.nix +++ b/nixos/tests/monado.nix @@ -1,5 +1,5 @@ import ./make-test-python.nix ( - { pkgs, ... }: + { ... }: { name = "monado"; @@ -16,6 +16,8 @@ import ./make-test-python.nix ( services.monado = { enable = true; defaultRuntime = true; + + forceDefaultRuntime = true; }; # Stop Monado from probing for any hardware systemd.user.services.monado.environment.SIMULATED_ENABLE = "1"; @@ -30,6 +32,9 @@ import ./make-test-python.nix ( runtimePath = "/run/user/${userId}"; in '' + # for defaultRuntime + machine.succeed("stat /etc/xdg/openxr/1/active_runtime.json") + machine.succeed("loginctl enable-linger alice") machine.wait_for_unit("user@${userId}.service") @@ -37,6 +42,9 @@ import ./make-test-python.nix ( machine.systemctl("start monado.service", "alice") machine.wait_for_unit("monado.service", "alice") + # for forceDefaultRuntime + machine.succeed("stat /home/alice/.config/openxr/1/active_runtime.json") + machine.succeed("su -- alice -c env XDG_RUNTIME_DIR=${runtimePath} openxr_runtime_list") ''; }