From a1180e40d32e45924680af7043cd429c5676bb60 Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Thu, 18 Sep 2025 13:22:14 -0700 Subject: [PATCH] opencv: invalidate Nix store paths used in version_string.inc Signed-off-by: Connor Baker --- ...s.cmake-invalidate-Nix-store-paths-b.patch | 34 +++++++++++++++++++ pkgs/development/libraries/opencv/4.x.nix | 6 +--- 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 pkgs/development/libraries/opencv/0001-cmake-OpenCVUtils.cmake-invalidate-Nix-store-paths-b.patch diff --git a/pkgs/development/libraries/opencv/0001-cmake-OpenCVUtils.cmake-invalidate-Nix-store-paths-b.patch b/pkgs/development/libraries/opencv/0001-cmake-OpenCVUtils.cmake-invalidate-Nix-store-paths-b.patch new file mode 100644 index 000000000000..03f912cef39a --- /dev/null +++ b/pkgs/development/libraries/opencv/0001-cmake-OpenCVUtils.cmake-invalidate-Nix-store-paths-b.patch @@ -0,0 +1,34 @@ +From fcc689e1887bcbeb9d1c4441266a63ea2114ae9f Mon Sep 17 00:00:00 2001 +From: Connor Baker +Date: Thu, 18 Sep 2025 13:15:43 -0700 +Subject: [PATCH] cmake/OpenCVUtils.cmake: invalidate Nix store paths before + including in version_string.inc + +Signed-off-by: Connor Baker +--- + cmake/OpenCVUtils.cmake | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake +index 5886f4f3cb..9f3a3a74e9 100644 +--- a/cmake/OpenCVUtils.cmake ++++ b/cmake/OpenCVUtils.cmake +@@ -956,6 +956,15 @@ function(ocv_output_status msg) + message(WARNING "String to be inserted to version_string.inc has an unexpected line break: '${msg}'") + string(REPLACE "\n" "\\n" msg "${msg}") + endif() ++ # The hash portion of Nix store paths are 32 characters long. Replace them with an invalid hash to avoid bloating ++ # the runtime closure by includnig references to the compiler and other build tools. ++ # https://fzakaria.com/2025/03/28/what-s-in-a-nix-store-path ++ # NOTE: This assumes the name of the Nix store is always /nix/store. ++ # NOTE: The regex [a-z0-9] is larger than Nix's base32, but it simplifies things. ++ # NOTE: This assumes all Nix store paths have additional characters after the hash. ++ # NOTE: CMake doesn't support fixed-length matching. See: ++ # https://cmake.org/cmake/help/latest/command/string.html#regex-specification ++ string(REGEX REPLACE "/nix/store/[a-z0-9]+-" "/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-" msg "${msg}") + set(OPENCV_BUILD_INFO_STR "${OPENCV_BUILD_INFO_STR}\"${msg}\\n\"\n" CACHE INTERNAL "") + endfunction() + +-- +2.48.1 + diff --git a/pkgs/development/libraries/opencv/4.x.nix b/pkgs/development/libraries/opencv/4.x.nix index 26a49c1ae1af..8c169864bab2 100644 --- a/pkgs/development/libraries/opencv/4.x.nix +++ b/pkgs/development/libraries/opencv/4.x.nix @@ -298,6 +298,7 @@ effectiveStdenv.mkDerivation { # Ensures that we use the system OpenEXR rather than the vendored copy of the source included with OpenCV. patches = [ ./cmake-don-t-use-OpenCVFindOpenEXR.patch + ./0001-cmake-OpenCVUtils.cmake-invalidate-Nix-store-paths-b.patch ] ++ optionals enableCuda [ ./cuda_opt_flow.patch @@ -321,11 +322,6 @@ effectiveStdenv.mkDerivation { ${installExtraFiles wechat_qrcode} ''); - postConfigure = '' - [ -e modules/core/version_string.inc ] - echo '"(build info elided)"' > modules/core/version_string.inc - ''; - buildInputs = [ boost gflags