|
| 1 | +{ |
| 2 | + # Core inputs |
| 3 | + self, |
| 4 | + lib, |
| 5 | + pkgs, |
| 6 | + stdenv, |
| 7 | + autoPatchelfHook, |
| 8 | + # xrDriver deps |
| 9 | + libusb1, |
| 10 | + curl, |
| 11 | + openssl, |
| 12 | + libevdev, |
| 13 | + json_c, |
| 14 | + hidapi, |
| 15 | + wayland, |
| 16 | + cmake, |
| 17 | + pkg-config, |
| 18 | + python3, |
| 19 | + libffi, |
| 20 | + systemd, |
| 21 | + makeWrapper, |
| 22 | + jq, |
| 23 | + # nrealAirLinuxDriver deps |
| 24 | + rustPlatform, |
| 25 | + rustc, |
| 26 | + cargo, |
| 27 | + ... |
| 28 | +}: |
| 29 | +let |
| 30 | + arch = |
| 31 | + let |
| 32 | + inherit (pkgs.stdenv.hostPlatform) isx86_64 isLinux isAarch64; |
| 33 | + in |
| 34 | + if isAarch64 && isLinux then |
| 35 | + "aarch64" |
| 36 | + else if isx86_64 && isLinux then |
| 37 | + "x86_64" |
| 38 | + else |
| 39 | + throw "Unsupported system ${pkgs.stdenv.hostPlatform.system}"; |
| 40 | +in |
| 41 | +stdenv.mkDerivation (finalAttrs: { |
| 42 | + pname = "xrlinuxdriver"; |
| 43 | + version = "2.0.5"; |
| 44 | + |
| 45 | + src = lib.cleanSourceWith { |
| 46 | + src = self; |
| 47 | + name = "${finalAttrs.pname}-src"; |
| 48 | + }; |
| 49 | + |
| 50 | + cargoRoot = "modules/xrealInterfaceLibrary/interface_lib/modules/xreal_one_driver"; |
| 51 | + |
| 52 | + cargoDeps = rustPlatform.importCargoLock { |
| 53 | + lockFile = "${finalAttrs.src}/${finalAttrs.cargoRoot}/Cargo.lock"; |
| 54 | + }; |
| 55 | + |
| 56 | + nativeBuildInputs = |
| 57 | + let |
| 58 | + pythonEnv = python3.withPackages (ps: [ ps.pyyaml ]); |
| 59 | + in |
| 60 | + [ |
| 61 | + cmake |
| 62 | + pkg-config |
| 63 | + pythonEnv |
| 64 | + autoPatchelfHook |
| 65 | + rustPlatform.cargoSetupHook |
| 66 | + rustc |
| 67 | + cargo |
| 68 | + makeWrapper |
| 69 | + ]; |
| 70 | + buildInputs = [ |
| 71 | + curl |
| 72 | + hidapi |
| 73 | + json_c |
| 74 | + libevdev |
| 75 | + libffi |
| 76 | + libusb1 |
| 77 | + openssl |
| 78 | + systemd |
| 79 | + wayland |
| 80 | + ]; |
| 81 | + |
| 82 | + # The vendor .so blobs and hidapi-hidraw need libudev at link time |
| 83 | + NIX_LDFLAGS = "-ludev"; |
| 84 | + |
| 85 | + autoPatchelfIgnoreMissingDeps = [ "libopencv_*" ]; |
| 86 | + |
| 87 | + installPhase = '' |
| 88 | + runHook preInstall |
| 89 | +
|
| 90 | + # Main binary |
| 91 | + install -Dm755 xrDriver $out/bin/xrDriver |
| 92 | +
|
| 93 | + # Vendor SDK shared libraries |
| 94 | + mkdir -p $out/lib |
| 95 | + for so in $src/lib/${arch}/*.so; do |
| 96 | + [ -f "$so" ] && install -Dm755 "$so" $out/lib/$(basename "$so") |
| 97 | + done |
| 98 | + if [ -d "$src/lib/${arch}/viture" ]; then |
| 99 | + for so in $src/lib/${arch}/viture/*.so*; do |
| 100 | + [ -f "$so" ] && install -Dm755 "$so" $out/lib/$(basename "$so") |
| 101 | + done |
| 102 | + fi |
| 103 | +
|
| 104 | + # Install hidapi shared libs built during CMake |
| 105 | + find . -name 'libhidapi*.so*' \( -type f -o -type l \) | while read -r f; do |
| 106 | + cp -a "$f" $out/lib/ |
| 107 | + done |
| 108 | +
|
| 109 | + patchelf --set-rpath "$out/lib:${ |
| 110 | + lib.makeLibraryPath [ |
| 111 | + systemd |
| 112 | + stdenv.cc.cc.lib |
| 113 | + curl |
| 114 | + openssl |
| 115 | + json_c |
| 116 | + libusb1 |
| 117 | + libevdev |
| 118 | + wayland |
| 119 | + ] |
| 120 | + }" $out/bin/xrDriver |
| 121 | +
|
| 122 | + # CLI tool |
| 123 | + install -Dm755 $src/bin/xr_driver_cli $out/bin/xr_driver_cli |
| 124 | + wrapProgram $out/bin/xr_driver_cli \ |
| 125 | + --prefix PATH : ${ |
| 126 | + lib.makeBinPath [ |
| 127 | + jq |
| 128 | + curl |
| 129 | + ] |
| 130 | + } |
| 131 | +
|
| 132 | + # Udev rules |
| 133 | + mkdir -p $out/lib/udev/rules.d |
| 134 | + cp $src/udev/*.rules $out/lib/udev/rules.d |
| 135 | +
|
| 136 | + # Systemd user service |
| 137 | + install -Dm644 $src/systemd/xr-driver.service $out/lib/systemd/user/xr-driver.service |
| 138 | + substituteInPlace $out/lib/systemd/user/xr-driver.service \ |
| 139 | + --replace-fail '{ld_library_path}' "$out/lib" \ |
| 140 | + --replace-fail '{bin_dir}' "$out/bin" |
| 141 | +
|
| 142 | + runHook postInstall |
| 143 | + ''; |
| 144 | + |
| 145 | + doInstallCheck = false; |
| 146 | + # The default release is a script which will do an impure download |
| 147 | + # just ensure that the application can run without network |
| 148 | + |
| 149 | + meta = { |
| 150 | + homepage = "https://github.com/wheaney/XRLinuxDriver"; |
| 151 | + license = lib.licenses.mit; |
| 152 | + description = "Linux service for interacting with XR devices."; |
| 153 | + mainProgram = "xrDriver"; |
| 154 | + maintainers = with lib.maintainers; [ shymega ]; |
| 155 | + platforms = lib.platforms.linux; |
| 156 | + }; |
| 157 | +}) |
0 commit comments