Skip to content

NixOS support - Detecting XR Hardware But Not Creating or Modifying Inputs #38

@xM8WVqaG

Description

@xM8WVqaG

This looked like an interesting project so I had a go at building it on NixOS. Seeing as SteamOS added a /nix directory in 3.5.5 NixPkg might be an interesting way of deploying this in the future! Because of how Nix works, your existing install and packaging scripts wouldn't work.

For this test, I was trying to get XRLinuxDriver running on my laptop using sway 1.8.1, Linux 6.1.69 and with xreal Air 1.

The Nix derivation (build script) is basically just checking out the repo & dependencies and running cmake - it looks like:

{ lib
  , stdenv
  , fetchgit
  , cmake
  , pkg-config

  , json_c
  , libevdev
  , libusb
}:

stdenv.mkDerivation rec {
  pname = "xr-linux-driver";
  version = "0.6.1-beta";

  src = (fetchgit {
    url = "https://github.com/wheaney/XRLinuxDriver";
    rev = "0f74025ccee6d9017f07e39db9bcdacfaac7e134";
    sha256 = "sha256-fpIxNiMW8IelrNMuHtOPePIxeI1sxUNigZq5f/CqjyA=";
    fetchSubmodules = true;
  }).overrideAttrs (_: {
    GIT_CONFIG_COUNT = 1;
    GIT_CONFIG_KEY_0 = "url.https://gitlab.com/.insteadOf";
    GIT_CONFIG_VALUE_0 = "[email protected]:";
  });

  buildInputs = [
    json_c
    libevdev
    libusb
  ];

  nativeBuildInputs = [
    pkg-config
    cmake
  ];

  outputs = [ "out" ];

  patches = [
    ./install.patch
  ];

  meta = with lib; {
    description = "Custom user-space Linux driver for XR devices";
    homepage = "https://github.com/wheaney/XRLinuxDriver";
    license = licenses.mit;
    platforms = platforms.linux;
    maintainers = [ "wheaney" ];
  };
}

The patch applied is to CMakeLists.txt to add install targets to the output:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9d55cec..073303b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -55,4 +55,8 @@ target_include_directories(xrealAirLinuxDriver
 
 target_link_libraries(xrealAirLinuxDriver
 		PRIVATE ${LIBEVDEV_LIBRARIES} nrealAirLibrary Threads::Threads m ${VITURE_LIB_NAME} ${LIBUSB_LIBRARY}
-)
\ No newline at end of file
+)
+
+install(TARGETS xrealAirLinuxDriver DESTINATION bin)
+
+install(TARGETS hidapi_hidraw DESTINATION lib)

This runs fine as far as I can tell, the compiled binary executes and creates .xreal_driver_{log,config,lock}, although it only ever logs:

Starting up XR driver
Waiting for glasses
Starting up XR driver
Waiting for glasses
Starting up XR driver
Waiting for glasses
...

modprobe was run elsewhere:

$ lsmod | grep uinput          
uinput                 20480  0

This is the slightly modified service to work around the hardcoded ~ and not actually having a writable home:

[Unit]
After=network.target
Description=xr-linux-driver
Type=simple

[Service]
Environment=HOME=/run/user/1000/xr-linux-driver
ExecStart=/nix/store/0kngb662m75hrxw88jsqb1mvdkxv0ixb-xr-linux-driver-0.6.1-beta/bin/xrealAirLinuxDriver
PrivateNetwork=true
Restart=on-failure

I can see that it's managing to create a device:

$ journalctl
Jan 02 19:18:34 hostname kernel: usb 1-1: new full-speed USB device number 5 using xhci_hcd
Jan 02 19:18:34 hostname kernel: usb 1-1: New USB device found, idVendor=3318, idProduct=0424, bcdDevice= 0.01
Jan 02 19:18:34 hostname kernel: usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Jan 02 19:18:34 hostname kernel: usb 1-1: Product: Air
Jan 02 19:18:34 hostname kernel: usb 1-1: Manufacturer: Vendor
Jan 02 19:18:34 hostname kernel: usb 1-1: SerialNumber: A00020:14:32
Jan 02 19:18:34 hostname kernel: hid-generic 0003:3318:0424.002F: hiddev98,hidraw4: USB HID v1.10 Device [Vendor Air] on usb-0000:00:14.0-1/input3
Jan 02 19:18:34 hostname kernel: hid-generic 0003:3318:0424.0030: hiddev99,hidraw5: USB HID v1.10 Device [Vendor Air] on usb-0000:00:14.0-1/input4
Jan 02 19:18:34 hostname kernel: hid-generic 0003:3318:0424.0031: hiddev100,hidraw6: USB HID v1.10 Device [Vendor Air] on usb-0000:00:14.0-1/input5
Jan 02 19:18:34 hostname kernel: input: Vendor Air as /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.6/0003:3318:0424.0032/input/input45
Jan 02 19:18:34 hostname kernel: hid-generic 0003:3318:0424.0032: input,hidraw7: USB HID v1.10 Device [Vendor Air] on usb-0000:00:14.0-1/input6
$ libinput list-devices
...
Device:           Vendor Air
Kernel:           /dev/input/event20
Group:            6
Seat:             seat0, default
Capabilities:     keyboard 
Tap-to-click:     n/a
Tap-and-drag:     n/a
Tap drag lock:    n/a
Left-handed:      n/a
Nat.scrolling:    n/a
Middle emulation: n/a
Calibration:      n/a
Scroll methods:   none
Click methods:    none
Disable-w-typing: n/a
Disable-w-trackpointing: n/a
Accel profiles:   n/a
Rotation:         0.0
$ swaymsg -t get_inputs
{
  {
    "identifier": "13080:1060:Vendor_Air",
    "name": "Vendor Air",
    "vendor": 13080,
    "product": 1060,
    "type": "keyboard",
    "repeat_delay": 600,
    "repeat_rate": 25,
    "xkb_layout_names": [
      "English (UK)"
    ],
    "xkb_active_layout_index": 0,
    "xkb_active_layout_name": "English (UK)",
    "libinput": {
      "send_events": "enabled"
    }
  },
  ...
}

But it identifies as a keyboard. I've done before and after lists of libinput and it can only see one new device being created.

I've tried changing the output_mode=mouse to output_mode=joystick and the driver can see the change, but that doesn't change the detected device.

$ journalctl
...
Jan 02 18:48:49 hostname systemd[1975]: Stopping xr-linux-driver...
Jan 02 18:48:49 hostname systemd[1975]: Stopped xr-linux-driver.
Jan 02 18:48:49 hostname systemd[1975]: Started xr-linux-driver.
Jan 02 18:48:49 hostname xrealAirLinuxDriver[120743]: Output mode has been changed to 'joystick'

Any ideas?

EDIT: I've just read this back and it's not super clear what I'm asking. The Vendor Air does appear to be from the glasses itself, rather than the user-mode driver. So I guess this is more of a question around the behaviour of XRLinuxDriver, and what the correct behaviour is supposed to be at this point. Presumably they should be called XR virtual {joystick,mouse} based on: outputs.c

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions