Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/monado: init #245005

Merged
merged 7 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nixos/doc/manual/release-notes/rl-2405.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
102 changes: 102 additions & 0 deletions nixos/modules/services/hardware/monado.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{ config
, lib
, pkgs
, ...
}:
let
inherit (lib) mkDefault mkEnableOption mkIf mkOption mkPackageOption types;

cfg = config.services.monado;

in
{
options.services.monado = {
enable = mkEnableOption "Monado 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;
};

highPriority = mkEnableOption "high priority capability for monado-service"
// mkOption { default = true; };
};

config = mkIf cfg.enable {
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 = 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
then "${config.security.wrapperDir}/monado-service"
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" ];

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 ];
}
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down
39 changes: 39 additions & 0 deletions nixos/tests/monado.nix
Original file line number Diff line number Diff line change
@@ -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")
'';
})
5 changes: 5 additions & 0 deletions pkgs/applications/graphics/monado/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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/";
Expand Down
27 changes: 27 additions & 0 deletions pkgs/by-name/xr/xr-hardware/package.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
Loading