Merge pull request #245005 from Scrumplex/nixos-monado

nixos/monado: init

authored by Atemu and committed by GitHub 97f445e8 b5c95626

+177
+2
nixos/doc/manual/release-notes/rl-2405.section.md
··· 87 87 88 88 - [go-camo](https://github.com/cactus/go-camo), a secure image proxy server. Available as [services.go-camo](#opt-services.go-camo.enable). 89 89 90 + - [Monado](https://monado.freedesktop.org/), an open source XR runtime. Available as [services.monado](#opt-services.monado.enable). 91 + 90 92 - [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). 91 93 92 94 - [TuxClocker](https://github.com/Lurkki14/tuxclocker), a hardware control and monitoring program. Available as [programs.tuxclocker](#opt-programs.tuxclocker.enable).
+1
nixos/modules/module-list.nix
··· 548 548 ./services/hardware/lcd.nix 549 549 ./services/hardware/lirc.nix 550 550 ./services/hardware/nvidia-container-toolkit-cdi-generator 551 + ./services/hardware/monado.nix 551 552 ./services/hardware/nvidia-optimus.nix 552 553 ./services/hardware/openrgb.nix 553 554 ./services/hardware/pcscd.nix
+102
nixos/modules/services/hardware/monado.nix
··· 1 + { config 2 + , lib 3 + , pkgs 4 + , ... 5 + }: 6 + let 7 + inherit (lib) mkDefault mkEnableOption mkIf mkOption mkPackageOption types; 8 + 9 + cfg = config.services.monado; 10 + 11 + in 12 + { 13 + options.services.monado = { 14 + enable = mkEnableOption "Monado user service"; 15 + 16 + package = mkPackageOption pkgs "monado" { }; 17 + 18 + defaultRuntime = mkOption { 19 + type = types.bool; 20 + description = '' 21 + Whether to enable Monado as the default OpenXR runtime on the system. 22 + 23 + Note that applications can bypass this option by setting an active 24 + runtime in a writable XDG_CONFIG_DIRS location like `~/.config`. 25 + ''; 26 + default = false; 27 + example = true; 28 + }; 29 + 30 + highPriority = mkEnableOption "high priority capability for monado-service" 31 + // mkOption { default = true; }; 32 + }; 33 + 34 + config = mkIf cfg.enable { 35 + security.wrappers."monado-service" = mkIf cfg.highPriority { 36 + setuid = false; 37 + owner = "root"; 38 + group = "root"; 39 + # cap_sys_nice needed for asynchronous reprojection 40 + capabilities = "cap_sys_nice+eip"; 41 + source = lib.getExe' cfg.package "monado-service"; 42 + }; 43 + 44 + services.udev.packages = with pkgs; [ xr-hardware ]; 45 + 46 + systemd.user = { 47 + services.monado = { 48 + description = "Monado XR runtime service module"; 49 + requires = [ "monado.socket" ]; 50 + conflicts = [ "monado-dev.service" ]; 51 + 52 + unitConfig.ConditionUser = "!root"; 53 + 54 + environment = { 55 + # Default options 56 + # https://gitlab.freedesktop.org/monado/monado/-/blob/4548e1738591d0904f8db4df8ede652ece889a76/src/xrt/targets/service/monado.in.service#L12 57 + XRT_COMPOSITOR_LOG = mkDefault "debug"; 58 + XRT_PRINT_OPTIONS = mkDefault "on"; 59 + IPC_EXIT_ON_DISCONNECT = mkDefault "off"; 60 + }; 61 + 62 + serviceConfig = { 63 + ExecStart = 64 + if cfg.highPriority 65 + then "${config.security.wrapperDir}/monado-service" 66 + else lib.getExe' cfg.package "monado-service"; 67 + Restart = "no"; 68 + }; 69 + 70 + restartTriggers = [ cfg.package ]; 71 + }; 72 + 73 + sockets.monado = { 74 + description = "Monado XR service module connection socket"; 75 + conflicts = [ "monado-dev.service" ]; 76 + 77 + unitConfig.ConditionUser = "!root"; 78 + 79 + socketConfig = { 80 + ListenStream = "%t/monado_comp_ipc"; 81 + RemoveOnStop = true; 82 + 83 + # If Monado crashes while starting up, we want to close incoming OpenXR connections 84 + FlushPending = true; 85 + }; 86 + 87 + restartTriggers = [ cfg.package ]; 88 + 89 + wantedBy = [ "sockets.target" ]; 90 + }; 91 + }; 92 + 93 + environment.systemPackages = [ cfg.package ]; 94 + environment.pathsToLink = [ "/share/openxr" ]; 95 + 96 + environment.etc."xdg/openxr/1/active_runtime.json" = mkIf cfg.defaultRuntime { 97 + source = "${cfg.package}/share/openxr/1/openxr_monado.json"; 98 + }; 99 + }; 100 + 101 + meta.maintainers = with lib.maintainers; [ Scrumplex ]; 102 + }
+1
nixos/tests/all-tests.nix
··· 537 537 mobilizon = handleTest ./mobilizon.nix {}; 538 538 mod_perl = handleTest ./mod_perl.nix {}; 539 539 molly-brown = handleTest ./molly-brown.nix {}; 540 + monado = handleTest ./monado.nix {}; 540 541 monica = handleTest ./web-apps/monica.nix {}; 541 542 mongodb = handleTest ./mongodb.nix {}; 542 543 moodle = handleTest ./moodle.nix {};
+39
nixos/tests/monado.nix
··· 1 + import ./make-test-python.nix ({ pkgs, ... }: { 2 + name = "monado"; 3 + 4 + nodes.machine = 5 + { pkgs, ... }: 6 + 7 + { 8 + hardware.opengl.enable = true; 9 + users.users.alice = { 10 + isNormalUser = true; 11 + uid = 1000; 12 + }; 13 + 14 + services.monado = { 15 + enable = true; 16 + defaultRuntime = true; 17 + }; 18 + # Stop Monado from probing for any hardware 19 + systemd.user.services.monado.environment.SIMULATED_ENABLE = "1"; 20 + 21 + environment.systemPackages = with pkgs; [ openxr-loader ]; 22 + }; 23 + 24 + testScript = { nodes, ... }: 25 + let 26 + userId = toString nodes.machine.users.users.alice.uid; 27 + runtimePath = "/run/user/${userId}"; 28 + in 29 + '' 30 + machine.succeed("loginctl enable-linger alice") 31 + machine.wait_for_unit("user@${userId}.service") 32 + 33 + machine.wait_for_unit("monado.socket", "alice") 34 + machine.systemctl("start monado.service", "alice") 35 + machine.wait_for_unit("monado.service", "alice") 36 + 37 + machine.succeed("su -- alice -c env XDG_RUNTIME_DIR=${runtimePath} openxr_runtime_list") 38 + ''; 39 + })
+5
pkgs/applications/graphics/monado/default.nix
··· 41 41 , wayland-scanner 42 42 , libdrm 43 43 , zlib 44 + , nixosTests 44 45 # Set as 'false' to build monado without service support, i.e. allow VR 45 46 # applications linking against libopenxr_monado.so to use OpenXR standalone 46 47 # instead of via the monado-service program. For more information see: ··· 136 137 # We don't have $HOME/.steam when building 137 138 ./force-enable-steamvr_lh.patch 138 139 ]; 140 + 141 + passthru.tests = { 142 + basic-service = nixosTests.monado; 143 + }; 139 144 140 145 meta = with lib; { 141 146 description = "Open source XR runtime";
+27
pkgs/by-name/xr/xr-hardware/package.nix
··· 1 + { 2 + lib, 3 + stdenvNoCC, 4 + fetchFromGitLab 5 + }: stdenvNoCC.mkDerivation { 6 + pname = "xr-hardware"; 7 + version = "unstable-2023-11-08"; 8 + 9 + src = fetchFromGitLab { 10 + domain = "gitlab.freedesktop.org"; 11 + owner = "monado/utilities"; 12 + repo = "xr-hardware"; 13 + rev = "9204de323210d2a5ab8635c2ee52127100de67b1"; 14 + hash = "sha256-ZS15WODms/WKsPu+WbfILO2BOwnxrhCY/SoF8jzOX5Q="; 15 + }; 16 + 17 + installTargets = "install_package"; 18 + installFlagsArray = "DESTDIR=${placeholder "out"}"; 19 + 20 + meta = with lib; { 21 + description = "Hardware description for XR devices"; 22 + homepage = "https://gitlab.freedesktop.org/monado/utilities/xr-hardware"; 23 + license = licenses.boost; 24 + maintainers = with maintainers; [ Scrumplex ]; 25 + platforms = platforms.linux; 26 + }; 27 + }