From 5d57df8a804b46f9071778e918a2c43f942faf42 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sun, 23 Jul 2023 11:36:49 +0200 Subject: [PATCH 1/7] nixos/monado: init Signed-off-by: Sefa Eyeoglu --- .../manual/release-notes/rl-2405.section.md | 2 + nixos/modules/module-list.nix | 1 + nixos/modules/services/hardware/monado.nix | 73 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 nixos/modules/services/hardware/monado.nix diff --git a/nixos/doc/manual/release-notes/rl-2405.section.md b/nixos/doc/manual/release-notes/rl-2405.section.md index 48038c2e2e70..a89dac57db34 100644 --- a/nixos/doc/manual/release-notes/rl-2405.section.md +++ b/nixos/doc/manual/release-notes/rl-2405.section.md @@ -77,6 +77,8 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m - [go-camo](https://github.com/cactus/go-camo), a secure image proxy server. Available as [services.go-camo](#opt-services.go-camo.enable). +- [Monado](https://monado.freedesktop.org/), an open source XR runtime. Available as [services.monado](#opt-services.monado.enable). + - [Clevis](https://github.com/latchset/clevis), a pluggable framework for automated decryption, used to unlock encrypted devices in initrd. Available as [boot.initrd.clevis.enable](#opt-boot.initrd.clevis.enable). - [TuxClocker](https://github.com/Lurkki14/tuxclocker), a hardware control and monitoring program. Available as [programs.tuxclocker](#opt-programs.tuxclocker.enable). diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 7273390595ec..b2038bb907ae 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -547,6 +547,7 @@ ./services/hardware/lcd.nix ./services/hardware/lirc.nix ./services/hardware/nvidia-container-toolkit-cdi-generator + ./services/hardware/monado.nix ./services/hardware/nvidia-optimus.nix ./services/hardware/openrgb.nix ./services/hardware/pcscd.nix diff --git a/nixos/modules/services/hardware/monado.nix b/nixos/modules/services/hardware/monado.nix new file mode 100644 index 000000000000..55ad2c299bae --- /dev/null +++ b/nixos/modules/services/hardware/monado.nix @@ -0,0 +1,73 @@ +{ config +, lib +, pkgs +, ... +}: +let + inherit (lib) mkDefault mkEnableOption mkIf mkPackageOption; + + cfg = config.services.monado; +in +{ + options.services.monado = { + enable = mkEnableOption "Monado wrapper and user service"; + + package = mkPackageOption pkgs "monado" { }; + }; + + config = mkIf cfg.enable { + security.wrappers."monado-service" = { + setuid = false; + owner = "root"; + group = "root"; + # cap_sys_nice needed for asynchronous reprojection + capabilities = "cap_sys_nice+eip"; + source = "${cfg.package}/bin/monado-service"; + }; + + 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 = "${config.security.wrapperDir}/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; + }; + + restartTriggers = [ cfg.package ]; + + wantedBy = [ "sockets.target" ]; + }; + }; + + environment.systemPackages = [ cfg.package ]; + }; + + meta.maintainers = with lib.maintainers; [ Scrumplex ]; +} From 90031675224ca0a530e377d8e8b4927db36ca256 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 18 Dec 2023 11:12:14 +0100 Subject: [PATCH 2/7] xr-hardware: init at unstable-2023-11-08 Signed-off-by: Sefa Eyeoglu --- nixos/modules/services/hardware/monado.nix | 2 ++ pkgs/by-name/xr/xr-hardware/package.nix | 27 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 pkgs/by-name/xr/xr-hardware/package.nix diff --git a/nixos/modules/services/hardware/monado.nix b/nixos/modules/services/hardware/monado.nix index 55ad2c299bae..3178c46c1a83 100644 --- a/nixos/modules/services/hardware/monado.nix +++ b/nixos/modules/services/hardware/monado.nix @@ -25,6 +25,8 @@ in source = "${cfg.package}/bin/monado-service"; }; + services.udev.packages = with pkgs; [ xr-hardware ]; + systemd.user = { services.monado = { description = "Monado XR runtime service module"; diff --git a/pkgs/by-name/xr/xr-hardware/package.nix b/pkgs/by-name/xr/xr-hardware/package.nix new file mode 100644 index 000000000000..b2359c2673df --- /dev/null +++ b/pkgs/by-name/xr/xr-hardware/package.nix @@ -0,0 +1,27 @@ +{ + lib, + stdenvNoCC, + fetchFromGitLab +}: stdenvNoCC.mkDerivation { + pname = "xr-hardware"; + version = "unstable-2023-11-08"; + + src = fetchFromGitLab { + domain = "gitlab.freedesktop.org"; + owner = "monado/utilities"; + repo = "xr-hardware"; + rev = "9204de323210d2a5ab8635c2ee52127100de67b1"; + hash = "sha256-ZS15WODms/WKsPu+WbfILO2BOwnxrhCY/SoF8jzOX5Q="; + }; + + installTargets = "install_package"; + installFlagsArray = "DESTDIR=${placeholder "out"}"; + + meta = with lib; { + description = "Hardware description for XR devices"; + homepage = "https://gitlab.freedesktop.org/monado/utilities/xr-hardware"; + license = licenses.boost; + maintainers = with maintainers; [ Scrumplex ]; + platforms = platforms.linux; + }; +} From ce36e73fdba7264db7296fcac045e41601683a66 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 18 Dec 2023 16:54:15 +0100 Subject: [PATCH 3/7] nixos/monado: link OpenXR runtimes Signed-off-by: Sefa Eyeoglu --- nixos/modules/services/hardware/monado.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nixos/modules/services/hardware/monado.nix b/nixos/modules/services/hardware/monado.nix index 3178c46c1a83..9933d905584f 100644 --- a/nixos/modules/services/hardware/monado.nix +++ b/nixos/modules/services/hardware/monado.nix @@ -69,6 +69,7 @@ in }; environment.systemPackages = [ cfg.package ]; + environment.pathsToLink = [ "/share/openxr" ]; }; meta.maintainers = with lib.maintainers; [ Scrumplex ]; From 2d2493b23dc35f552e13f6022b0ec4b2a4cdc7b1 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 18 Dec 2023 16:55:02 +0100 Subject: [PATCH 4/7] nixos/monado: add option to make Monado the default OpenXR runtime Signed-off-by: Sefa Eyeoglu --- nixos/modules/services/hardware/monado.nix | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/hardware/monado.nix b/nixos/modules/services/hardware/monado.nix index 9933d905584f..09895bfab2f0 100644 --- a/nixos/modules/services/hardware/monado.nix +++ b/nixos/modules/services/hardware/monado.nix @@ -4,15 +4,28 @@ , ... }: let - inherit (lib) mkDefault mkEnableOption mkIf mkPackageOption; + inherit (lib) mkDefault mkEnableOption mkIf mkOption mkPackageOption types; cfg = config.services.monado; + in { options.services.monado = { enable = mkEnableOption "Monado wrapper and user service"; package = mkPackageOption pkgs "monado" { }; + + defaultRuntime = mkOption { + type = types.bool; + description = '' + Whether to enable Monado as the default OpenXR runtime on the system. + + 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; + }; }; config = mkIf cfg.enable { @@ -70,6 +83,10 @@ in environment.systemPackages = [ cfg.package ]; environment.pathsToLink = [ "/share/openxr" ]; + + environment.etc."xdg/openxr/1/active_runtime.json" = mkIf cfg.defaultRuntime { + source = "${cfg.package}/share/openxr/1/openxr_monado.json"; + }; }; meta.maintainers = with lib.maintainers; [ Scrumplex ]; From 8fc2690b73a3c0376f69c34a37dc716c5d6bd6bd Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 18 Dec 2023 17:48:48 +0100 Subject: [PATCH 5/7] nixos/monado: add test Signed-off-by: Sefa Eyeoglu --- nixos/tests/all-tests.nix | 1 + nixos/tests/monado.nix | 39 +++++++++++++++++++ pkgs/applications/graphics/monado/default.nix | 5 +++ 3 files changed, 45 insertions(+) create mode 100644 nixos/tests/monado.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 1144a5611dcf..138753131654 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -535,6 +535,7 @@ in { mobilizon = handleTest ./mobilizon.nix {}; mod_perl = handleTest ./mod_perl.nix {}; molly-brown = handleTest ./molly-brown.nix {}; + monado = handleTest ./monado.nix {}; monica = handleTest ./web-apps/monica.nix {}; mongodb = handleTest ./mongodb.nix {}; moodle = handleTest ./moodle.nix {}; diff --git a/nixos/tests/monado.nix b/nixos/tests/monado.nix new file mode 100644 index 000000000000..8368950951e7 --- /dev/null +++ b/nixos/tests/monado.nix @@ -0,0 +1,39 @@ +import ./make-test-python.nix ({ pkgs, ... }: { + name = "monado"; + + nodes.machine = + { pkgs, ... }: + + { + hardware.opengl.enable = true; + users.users.alice = { + isNormalUser = true; + uid = 1000; + }; + + services.monado = { + enable = true; + defaultRuntime = true; + }; + # Stop Monado from probing for any hardware + systemd.user.services.monado.environment.SIMULATED_ENABLE = "1"; + + environment.systemPackages = with pkgs; [ openxr-loader ]; + }; + + 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.succeed("su -- alice -c env XDG_RUNTIME_DIR=${runtimePath} openxr_runtime_list") + ''; +}) diff --git a/pkgs/applications/graphics/monado/default.nix b/pkgs/applications/graphics/monado/default.nix index 40e5f916f3f3..7442f192fe24 100644 --- a/pkgs/applications/graphics/monado/default.nix +++ b/pkgs/applications/graphics/monado/default.nix @@ -41,6 +41,7 @@ , wayland-scanner , libdrm , zlib +, nixosTests # Set as 'false' to build monado without service support, i.e. allow VR # applications linking against libopenxr_monado.so to use OpenXR standalone # instead of via the monado-service program. For more information see: @@ -137,6 +138,10 @@ stdenv.mkDerivation { ./force-enable-steamvr_lh.patch ]; + passthru.tests = { + basic-service = nixosTests.monado; + }; + meta = with lib; { description = "Open source XR runtime"; homepage = "https://monado.freedesktop.org/"; From 0e585a63e2f2ae03d658d41ab99cd41c0b0de9c1 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 6 Jan 2024 12:15:47 +0100 Subject: [PATCH 6/7] nixos/monado: make CAP_SYS_NICE wrapper configurable Signed-off-by: Sefa Eyeoglu --- nixos/modules/services/hardware/monado.nix | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nixos/modules/services/hardware/monado.nix b/nixos/modules/services/hardware/monado.nix index 09895bfab2f0..0fb822bb21e8 100644 --- a/nixos/modules/services/hardware/monado.nix +++ b/nixos/modules/services/hardware/monado.nix @@ -11,7 +11,7 @@ let in { options.services.monado = { - enable = mkEnableOption "Monado wrapper and user service"; + enable = mkEnableOption "Monado user service"; package = mkPackageOption pkgs "monado" { }; @@ -26,16 +26,19 @@ in default = false; example = true; }; + + highPriority = mkEnableOption "high priority capability for monado-service" + // mkOption { default = true; }; }; config = mkIf cfg.enable { - security.wrappers."monado-service" = { + security.wrappers."monado-service" = mkIf cfg.highPriority { setuid = false; owner = "root"; group = "root"; # cap_sys_nice needed for asynchronous reprojection capabilities = "cap_sys_nice+eip"; - source = "${cfg.package}/bin/monado-service"; + source = lib.getExe' cfg.package "monado-service"; }; services.udev.packages = with pkgs; [ xr-hardware ]; @@ -57,7 +60,10 @@ in }; serviceConfig = { - ExecStart = "${config.security.wrapperDir}/monado-service"; + ExecStart = + if cfg.highPriority + then "${config.security.wrapperDir}/monado-service" + else lib.getExe' cfg.package "monado-service"; Restart = "no"; }; From 3f7e9baeebab425f44caa19de37f004724c9c0fc Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Fri, 12 Jan 2024 11:35:08 +0100 Subject: [PATCH 7/7] nixos/monado: prevent Monado from restarting quickly Signed-off-by: Sefa Eyeoglu --- nixos/modules/services/hardware/monado.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nixos/modules/services/hardware/monado.nix b/nixos/modules/services/hardware/monado.nix index 0fb822bb21e8..9f9c6c39a0b4 100644 --- a/nixos/modules/services/hardware/monado.nix +++ b/nixos/modules/services/hardware/monado.nix @@ -79,6 +79,9 @@ in 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 ];