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