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: refactor #299841

Closed
wants to merge 1 commit into from
Closed
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
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; };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this really be true by default?


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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it make sense to make services.monado.environment part of options so that XRT_COMPOSITOR_LOG, XRT_PRINT_OPTIONS, and IPC_EXIT_ON_DISCONNECT can be documented?

# 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