|
| 1 | +{ |
| 2 | + self, |
| 3 | + lib, |
| 4 | + pkgs, |
| 5 | + stdenv, |
| 6 | + fetchFromGitLab, |
| 7 | + libusb1, |
| 8 | + curl, |
| 9 | + openssl, |
| 10 | + libevdev, |
| 11 | + json_c, |
| 12 | + hidapi, |
| 13 | + wayland, |
| 14 | + cmake, |
| 15 | + pkg-config, |
| 16 | + python3, |
| 17 | + libffi, |
| 18 | + autoPatchelfHook, |
| 19 | + ... |
| 20 | +}: |
| 21 | +let |
| 22 | + pythonEnv = python3.withPackages (ps: [ ps.pyyaml ]); |
| 23 | + commonBuildInputs = [ |
| 24 | + curl |
| 25 | + hidapi |
| 26 | + json_c |
| 27 | + libevdev |
| 28 | + libffi |
| 29 | + libusb1 |
| 30 | + openssl |
| 31 | + stdenv.cc.cc.lib |
| 32 | + wayland |
| 33 | + ]; |
| 34 | + arch = |
| 35 | + if pkgs.system == "aarch64-linux" then |
| 36 | + "aarch64" |
| 37 | + else if pkgs.system == "x86_64-linux" then |
| 38 | + "x86_64" |
| 39 | + else |
| 40 | + throw "Unsupported system ${pkgs.system}"; |
| 41 | +in |
| 42 | +stdenv.mkDerivation rec { |
| 43 | + pname = "xrlinuxdriver"; |
| 44 | + version = "0.12.0.1"; |
| 45 | + |
| 46 | + srcs = [ |
| 47 | + (fetchFromGitLab rec { |
| 48 | + domain = "gitlab.com"; |
| 49 | + owner = "TheJackiMonster"; |
| 50 | + repo = "nrealAirLinuxDriver"; |
| 51 | + rev = "3225fcc575e19a8407d5019903567cff1c3ed1a8"; |
| 52 | + hash = "sha256-NRbcANt/CqREQZoYIYtTGVbvkZ7uo2Tm90s6prlsrQE="; |
| 53 | + fetchSubmodules = true; |
| 54 | + name = "${repo}-src"; |
| 55 | + }) |
| 56 | + (lib.cleanSourceWith { |
| 57 | + src = self; |
| 58 | + name = "${pname}-src"; |
| 59 | + }) |
| 60 | + ]; |
| 61 | + sourceRoot = "."; |
| 62 | + postUnpack = |
| 63 | + let |
| 64 | + nrealAirLinuxDriver = (builtins.elemAt srcs 0).name; |
| 65 | + xrlinuxdriver = (builtins.elemAt srcs 1).name; |
| 66 | + in |
| 67 | + '' |
| 68 | + cp -R ${xrlinuxdriver}/ $sourceRoot/xrlinuxdriver |
| 69 | + cp -R ${nrealAirLinuxDriver}/* $sourceRoot/xrlinuxdriver/modules/xrealInterfaceLibrary |
| 70 | + chmod -R u+w $sourceRoot/xrlinuxdriver |
| 71 | + ''; |
| 72 | + |
| 73 | + nativeBuildInputs = [ |
| 74 | + cmake |
| 75 | + pkg-config |
| 76 | + pythonEnv |
| 77 | + autoPatchelfHook |
| 78 | + ]; |
| 79 | + buildInputs = commonBuildInputs; |
| 80 | + |
| 81 | + cmakeFlags = [ |
| 82 | + "-DCMAKE_SKIP_RPATH=ON" |
| 83 | + "-DXRLINUXDRIVER_ALLOW_SUBMODULES=OFF" |
| 84 | + ]; |
| 85 | + cmakeBuildDir = "xrlinuxdriver/build"; |
| 86 | + cmakeBuildType = "RelWithDebInfo"; |
| 87 | + |
| 88 | + postPatch = |
| 89 | + let |
| 90 | + root = "$sourceRoot/xrlinuxdriver"; |
| 91 | + in |
| 92 | + '' |
| 93 | + substituteInPlace ${root}/systemd/xr-driver.service \ |
| 94 | + --replace-fail "ExecStart={bin_dir}/${meta.mainProgram}" "ExecStart=$out/bin/${meta.mainProgram}" \ |
| 95 | + --replace-fail "{ld_library_path}" "$out/usr/lib/${arch}" |
| 96 | + ''; |
| 97 | + |
| 98 | + installPhase = |
| 99 | + let |
| 100 | + root = "$sourceRoot/xrlinuxdriver"; |
| 101 | + in |
| 102 | + '' |
| 103 | + mkdir -p $out/bin $out/usr/lib/systemd/user $out/usr/lib/udev/rules.d $out/usr/lib/${arch} |
| 104 | + cp ${meta.mainProgram} ../bin/xr_driver_cli ../bin/xr_driver_verify $out/bin |
| 105 | + cp ../udev/* $out/usr/lib/udev/rules.d/ |
| 106 | + cp ../lib/${arch}/* $out/usr/lib/${arch}/ |
| 107 | + cp ${hidapi}/lib/libhidapi-hidraw.so.0 $out/usr/lib/ |
| 108 | + cp ../systemd/xr-driver.service $out/usr/lib/systemd/user/ |
| 109 | + ''; |
| 110 | + |
| 111 | + preBuild = '' |
| 112 | + addAutoPatchelfSearchPath $out/usr/lib/${arch} |
| 113 | + ''; |
| 114 | + |
| 115 | + doInstallCheck = false; |
| 116 | + # The default release is a script which will do an impure download |
| 117 | + # just ensure that the application can run without network |
| 118 | + |
| 119 | + meta = with lib; { |
| 120 | + homepage = "https://github.com/wheaney/XRLinuxDriver"; |
| 121 | + license = licenses.mit; |
| 122 | + description = "Linux service for interacting with XR devices."; |
| 123 | + mainProgram = "xrDriver"; |
| 124 | + maintainers = with maintainers; [ shymega ]; |
| 125 | + platforms = platforms.linux; |
| 126 | + }; |
| 127 | +} |
0 commit comments