Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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 libusb1 45 gcc.cc.lib 46 nlohmann_json 47 ] 48 ++ lib.optionals cudaSupport [ cudaPackages.cuda_cudart ] 49 ++ lib.optionals enablePython ( 50 with pythonPackages; 51 [ 52 python 53 pybind11 54 ] 55 ) 56 ++ lib.optionals enableGUI [ 57 libgbm 58 gtk3 59 glfw 60 libGLU 61 curl 62 ]; 63 64 patches = [ 65 ./py_pybind11_no_external_download.patch 66 ./install-presets.patch 67 ]; 68 69 postPatch = '' 70 # use nixpkgs nlohmann_json instead of fetching it 71 substituteInPlace third-party/CMakeLists.txt \ 72 --replace-fail \ 73 'include(CMake/external_json.cmake)' \ 74 'find_package(nlohmann_json 3.11.3 REQUIRED)' 75 ''; 76 77 nativeBuildInputs = [ 78 cmake 79 ninja 80 pkg-config 81 ] 82 ++ lib.optionals cudaSupport [ 83 cudaPackages.cuda_nvcc 84 ]; 85 86 cmakeFlags = [ 87 "-DBUILD_EXAMPLES=ON" 88 "-DBUILD_GRAPHICAL_EXAMPLES=${lib.boolToString enableGUI}" 89 "-DBUILD_GLSL_EXTENSIONS=${lib.boolToString enableGUI}" 90 "-DCHECK_FOR_UPDATES=OFF" # activated by BUILD_GRAPHICAL_EXAMPLES, will make it download and compile libcurl 91 ] 92 ++ lib.optionals enablePython [ 93 "-DBUILD_PYTHON_BINDINGS:bool=true" 94 "-DXXNIX_PYTHON_SITEPACKAGES=${placeholder "out"}/${pythonPackages.python.sitePackages}" 95 ] 96 ++ lib.optional cudaSupport "-DBUILD_WITH_CUDA:bool=true"; 97 98 # ensure python package contains its __init__.py. for some reason the install 99 # script does not do this, and it's questionable if intel knows it should be 100 # done 101 # ( https://github.com/IntelRealSense/meta-intel-realsense/issues/20 ) 102 postInstall = '' 103 substituteInPlace $out/lib/cmake/realsense2/realsense2Targets.cmake \ 104 --replace-fail "\''${_IMPORT_PREFIX}/include" "$dev/include" 105 '' 106 + lib.optionalString enablePython '' 107 cp ../wrappers/python/pyrealsense2/__init__.py $out/${pythonPackages.python.sitePackages}/pyrealsense2 108 ''; 109 110 meta = with lib; { 111 description = "Cross-platform library for Intel® RealSense depth cameras (D400 series and the SR300)"; 112 homepage = "https://github.com/IntelRealSense/librealsense"; 113 license = licenses.asl20; 114 maintainers = with maintainers; [ 115 brian-dawn 116 pbsds 117 ]; 118 platforms = platforms.unix; 119 }; 120}