|
| 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 | + # nrealAirLinuxDriver deps |
| 22 | + rustPlatform, |
| 23 | + rustc, |
| 24 | + cargo, |
| 25 | + ... |
| 26 | +}: let |
| 27 | + pythonEnv = python3.withPackages (ps: [ps.pyyaml]); |
| 28 | + arch = |
| 29 | + if pkgs.stdenv.hostPlatform.system == "aarch64-linux" |
| 30 | + then "aarch64" |
| 31 | + else if pkgs.stdenv.hostPlatform.system == "x86_64-linux" |
| 32 | + then "x86_64" |
| 33 | + else throw "Unsupported system ${pkgs.stdenv.hostPlatform.system}"; |
| 34 | +in |
| 35 | + stdenv.mkDerivation rec { |
| 36 | + pname = "xrlinuxdriver"; |
| 37 | + version = "2.0.5"; |
| 38 | + |
| 39 | + src = lib.cleanSourceWith { |
| 40 | + src = self; |
| 41 | + name = "${pname}-src"; |
| 42 | + }; |
| 43 | + cargoRoot = "modules/xrealInterfaceLibrary/interface_lib/modules/xreal_one_driver"; |
| 44 | + |
| 45 | + cargoDeps = rustPlatform.fetchCargoVendor rec { |
| 46 | + name = "xrealInterfaceLibrary-${version}-cargo-deps"; |
| 47 | + inherit src; |
| 48 | + sourceRoot = cargoRoot; |
| 49 | + hash = "sha256-ISgdmB5MEZ3P9KWCeURzr1PbIeb4BOCf1Z+Rs8wnJdM="; |
| 50 | + }; |
| 51 | + |
| 52 | + nativeBuildInputs = [ |
| 53 | + cmake |
| 54 | + pkg-config |
| 55 | + pythonEnv |
| 56 | + autoPatchelfHook |
| 57 | + rustPlatform.cargoSetupHook |
| 58 | + rustc |
| 59 | + cargo |
| 60 | + ]; |
| 61 | + buildInputs = [ |
| 62 | + curl |
| 63 | + hidapi |
| 64 | + json_c |
| 65 | + libevdev |
| 66 | + libffi |
| 67 | + libusb1 |
| 68 | + openssl |
| 69 | + stdenv.cc.cc.lib |
| 70 | + systemd |
| 71 | + wayland |
| 72 | + ]; |
| 73 | + |
| 74 | + cmakeFlags = [ |
| 75 | + "-DCMAKE_BUILD_TYPE=Release" |
| 76 | + "-DCMAKE_SKIP_BUILD_RPATH=OFF" |
| 77 | + "-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON" |
| 78 | + "-DCMAKE_INSTALL_RPATH=$ORIGIN/../lib" |
| 79 | + "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON" |
| 80 | + ]; |
| 81 | + cmakeBuildDir = "build"; |
| 82 | + cmakeBuildType = "RelWithDebInfo"; |
| 83 | + |
| 84 | + preConfigure = '' |
| 85 | + autoPatchelf lib/${arch} |
| 86 | + addAutoPatchelfSearchPath $out/lib/${arch} |
| 87 | + ''; |
| 88 | + |
| 89 | + postPatch = '' |
| 90 | + # Make git submodule commands do nothing |
| 91 | + substituteInPlace CMakeLists.txt \ |
| 92 | + --replace-fail "execute_process(COMMAND git submodule update --init --recursive" "execute_process(COMMAND echo \"Skipping git submodule update\"" |
| 93 | + ''; |
| 94 | + |
| 95 | + fixupPhase = '' |
| 96 | + # Fix RPATH issues |
| 97 | + patchelf --set-rpath '$ORIGIN/../lib' $out/bin/xrDriver |
| 98 | + ''; |
| 99 | + |
| 100 | + installPhase = '' |
| 101 | + mkdir -p $out/bin $out/lib/systemd/user $out/lib/udev/rules.d $out/lib/${arch} |
| 102 | + install -m755 -t $out/bin xrDriver ../bin/xr_driver_cli ../bin/xr_driver_verify |
| 103 | + cp ../udev/* $out/lib/udev/rules.d/ |
| 104 | + cp -r ../lib/${arch}/* $out/lib/$arch/ |
| 105 | + cp ../systemd/xr-driver.service $out/lib/systemd/user/xr-driver.service |
| 106 | + cp ${hidapi}/lib/libhidapi-hidraw.so.0 $out/lib/ |
| 107 | + substituteInPlace \ |
| 108 | + $out/lib/systemd/user/xr-driver.service \ |
| 109 | + --replace-fail "ExecStart={bin_dir}/xrDriver" "ExecStart=$out/bin/xrDriver" \ |
| 110 | + --replace-fail "{ld_library_path}" "$out/lib/${arch}" |
| 111 | + ''; |
| 112 | + |
| 113 | + doInstallCheck = false; |
| 114 | + # The default release is a script which will do an impure download |
| 115 | + # just ensure that the application can run without network |
| 116 | + |
| 117 | + meta = { |
| 118 | + homepage = "https://github.com/wheaney/XRLinuxDriver"; |
| 119 | + license = lib.licenses.mit; |
| 120 | + description = "Linux service for interacting with XR devices."; |
| 121 | + mainProgram = "xrDriver"; |
| 122 | + maintainers = with lib.maintainers; [shymega]; |
| 123 | + platforms = lib.platforms.linux; |
| 124 | + }; |
| 125 | + } |
0 commit comments