nixos/monado: add forceDefaultRuntime option (#348815)

This commit is contained in:
Sefa Eyeoglu 2024-11-24 13:26:39 +01:00 committed by GitHub
commit 2636739e7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 68 additions and 32 deletions

View File

@ -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;
};
};

View File

@ -1,39 +1,51 @@
import ./make-test-python.nix ({ pkgs, ... }: {
name = "monado";
import ./make-test-python.nix (
{ ... }:
{
name = "monado";
nodes.machine =
{ pkgs, ... }:
nodes.machine =
{ pkgs, ... }:
{
hardware.graphics.enable = true;
users.users.alice = {
isNormalUser = true;
uid = 1000;
{
hardware.graphics.enable = true;
users.users.alice = {
isNormalUser = true;
uid = 1000;
};
services.monado = {
enable = true;
defaultRuntime = true;
forceDefaultRuntime = true;
};
# Stop Monado from probing for any hardware
systemd.user.services.monado.environment.SIMULATED_ENABLE = "1";
environment.systemPackages = with pkgs; [ openxr-loader ];
};
services.monado = {
enable = true;
defaultRuntime = true;
};
# Stop Monado from probing for any hardware
systemd.user.services.monado.environment.SIMULATED_ENABLE = "1";
testScript =
{ nodes, ... }:
let
userId = toString nodes.machine.users.users.alice.uid;
runtimePath = "/run/user/${userId}";
in
''
# for defaultRuntime
machine.succeed("stat /etc/xdg/openxr/1/active_runtime.json")
environment.systemPackages = with pkgs; [ openxr-loader ];
};
machine.succeed("loginctl enable-linger alice")
machine.wait_for_unit("user@${userId}.service")
testScript = { nodes, ... }:
let
userId = toString nodes.machine.users.users.alice.uid;
runtimePath = "/run/user/${userId}";
in
''
machine.succeed("loginctl enable-linger alice")
machine.wait_for_unit("user@${userId}.service")
machine.wait_for_unit("monado.socket", "alice")
machine.systemctl("start monado.service", "alice")
machine.wait_for_unit("monado.service", "alice")
machine.wait_for_unit("monado.socket", "alice")
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")
'';
})
machine.succeed("su -- alice -c env XDG_RUNTIME_DIR=${runtimePath} openxr_runtime_list")
'';
}
)