|
2 | 2 | lib, |
3 | 3 | fetchFromGitHub, |
4 | 4 | fetchpatch2, |
| 5 | + jq, |
5 | 6 | python3, |
6 | 7 | python3Packages, |
7 | 8 | enableContrib ? true, |
8 | 9 | enableCuda ? false, |
9 | 10 | apply_patch_py, |
| 11 | + sysprof, |
| 12 | + libsysprof-capture, |
10 | 13 | ... |
11 | 14 | }: |
12 | 15 | let |
|
24 | 27 | }).overrideAttrs |
25 | 28 | ( |
26 | 29 | finalAttrs: previousAttrs: { |
27 | | - # Explanation: nixpkgs's opencv-4.12.0 is not (yet) supported by evision-0.2.14 |
28 | | - # and more specifically, gen2.py's flags where changed substantialy in opencv-4.12.0: |
29 | | - # https://github.com/opencv/opencv/pull/27325 |
30 | | - # |
31 | | - # ToDo(maintenance/update): once evision supports opencv-4.12.0 |
32 | | - # this version may be able to match nixpkgs' version. |
33 | | - version = "4.11.0"; |
| 30 | + # Explanation: match evision-0.2.17's `OPENCV_VER` |
| 31 | + version = "4.13.0"; |
34 | 32 |
|
35 | 33 | src = fetchFromGitHub { |
36 | 34 | owner = "opencv"; |
37 | 35 | repo = "opencv"; |
38 | 36 | tag = finalAttrs.version; |
39 | | - hash = "sha256-oiU4CwoMfuUbpDtujJVTShMCzc5GsnIaprC4DzkSzEM="; |
| 37 | + hash = "sha256-h9gpSf+xf/OafQSCYq3JYBt/ShnxafSG7WbxesTjM/A="; |
40 | 38 | }; |
41 | | - patches = [ |
42 | | - # ToDo(maintenance/update): remove this patch on opencv-4.12.0 |
43 | | - # |
44 | | - # Explanation: frontporting opencv-4.11.0 to nixos-25.11 |
45 | | - # stumbles on the new ffmpeg-8 in nixos-25.11. |
46 | | - # Issue: https://github.com/opencv/opencv/issues/27688 |
47 | | - (fetchpatch2 { |
48 | | - name = "FFmpeg 8.0 support"; |
49 | | - url = "https://github.com/opencv/opencv/pull/27691.patch"; |
50 | | - hash = "sha256-wRL2mLxclO5NpWg1rBKso/8oTO13I5XJ6pEW+Y3PsPc="; |
51 | | - }) |
| 39 | + /* |
| 40 | + patches = [ |
| 41 | + # ToDo(maintenance/update): remove this patch on opencv-4.12.0 |
| 42 | + # |
| 43 | + # Explanation: frontporting opencv-4.11.0 to nixos-25.11 |
| 44 | + # stumbles on the new ffmpeg-8 in nixos-25.11. |
| 45 | + # Issue: https://github.com/opencv/opencv/issues/27688 |
| 46 | + (fetchpatch2 { |
| 47 | + name = "FFmpeg 8.0 support"; |
| 48 | + url = "https://github.com/opencv/opencv/pull/27691.patch"; |
| 49 | + hash = "sha256-wRL2mLxclO5NpWg1rBKso/8oTO13I5XJ6pEW+Y3PsPc="; |
| 50 | + }) |
52 | 51 |
|
53 | | - # ToDo(maintenance/update): remove this patch on opencv-4.12.0 |
54 | | - # |
55 | | - # Explanation: frontporting opencv-4.11.0 to nixos-25.11 |
56 | | - # stumbles on the new cmake-4 in nixos-25.11, |
57 | | - # which deprecated too old cmake_minimum_required() in CMakeLists.txt |
58 | | - # that BUILD_JASPER=ON + WITH_ADE=ON still expects. |
59 | | - (fetchpatch2 { |
60 | | - name = "Fix configuring with CMake version 4"; |
61 | | - url = "https://github.com/opencv/opencv/pull/27192.patch"; |
62 | | - hash = "sha256-1yzOU9xR5LmdxzczM4sXuDyZ/DCLJApAQMUQE2mmAlg="; |
63 | | - }) |
64 | | - ]; |
| 52 | + # ToDo(maintenance/update): remove this patch on opencv-4.12.0 |
| 53 | + # |
| 54 | + # Explanation: frontporting opencv-4.11.0 to nixos-25.11 |
| 55 | + # stumbles on the new cmake-4 in nixos-25.11, |
| 56 | + # which deprecated too old cmake_minimum_required() in CMakeLists.txt |
| 57 | + # that BUILD_JASPER=ON + WITH_ADE=ON still expects. |
| 58 | + (fetchpatch2 { |
| 59 | + name = "Fix configuring with CMake version 4"; |
| 60 | + url = "https://github.com/opencv/opencv/pull/27192.patch"; |
| 61 | + hash = "sha256-1yzOU9xR5LmdxzczM4sXuDyZ/DCLJApAQMUQE2mmAlg="; |
| 62 | + }) |
| 63 | + ]; |
| 64 | + */ |
65 | 65 |
|
66 | | - # Explanation: nixos-25.11#opencv4's contribSrc's version |
| 66 | + # Explanation: nixos-26.05#opencv4's contribSrc's version |
67 | 67 | # is not using finalAttrs.version |
68 | 68 | # so override postUnpack with the correct one. |
69 | 69 | opencvContribSrc = fetchFromGitHub { |
70 | 70 | owner = "opencv"; |
71 | 71 | repo = "opencv_contrib"; |
72 | 72 | tag = finalAttrs.version; |
73 | | - hash = "sha256-YNd96qFJ8SHBgDEEsoNps888myGZdELbbuYCae9pW3M="; |
| 73 | + hash = "sha256-8YRCq1H9afb1a0pVevH0x61SMW4dTpLAno/P9A6bOIg="; |
74 | 74 | }; |
75 | 75 | postUnpack = '' |
76 | | - cp --no-preserve=mode -r "${finalAttrs.opencvContribSrc}/modules" "$NIX_BUILD_TOP/source/opencv_contrib" |
| 76 | + cp --no-preserve=mode -r "${finalAttrs.opencvContribSrc}/modules" "$sourceRoot/opencv_contrib" |
| 77 | + # Required for apply_patch to find `opencv_contrib`, |
| 78 | + # eg. for `patch_ocr_tesseract_run_with_components` |
| 79 | + mkdir $sourceRoot/opencv_contrib-${finalAttrs.version} |
| 80 | + ln -s ../opencv_contrib $sourceRoot/opencv_contrib-${finalAttrs.version}/modules |
77 | 81 | ''; |
78 | 82 |
|
79 | | - nativeBuildInputs = previousAttrs.nativeBuildInputs or [ ] ++ [ python3 ]; |
| 83 | + nativeBuildInputs = previousAttrs.nativeBuildInputs or [ ] ++ [ |
| 84 | + jq |
| 85 | + python3 |
| 86 | + ]; |
| 87 | + buildInputs = previousAttrs.buildInputs or [ ] ++ [ |
| 88 | + sysprof |
| 89 | + libsysprof-capture |
| 90 | + ]; |
80 | 91 |
|
81 | 92 | # Explanation(compatibility): evision has an unusual way to patch opencv: |
82 | 93 | # a Python script. |
|
190 | 201 | # > from the python module in the OpenCV repo so that they output header files |
191 | 202 | # > that can be used in Elixir bindings |
192 | 203 | # |
193 | | - # For that evision needs a headers.txt generated for Python |
| 204 | + # For that evision needs a gen_python_config.json generated for Python |
194 | 205 | # listing the .hpp files to consider. |
195 | 206 | # Unfortunately those files are absolute path in $NIX_BUILD_TOP, |
196 | | - # they need to be fixed to point to $out, and installed there. |
| 207 | + # they need to be fixed to point to somewhere in $out. |
| 208 | + # Note that $out/include/ cannot be used reliably |
| 209 | + # since some headers are not installed at all yet required by evision. |
197 | 210 | postInstall = previousAttrs.postInstall or "" + '' |
198 | | - OPENCV_HEADERS_TXT=$NIX_BUILD_TOP/$sourceRoot/build/modules/python_bindings_generator/headers.txt |
| 211 | + pushd "$NIX_BUILD_TOP/$sourceRoot" |
| 212 | + find . \( -name "*.hpp" -or -name "*.h" \) \ |
| 213 | + -exec sh -xc 'install -Dm644 -t$out/source/''${1%/*} $1' -- {} \; |
| 214 | + OPENCV_HEADERS="build/modules/python_bindings_generator/gen_python_config.json" |
199 | 215 | mkdir -p $out/modules/python_bindings_generator/ |
200 | | - while IFS= read -r header; do |
201 | | - h=$(realpath --relative-to "$NIX_BUILD_TOP" "$header") |
202 | | - install -Dm644 "$header" "$out/$h" |
203 | | - echo "$out/$h" |
204 | | - done <"$OPENCV_HEADERS_TXT" >$out/modules/python_bindings_generator/headers${lib.optionalString enableContrib "-contrib"}.txt |
| 216 | + jq '.headers |= map(sub("^'"$NIX_BUILD_TOP"'"; "'$out'"))' \ |
| 217 | + <"$OPENCV_HEADERS" \ |
| 218 | + >$out/modules/python_bindings_generator/gen_python_config${lib.optionalString enableContrib "-contrib"}.json |
| 219 | + popd |
205 | 220 | ''; |
206 | 221 | } |
207 | 222 | ) |
0 commit comments