Skip to content

nix: Add Nix Flake support - #80

Open
shymega wants to merge 4 commits into
wheaney:mainfrom
shymega:shymega/nix-flake-support
Open

shymega wants to merge 4 commits into
wheaney:mainfrom
shymega:shymega/nix-flake-support

Conversation

@shymega

@shymega shymega commented Dec 1, 2024 •

Copy link
Copy Markdown

This commit consists of the following changes:

  • default.nix/shell.nix
    This allows for legacy Nix tooling like nix-build/nix-shell to work.
  • flake.nix
    This is for the (new) Nix Flake support.
  • flake.lock
    As above, but for tracking Flake inputs.
  • .envrc
    This allows for a fully self-contained developer environment to be
    setup with Nix.
  • nix/default.nix
    This is the main package derivation. Both this repo & Nixpkgs are
    derived from the same codebase.

Closes: #38

@shymega

shymega commented Dec 1, 2024

Copy link
Copy Markdown
Author

I finally had delivery of a VITURE Pro today, after being lost, but I've tested my Flake with the glasses, and it does seem to work - about to test mouse control shortly.

@shymega

shymega commented Dec 1, 2024 •

Copy link
Copy Markdown
Author

The long-term steps would be to upstream the derivation (+ Breezy) to Nixpkgs, as well as a Nix module, and a CI workflow for this repo (+ Breezy).

@shymega
shymega force-pushed the shymega/nix-flake-support branch from 489b7fc to fba3fa3 Compare December 2, 2024 20:36
@shymega
shymega force-pushed the shymega/nix-flake-support branch 5 times, most recently from 519285a to 77822f9 Compare December 6, 2024 20:33
@shymega
shymega force-pushed the shymega/nix-flake-support branch 3 times, most recently from aa811c1 to 8140a66 Compare February 16, 2025 18:27
@wheaney

wheaney commented Apr 27, 2025

Copy link
Copy Markdown
Owner

@shymega can you let me know if this is ready? Also can you have another Nix user test and sign off on it?

@deephack1982

Copy link
Copy Markdown

As for another Nix user I'm here. I actually already put together a Nix package for the driver but this one looks further along than mine so will test. Will post my findings here in the next few days.

@deephack1982

deephack1982 commented Apr 28, 2025 •

Copy link
Copy Markdown

Okay so it builds and I can install the driver but I seem to be having some issues connecting to my Viture Pro glasses. I get the following in the xrDriver log.

2025-04-28 22:02:40.853 Project version: 1.1.0
2025-04-28 22:02:40.854 Driver is disabled
2025-04-28 22:02:40.855 Using hardware id b50796e372423c376420886322d8fee0f49f3f28fb6c8a90a08dda81f1a0599f
2025-04-28 22:02:40.856 Feature sbs granted.
2025-04-28 22:02:40.856 Feature smooth_follow granted.
2025-04-28 22:02:40.856 Feature productivity_basic granted.
2025-04-28 22:02:40.856 Starting up XR driver
2025-04-28 22:02:40.857 Found device with vendor ID 0x35ca and product ID 0x101d
2025-04-28 22:02:40.857 Found device with vendor ID 0x35ca and product ID 0x101d
2025-04-28 22:03:07.988 Driver has been re-enabled
2025-04-28 22:03:09.991 Device driver connection attempt failed
2025-04-28 22:03:09.991 Retrying driver connection in 1 second
2025-04-28 22:03:12.992 Device driver connection attempt failed
2025-04-28 22:03:12.992 Retrying driver connection in 1 second
2025-04-28 22:03:15.994 Device driver connection attempt failed
2025-04-28 22:03:15.994 Retrying driver connection in 1 second
2025-04-28 22:03:16.395 Driver has been disabled

In kernel logs I have this when I plug in the glasses.

[ 187.344812] usb 2-1: new full-speed USB device number 7 using xhci_hcd
[ 187.470047] usb 2-1: New USB device found, idVendor=35ca, idProduct=101d, bcdDevice= 2.00
[ 187.470064] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 187.470070] usb 2-1: Product: VITURE Pro XR Glasses
[ 187.470076] usb 2-1: Manufacturer: VITURE Pro
[ 187.470080] usb 2-1: SerialNumber: 205A308E4742
[ 187.474054] hid-generic 0003:35CA:101D.0003: hiddev96,hidraw0: USB HID v1.11 Device [VITURE Pro VITURE Pro XR Glasses] on usb-0000:00:14.0-1/input0
[ 187.475272] hid-generic 0003:35CA:101D.0004: hiddev97,hidraw1: USB HID v1.11 Device [VITURE Pro VITURE Pro XR Glasses] on usb-0000:00:14.0-1/input1
[ 187.475951] cdc_acm 2-1:1.2: ttyACM0: USB ACM device

So the glasses are being recognised by the kernel. For refernce this is NixOS unstable running kernel 6.12.24.

@wheaney

wheaney commented Apr 28, 2025

Copy link
Copy Markdown
Owner

You might want to try rebasing this branch, as main is on 2.x and may include a fixing change for that. But first you could try to see if this persists after a restart. And try not having the glasses plugged in on boot.

@shymega

shymega commented Apr 28, 2025

Copy link
Copy Markdown
Author

Yes, this isn't a problem with my package. I did raise it with @wheaney over Discord, but the solution isn't clear yet.

Have you put the udev rules in your services.udev.extraRules? I could add that as an output to the package...

@shymega

shymega commented Apr 28, 2025

Copy link
Copy Markdown
Author

I'll rebase this now.

@deephack1982

Copy link
Copy Markdown

Tried a restart and adding the udev rules but still getting the same output for now.

@shymega
shymega force-pushed the shymega/nix-flake-support branch from 8140a66 to 4dabde1 Compare April 28, 2025 20:29
@shymega

shymega commented Apr 28, 2025

Copy link
Copy Markdown
Author

@deephack1982 Try now :-)

I'm also working on a Guix package, if that's of interest to anyone following this thread.

@deephack1982

deephack1982 commented Apr 28, 2025 •

Copy link
Copy Markdown

New one gives me a build failure with the following make output.

[ 58%] Building C object CMakeFiles/xrDriver.dir/src/ipc.c.o
[ 60%] Building C object CMakeFiles/xrDriver.dir/src/multitap.c.o
[ 62%] Building C object CMakeFiles/xrDriver.dir/src/outputs.c.o
/build/xrlinuxdriver-src/src/ipc.c: In function 'setup_ipc_value':
/build/xrlinuxdriver-src/src/ipc.c:78:5: error: implicit declaration of function 'close'; did you mean 'pclose'? []
78 | close(fd);
| ^~~~~
| pclose
make[2]: *** [CMakeFiles/xrDriver.dir/build.make:261: CMakeFiles/xrDriver.dir/src/ipc.c.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:253: CMakeFiles/xrDriver.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Tested and this is present on wheaneys main branch if I do a basic cmake and make so nothing up with the flake.

2.0.5 tag builds cleanly however.

@shymega

shymega commented Apr 28, 2025

Copy link
Copy Markdown
Author

Yeah, the Flake builds from the Git repo, but I didn't have any issues building.

@shymega

shymega commented Apr 28, 2025

Copy link
Copy Markdown
Author

How did you invoke the Flake?

@deephack1982

Copy link
Copy Markdown

I allow the direnv to load and then issue the nix-build command in the root.

@shymega

shymega commented Apr 28, 2025

Copy link
Copy Markdown
Author

Ah, I can reproduce it now. It was cached.

Try building from shymega/nix-flake-support-v2.0.5 on my fork, and then we can establish if the Nix package can fix the issues with the glasses - I experienced this too.

@deephack1982

Copy link
Copy Markdown

That branch builds fine but the driver output is still the same. Connection attempt fails and then it retries in a loop.

@deephack1982

deephack1982 commented Apr 28, 2025 •

Copy link
Copy Markdown

Quick note by the way as I was looking into the udev rules and how to package them. As per this thread it seems that any package containing $out/lib/udev/rules.d/ will be picked up by the system automatically. Actually not quite automatically, you need to specify sevices.udev.package = [ mypackage ]; but anyway.

https://discourse.nixos.org/t/how-to-create-files-in-the-etc-udev-rules-d-directory/11929/13

@shymega

shymega commented Apr 28, 2025

Copy link
Copy Markdown
Author

That branch builds fine but the driver output is still the same. Connection attempt fails and then it retries in a loop.

I found this happened for me too, but not on the first connection cycle of my VITURE Pros.

@shymega

shymega commented Apr 28, 2025

Copy link
Copy Markdown
Author

Quick note by the way as I was looking into the udev rules and how to package them. As per this thread it seems that any package containing $out/lib/udev/rules.d/ will be picked up by the system automatically. Actually not quite automatically, you need to specify sevices.udev.package = [ mypackage ]; but anyway.

discourse.nixos.org/t/how-to-create-files-in-the-etc-udev-rules-d-directory/11929/13

Ah, that's good to hear. So the way I've packaged it makes this seamless.

@seanybaggins

Copy link
Copy Markdown

Okay took a bit of a different approach to this but I now have it working perfectly. I think the issue was indeed the udev rules. See attached files strip the txt, below is my file structure.
/etc/nixos

* overlays

* * xrlinuxdriver-overlay.nix

* pkgs

* * xrlinuxdriver/  # Of course in once PR is merged we will just fetchgit this in xrlinuxdriver.nix

* * xrlinuxdriver.nix

I then added the following to my configuration.nix and ran rebuild.

nixpkgs.overlays = [
    (import ./overlays/xrlinuxdriver-overlay.nix)
  ];

environment.systemPackages = with pkgs; [
    xrlinuxdriver
  ];

  services.udev.packages = with pkgs; [
    xrlinuxdriver
  ];

The systemd unit still needs to be manually installed but now all the udev stuff just works.
xrlinuxdriver.nix.txt xrlinuxdriver-overlay.nix.txt

I'll edit the udev path, but if you can test the systemd unit as well, that would be great.

I use Home Manager for installing the CLI, which works for me. My overlay setup is slightly more complex, and I don't think you use Flakes, right?

So I am testing this out and am using the config listed by @shymega. You can confirm looking here... https://github.com/seanybaggins/nix-home/commit/9e0ba8988d764cf1ea5f407d15d781d1f4fda4e1

I am not sure I am observing successful behavior. When wearing the glasses, the screen is always appearing directly in front of me.

xr_driver_cli -l

2025-05-31 13:49:51.310 Project version: 2.0.6
2025-05-31 13:49:51.310 Driver is disabled
2025-05-31 13:49:51.312 Using hardware id 9528df32eb00986ec8a14c7e50a5a9ece48763aa75bcc735d471f1e07ddb7254
2025-05-31 13:49:52.989 Feature sbs granted.
2025-05-31 13:49:52.990 Feature smooth_follow granted.
2025-05-31 13:49:52.990 Feature productivity_basic granted.
2025-05-31 13:49:52.990 Starting up XR driver
2025-05-31 13:49:52.993 Found device with vendor ID 0x35ca and product ID 0x101d
2025-05-31 13:49:52.993 Found device with vendor ID 0x35ca and product ID 0x101d
❯ xr_driver_verify
Verification failed

Looks like I dont have a manafest file at ~/.local/share

@shymega

shymega commented Jun 1, 2025

Copy link
Copy Markdown
Author

@seanybaggins This is expected behaviour. XRLinuxDriver doesn't implement multiple screens - Breezy does, but this is a separate issue.

What you're seeing is a functioning Flake for XRLinuxDriver, and therefore it can now be merged, I am happy to say.

You can test the state by running cat /dev/shm/xr_driver_state.

Breezy is more complex, as we'll need to build from source rather than using binaries, and this requires a few hacks. I am working on this separately.

If @wheaney is happy to merge this MR, I can then upstream my Nixpkgs branch to Nixpkgs, and it'll be backported to 25.05.

@wheaney wheaney left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please update the README with instructions for Nix setup, also rebase and update any version numbers.

Comment thread nix/default.nix Resolved
@shymega
shymega force-pushed the shymega/nix-flake-support branch from c6cd02d to 17a67cd Compare June 1, 2025 18:27

@wheaney wheaney left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please also update the README with Nix instructions.

Comment thread modules/xrealInterfaceLibrary Resolved
@shymega
shymega force-pushed the shymega/nix-flake-support branch from 17a67cd to 621128a Compare March 23, 2026 22:45
@shymega
shymega force-pushed the shymega/nix-flake-support branch 2 times, most recently from fec340d to 888dcef Compare April 17, 2026 23:22
@signaleleven

Copy link
Copy Markdown

If it helps and if it counts as independent testing, I successfully configured this on NixOS today, adding it (shymega's fork, nix-flake-support branch) as an input to my system flake.
It would definitely benefit from a short example that shows how to configure the udev rules and activate the systemd user service (I'm an eternal NixOS noob so I had to find my way through with some LLM guidance)...but it works!

@wheaney

wheaney commented Jul 30, 2026

Copy link
Copy Markdown
Owner

@shymega is this ready to go?

@shymega
shymega force-pushed the shymega/nix-flake-support branch 2 times, most recently from 558a065 to b9f38ee Compare August 1, 2026 21:23
@shymega

shymega commented Aug 5, 2026

Copy link
Copy Markdown
Author

@wheaney Kind of. I had some interest in my Discord DMs, but no testing results yet.

This PR needs CI and README implementation, but I'd like to see testing first.

@signaleleven

signaleleven commented Aug 15, 2026 •

Copy link
Copy Markdown

I had https://github.com/shymega/XRLinuxDriver/tree/shymega/nix-flake-support in my flake inputs and it's broken since the refactoring. Something about trying to build something twice...I don't use it that much so I could not look into the problem yet and I did not save the error, sorry. It's entirely possible that I am doing something wrong. Could you add an example to the readme?

edit: recovered the error

building the system configuration...
error: Cannot build '/nix/store/z3w8fbk229m8qmljxgp0m8q1g80dmnc3-xrlinuxdriver-2.10.0.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/wshrigc1f0ppwkg6ivazbmx3qlwg3b6g-xrlinuxdriver-2.10.0
       Last 25 log lines:
       >   See documentation for policy CMP0002 for more details.
       >
       >
       > CMake Error at modules/xrealOneDeviceKit/modules/xreal_one_driver/CMakeLists.txt:53 (add_library):
       >   add_library cannot create imported target "xreal_one_driver" because
       >   another target with the same name already exists.
       >
       >
       > -- xreal_one_driver: IMPORTED_LOCATION=/build/xrlinuxdriver-src/modules/xrealOneDeviceKit/modules/xreal_one_driver/target/release/libxreal_one_driver.a
       > CMake Error at modules/xrealOneDeviceKit/modules/xreal_one_driver/CMakeLists.txt:64 (add_executable):
       >   add_executable cannot create target "run_c_example" because another target
       >   with the same name already exists.  The existing target is an executable
       >   created in source directory
       >   "/build/xrlinuxdriver-src/modules/xrealInterfaceLibrary/interface_lib/modules/xreal_one_driver".
       >   See documentation for policy CMP0002 for more details.
       >
       >
       > -- LIB_DIR: /build/xrlinuxdriver-src/lib/x86_64
       > -- VITURE_LIB_DIR: /build/xrlinuxdriver-src/lib/x86_64/viture
       > -- STATIC_LIBS:
       > -- SHARED_LIBS: /build/xrlinuxdriver-src/lib/x86_64/libGlassSDK.so;/build/xrlinuxdriver-src/lib/x86_64/libRayNeoXRMiniSDK.so;/build/xrlinuxdriver-src/lib/x86_64/viture/libcarina_vio.so;/build/xrlinuxdriver-src/lib/x86_64/viture/libglasses.so;/build/xrlinuxdriver-src/lib/x86_64/viture/libopencv_calib3d.so;/build/xrlinuxdriver-src/lib/x86_64/viture/libopencv_core.so;/build/xrlinuxdriver-src/lib/x86_64/viture/libopencv_features2d.so;/build/xrlinuxdriver-src/lib/x86_64/viture/libopencv_flann.so;/build/xrlinuxdriver-src/lib/x86_64/viture/libopencv_highgui.so;/build/xrlinuxdriver-src/lib/x86_64/viture/libopencv_imgcodecs.so;/build/xrlinuxdriver-src/lib/x86_64/viture/libopencv_imgproc.so;/build/xrlinuxdriver-src/lib/x86_64/viture/libopencv_video.so;/build/xrlinuxdriver-src/lib/x86_64/viture/libopencv_videoio.so
       > -- GlassSDK support enabled, added src/devices/rokid.c
       > -- RayNeoXRMiniSDK support enabled, added src/devices/rayneo.c
       > -- VITURE support enabled, added src/devices/viture.c
       > -- Configuring incomplete, errors occurred!
       For full logs, run:
         nix log /nix/store/z3w8fbk229m8qmljxgp0m8q1g80dmnc3-xrlinuxdriver-2.10.0.drv
error: Cannot build '/nix/store/bh90az75pzsfrsr13fm1njnyy0glrcg6-hwdb.bin.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/8r0b77nj0i5q2zjvc7n42jxn3az33hmm-hwdb.bin
error: Cannot build '/nix/store/w4ixkj6cd488dcsqy5wjwhmry7ndf8x1-udev-rules.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/b4nwaw6b7qmh5bbg6by9grik0ax4bca9-udev-rules
error: Cannot build '/nix/store/p3dkm7j98lpdhgirh872mxvkp9ff7gnn-etc.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/jaaawb6nnnh11mn4dcl04s4jy7y0qy31-etc
error: Cannot build '/nix/store/5amj4s62a7rnm6w2cdxy111cvnkdl6nf-nixos-system-ufp-26.05.20260814.02e0898.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/x7ic7h611gzz7q35gipkyk0ajjq9c2hz-nixos-system-ufp-26.05.20260814.02e0898
Command 'nix --extra-experimental-features 'nix-command flakes' build --print-out-paths '.#nixosConfigurations."ufp".config.system.build.toplevel' --no-link' returned non-zero exit status 1.

@shymega

shymega commented Aug 16, 2026

Copy link
Copy Markdown
Author

This error looks related to my recent rebasing against main. I will investigate... I'm starting to think it'd be easier to upstream this to Nixpkgs, and then access that derivation from this repo. The submodules both here and in Breezy add a level of complexity that Nix doesn't currently cope well with currently.

@shymega
shymega force-pushed the shymega/nix-flake-support branch from b9f38ee to 470fc26 Compare August 16, 2026 21:24
@shymega

shymega commented Aug 16, 2026

Copy link
Copy Markdown
Author

OK, something in the submodule changed. Fixed that now.

@signaleleven Can you try again?

@shymega
shymega force-pushed the shymega/nix-flake-support branch from 470fc26 to 2042249 Compare August 16, 2026 21:43
@shymega
shymega force-pushed the shymega/nix-flake-support branch from 2042249 to 3b52279 Compare September 12, 2026 23:27
@shymega

shymega commented Sep 12, 2026

Copy link
Copy Markdown
Author

Ready for review and testing.

I used AI to quickly wrap this up, as it's been pending for a long time.

@shymega
shymega force-pushed the shymega/nix-flake-support branch 2 times, most recently from b4cdbc0 to 55b1102 Compare September 16, 2026 22:32
@shymega
shymega force-pushed the shymega/nix-flake-support branch 3 times, most recently from 4ace8e4 to 5426855 Compare September 26, 2026 19:14
shymega and others added 4 commits November 21, 2026 11:14
This commit consists of the following changes:

- `default.nix`/`shell.nix`
  This allows for legacy Nix tooling like `nix-build`/`nix-shell` to work.
- `flake.nix`
  This is for the (new) Nix Flake support.
- `flake.lock`
  As above, but for tracking Flake inputs.
- `.envrc`
  This allows for a fully self-contained developer environment to be
  setup with Nix.
- `.nix/XRLinuxDriver/default.nix`
  This derives from @johnrizzo1's Nix package for the Nix Flake, which were
  REALLY helpful for me.

Closes: wheaney#38

Co-authored-by: John Rizzo <johnrizzo1@gmail.com>
Assisted-by: Claude <noreply@anthropic.com>
Adds jobs to build the package and validate the flake on PRs/pushes,
plus a scheduled job to update the flake inputs weekly, pushing
straight to main.

Assisted-by: Claude <noreply@anthropic.com>
Documents the flake's outputs, inputs, the SSH-submodule fetch
caveat, and the CI update job. Linked from docs/index.md.

Assisted-by: Claude <noreply@anthropic.com>
Covers installing the package as a flake input or a plain tarball,
each either imperatively via nix profile/nix-env or via the overlay.

Assisted-by: Claude <noreply@anthropic.com>
@shymega
shymega force-pushed the shymega/nix-flake-support branch from 5426855 to 54d1fc8 Compare November 21, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

6 participants