Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 124 lines 3.0 kB view raw
1{ 2 stdenv, 3 config, 4 lib, 5 fetchFromGitHub, 6 cmake, 7 libusb1, 8 nlohmann_json, 9 ninja, 10 pkg-config, 11 gcc, 12 libgbm, 13 gtk3, 14 glfw, 15 libGLU, 16 curl, 17 cudaSupport ? config.cudaSupport, 18 cudaPackages ? { }, 19 enablePython ? false, 20 pythonPackages ? null, 21 enableGUI ? false, 22}: 23 24assert cudaSupport -> (cudaPackages ? cudatoolkit && cudaPackages.cudatoolkit != null); 25assert enablePython -> pythonPackages != null; 26 27stdenv.mkDerivation rec { 28 pname = "librealsense"; 29 version = "2.56.3"; 30 31 outputs = [ 32 "out" 33 "dev" 34 ]; 35 36 src = fetchFromGitHub { 37 owner = "IntelRealSense"; 38 repo = pname; 39 rev = "v${version}"; 40 sha256 = "sha256-Stx337mGcpMCg9DlZmvX4LPQmCSzLRFcUQPxaD/Y0Ds="; 41 }; 42 43 buildInputs = 44 [ 45 libusb1 46 gcc.cc.lib 47 nlohmann_json 48 ] 49 ++ lib.optionals cudaSupport [ cudaPackages.cuda_cudart ] 50 ++ lib.optionals enablePython ( 51 with pythonPackages; 52 [ 53 python 54 pybind11 55 ] 56 ) 57 ++ lib.optionals enableGUI [ 58 libgbm 59 gtk3 60 glfw 61 libGLU 62 curl 63 ]; 64 65 patches = [ 66 ./py_pybind11_no_external_download.patch 67 ./install-presets.patch 68 ]; 69 70 postPatch = '' 71 # use nixpkgs nlohmann_json instead of fetching it 72 substituteInPlace third-party/CMakeLists.txt \ 73 --replace-fail \ 74 'include(CMake/external_json.cmake)' \ 75 'find_package(nlohmann_json 3.11.3 REQUIRED)' 76 ''; 77 78 nativeBuildInputs = 79 [ 80 cmake 81 ninja 82 pkg-config 83 ] 84 ++ lib.optionals cudaSupport [ 85 cudaPackages.cuda_nvcc 86 ]; 87 88 cmakeFlags = 89 [ 90 "-DBUILD_EXAMPLES=ON" 91 "-DBUILD_GRAPHICAL_EXAMPLES=${lib.boolToString enableGUI}" 92 "-DBUILD_GLSL_EXTENSIONS=${lib.boolToString enableGUI}" 93 "-DCHECK_FOR_UPDATES=OFF" # activated by BUILD_GRAPHICAL_EXAMPLES, will make it download and compile libcurl 94 ] 95 ++ lib.optionals enablePython [ 96 "-DBUILD_PYTHON_BINDINGS:bool=true" 97 "-DXXNIX_PYTHON_SITEPACKAGES=${placeholder "out"}/${pythonPackages.python.sitePackages}" 98 ] 99 ++ lib.optional cudaSupport "-DBUILD_WITH_CUDA:bool=true"; 100 101 # ensure python package contains its __init__.py. for some reason the install 102 # script does not do this, and it's questionable if intel knows it should be 103 # done 104 # ( https://github.com/IntelRealSense/meta-intel-realsense/issues/20 ) 105 postInstall = 106 '' 107 substituteInPlace $out/lib/cmake/realsense2/realsense2Targets.cmake \ 108 --replace-fail "\''${_IMPORT_PREFIX}/include" "$dev/include" 109 '' 110 + lib.optionalString enablePython '' 111 cp ../wrappers/python/pyrealsense2/__init__.py $out/${pythonPackages.python.sitePackages}/pyrealsense2 112 ''; 113 114 meta = with lib; { 115 description = "Cross-platform library for Intel® RealSense depth cameras (D400 series and the SR300)"; 116 homepage = "https://github.com/IntelRealSense/librealsense"; 117 license = licenses.asl20; 118 maintainers = with maintainers; [ 119 brian-dawn 120 pbsds 121 ]; 122 platforms = platforms.unix; 123 }; 124}