Skip to content

Commit

Permalink
nixos/monado: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
PassiveLemon committed Jun 6, 2024
1 parent 3c9cdd2 commit 15837e6
Showing 1 changed file with 26 additions and 36 deletions.
62 changes: 26 additions & 36 deletions nixos/modules/services/hardware/monado.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,29 @@
, ...
}:
let
inherit (lib) mkDefault mkEnableOption mkIf mkOption mkPackageOption types;

inherit (lib) mkAliasOptionModule 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.
defaultRuntime = mkEnableOption ''
WiVRn Monado as the default OpenXR runtime on the system. The config can be found at `/etc/xdg/openxr/1/active_runtime.json`.
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;
};
runtime in a writable XDG_CONFIG_DIRS location like `~/.config`
'' // { default = true; };

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

imports = [
(mkAliasOptionModule ["services" "monado" "environment"] ["systemd" "user" "services" "monado" "environment"])
];

config = mkIf cfg.enable {
security.wrappers."monado-service" = mkIf cfg.highPriority {
setuid = false;
Expand All @@ -41,60 +37,54 @@ in
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" ];
services = {
monado.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";
};
udev.packages = with pkgs; [ xr-hardware ];
};

environment.etc."xdg/openxr/1/active_runtime.json" = mkIf cfg.defaultRuntime {
source = "${cfg.package}/share/openxr/1/openxr_monado.json";
environment = {
systemPackages = [ cfg.package ];
pathsToLink = [ "/share/openxr" ];
etc."xdg/openxr/1/active_runtime.json" = mkIf cfg.defaultRuntime {
source = "${cfg.package}/share/openxr/1/openxr_monado.json";
};
};
};

Expand Down

0 comments on commit 15837e6

Please sign in to comment.