various: extremely lightweight fixes to support FreeBSD build (#387230)

This commit is contained in:
Audrey Dutcher
2025-03-05 16:08:19 -07:00
committed by GitHub
17 changed files with 1586 additions and 1341 deletions
@@ -1,51 +1,85 @@
{ lib
, stdenv
, fetchFromGitHub
, pkg-config
, libtool
, bzip2Support ? true, bzip2
, zlibSupport ? true, zlib
, libX11Support ? !stdenv.hostPlatform.isMinGW, libX11
, libXtSupport ? !stdenv.hostPlatform.isMinGW, libXt
, fontconfigSupport ? true, fontconfig
, freetypeSupport ? true, freetype
, ghostscriptSupport ? false, ghostscript
, libjpegSupport ? true, libjpeg
, djvulibreSupport ? true, djvulibre
, lcms2Support ? true, lcms2
, openexrSupport ? !stdenv.hostPlatform.isMinGW, openexr
, libjxlSupport ? true, libjxl
, libpngSupport ? true, libpng
, liblqr1Support ? true, liblqr1
, librawSupport ? true, libraw
, librsvgSupport ? !stdenv.hostPlatform.isMinGW, librsvg, pango
, libtiffSupport ? true, libtiff
, libxml2Support ? true, libxml2
, openjpegSupport ? !stdenv.hostPlatform.isMinGW, openjpeg
, libwebpSupport ? !stdenv.hostPlatform.isMinGW, libwebp
, libheifSupport ? true, libheif
, fftwSupport ? true, fftw
, potrace
, coreutils
, curl
, ApplicationServices
, Foundation
, testers
, nixos-icons
, perlPackages
, python3
{
lib,
stdenv,
fetchFromGitHub,
pkg-config,
libtool,
bzip2Support ? true,
bzip2,
zlibSupport ? true,
zlib,
libX11Support ? !stdenv.hostPlatform.isMinGW,
libX11,
libXtSupport ? !stdenv.hostPlatform.isMinGW,
libXt,
fontconfigSupport ? true,
fontconfig,
freetypeSupport ? true,
freetype,
ghostscriptSupport ? false,
ghostscript,
libjpegSupport ? true,
libjpeg,
djvulibreSupport ? true,
djvulibre,
lcms2Support ? true,
lcms2,
openexrSupport ? !stdenv.hostPlatform.isMinGW,
openexr,
libjxlSupport ? true,
libjxl,
libpngSupport ? true,
libpng,
liblqr1Support ? true,
liblqr1,
librawSupport ? true,
libraw,
librsvgSupport ? !stdenv.hostPlatform.isMinGW,
librsvg,
pango,
libtiffSupport ? true,
libtiff,
libxml2Support ? true,
libxml2,
openjpegSupport ? !stdenv.hostPlatform.isMinGW,
openjpeg,
libwebpSupport ? !stdenv.hostPlatform.isMinGW,
libwebp,
libheifSupport ? true,
libheif,
fftwSupport ? true,
fftw,
potrace,
coreutils,
curl,
ApplicationServices,
Foundation,
testers,
nixos-icons,
perlPackages,
python3,
}:
assert libXtSupport -> libX11Support;
let
arch =
if stdenv.hostPlatform.system == "i686-linux" then "i686"
else if stdenv.hostPlatform.system == "x86_64-linux" || stdenv.hostPlatform.system == "x86_64-darwin" then "x86-64"
else if stdenv.hostPlatform.system == "armv7l-linux" then "armv7l"
else if stdenv.hostPlatform.system == "aarch64-linux" || stdenv.hostPlatform.system == "aarch64-darwin" then "aarch64"
else if stdenv.hostPlatform.system == "powerpc64le-linux" then "ppc64le"
else null;
if stdenv.hostPlatform.system == "i686-linux" then
"i686"
else if
stdenv.hostPlatform.system == "x86_64-linux" || stdenv.hostPlatform.system == "x86_64-darwin"
then
"x86-64"
else if stdenv.hostPlatform.system == "armv7l-linux" then
"armv7l"
else if
stdenv.hostPlatform.system == "aarch64-linux" || stdenv.hostPlatform.system == "aarch64-darwin"
then
"aarch64"
else if stdenv.hostPlatform.system == "powerpc64le-linux" then
"ppc64le"
else
null;
in
stdenv.mkDerivation (finalAttrs: {
@@ -59,33 +93,44 @@ stdenv.mkDerivation (finalAttrs: {
hash = "sha256-DsJRTLMyjU2mMEGq/2qEJvjdYa698TEZZqkxuWtd/A4=";
};
outputs = [ "out" "dev" "doc" ]; # bin/ isn't really big
outputs = [
"out"
"dev"
"doc"
]; # bin/ isn't really big
outputMan = "out"; # it's tiny
enableParallelBuilding = true;
configureFlags = [
# specify delegates explicitly otherwise `convert` will invoke the build
# coreutils for filetypes it doesn't natively support.
"MVDelegate=${lib.getExe' coreutils "mv"}"
"RMDelegate=${lib.getExe' coreutils "rm"}"
"--with-frozenpaths"
(lib.withFeatureAs (arch != null) "gcc-arch" arch)
(lib.withFeature librsvgSupport "rsvg")
(lib.withFeature librsvgSupport "pango")
(lib.withFeature liblqr1Support "lqr")
(lib.withFeature libjxlSupport "jxl")
(lib.withFeatureAs ghostscriptSupport "gs-font-dir" "${ghostscript.fonts}/share/fonts")
(lib.withFeature ghostscriptSupport "gslib")
(lib.withFeature fftwSupport "fftw")
] ++ lib.optionals stdenv.hostPlatform.isMinGW [
# due to libxml2 being without DLLs ATM
"--enable-static" "--disable-shared"
configureFlags =
[
# specify delegates explicitly otherwise `convert` will invoke the build
# coreutils for filetypes it doesn't natively support.
"MVDelegate=${lib.getExe' coreutils "mv"}"
"RMDelegate=${lib.getExe' coreutils "rm"}"
"--with-frozenpaths"
(lib.withFeatureAs (arch != null) "gcc-arch" arch)
(lib.withFeature librsvgSupport "rsvg")
(lib.withFeature librsvgSupport "pango")
(lib.withFeature liblqr1Support "lqr")
(lib.withFeature libjxlSupport "jxl")
(lib.withFeatureAs ghostscriptSupport "gs-font-dir" "${ghostscript.fonts}/share/fonts")
(lib.withFeature ghostscriptSupport "gslib")
(lib.withFeature fftwSupport "fftw")
]
++ lib.optionals stdenv.hostPlatform.isMinGW [
# due to libxml2 being without DLLs ATM
"--enable-static"
"--disable-shared"
];
nativeBuildInputs = [
pkg-config
libtool
];
nativeBuildInputs = [ pkg-config libtool ];
buildInputs = [ potrace ]
buildInputs =
[ potrace ]
++ lib.optional zlibSupport zlib
++ lib.optional fontconfigSupport fontconfig
++ lib.optional ghostscriptSupport ghostscript
@@ -108,7 +153,8 @@ stdenv.mkDerivation (finalAttrs: {
Foundation
];
propagatedBuildInputs = [ curl ]
propagatedBuildInputs =
[ curl ]
++ lib.optional bzip2Support bzip2
++ lib.optional freetypeSupport freetype
++ lib.optional libjpegSupport libjpeg
@@ -118,24 +164,26 @@ stdenv.mkDerivation (finalAttrs: {
++ lib.optional libwebpSupport libwebp
++ lib.optional fftwSupport fftw;
postInstall = ''
(cd "$dev/include" && ln -s ImageMagick* ImageMagick)
# Q16HDRI = 16 bit quantum depth with HDRI support, and is the default ImageMagick configuration
# If the default is changed, or the derivation is modified to use a different configuration
# this will need to be changed below.
moveToOutput "bin/*-config" "$dev"
moveToOutput "lib/ImageMagick-*/config-Q16HDRI" "$dev" # includes configure params
configDestination=($out/share/ImageMagick-*)
grep -v '/nix/store' $dev/lib/ImageMagick-*/config-Q16HDRI/configure.xml > $configDestination/configure.xml
for file in "$dev"/bin/*-config; do
substituteInPlace "$file" --replace pkg-config \
"PKG_CONFIG_PATH='$dev/lib/pkgconfig' '$(command -v $PKG_CONFIG)'"
done
'' + lib.optionalString ghostscriptSupport ''
for la in $out/lib/*.la; do
sed 's|-lgs|-L${lib.getLib ghostscript}/lib -lgs|' -i $la
done
'';
postInstall =
''
(cd "$dev/include" && ln -s ImageMagick* ImageMagick)
# Q16HDRI = 16 bit quantum depth with HDRI support, and is the default ImageMagick configuration
# If the default is changed, or the derivation is modified to use a different configuration
# this will need to be changed below.
moveToOutput "bin/*-config" "$dev"
moveToOutput "lib/ImageMagick-*/config-Q16HDRI" "$dev" # includes configure params
configDestination=($out/share/ImageMagick-*)
grep -v '/nix/store' $dev/lib/ImageMagick-*/config-Q16HDRI/configure.xml > $configDestination/configure.xml
for file in "$dev"/bin/*-config; do
substituteInPlace "$file" --replace pkg-config \
"PKG_CONFIG_PATH='$dev/lib/pkgconfig' '$(command -v $PKG_CONFIG)'"
done
''
+ lib.optionalString ghostscriptSupport ''
for la in $out/lib/*.la; do
sed 's|-lgs|-L${lib.getLib ghostscript}/lib -lgs|' -i $la
done
'';
passthru.tests = {
version = testers.testVersion { package = finalAttrs.finalPackage; };
@@ -152,9 +200,16 @@ stdenv.mkDerivation (finalAttrs: {
homepage = "http://www.imagemagick.org/";
changelog = "https://github.com/ImageMagick/Website/blob/main/ChangeLog.md";
description = "Software suite to create, edit, compose, or convert bitmap images";
pkgConfigModules = [ "ImageMagick" "MagickWand" ];
platforms = platforms.linux ++ platforms.darwin;
maintainers = with maintainers; [ dotlambda rhendric bloxx12 ];
pkgConfigModules = [
"ImageMagick"
"MagickWand"
];
platforms = platforms.unix;
maintainers = with maintainers; [
dotlambda
rhendric
bloxx12
];
license = licenses.asl20;
mainProgram = "magick";
};
+1 -1
View File
@@ -65,7 +65,7 @@ stdenv.mkDerivation (finalAttrs: {
"alsa"
"alsa-topology"
];
platforms = platforms.linux;
platforms = platforms.linux ++ platforms.freebsd;
maintainers = with maintainers; [ l-as ];
};
})
@@ -35,6 +35,6 @@ stdenv.mkDerivation rec {
license = licenses.bsd3;
maintainers = [ maintainers.roastiek ];
platforms = platforms.linux;
platforms = platforms.linux ++ platforms.freebsd;
};
}
+26 -21
View File
@@ -18,31 +18,36 @@ stdenv.mkDerivation (finalAttrs: {
dontBuild = true;
installPhase = ''
runHook preInstall
installPhase =
''
runHook preInstall
substituteInPlace ucm2/lib/card-init.conf \
--replace-fail "/bin/rm" "${coreutils}/bin/rm" \
--replace-fail "/bin/mkdir" "${coreutils}/bin/mkdir"
substituteInPlace ucm2/lib/card-init.conf \
--replace-fail "/bin/rm" "${coreutils}/bin/rm" \
--replace-fail "/bin/mkdir" "${coreutils}/bin/mkdir"
files=(
"ucm2/HDA/HDA.conf"
"ucm2/codecs/rt715/init.conf"
"ucm2/codecs/rt715-sdca/init.conf"
"ucm2/Intel/cht-bsw-rt5672/cht-bsw-rt5672.conf"
"ucm2/Intel/bytcr-rt5640/bytcr-rt5640.conf"
)
files=(
"ucm2/HDA/HDA.conf"
"ucm2/codecs/rt715/init.conf"
"ucm2/codecs/rt715-sdca/init.conf"
"ucm2/Intel/cht-bsw-rt5672/cht-bsw-rt5672.conf"
"ucm2/Intel/bytcr-rt5640/bytcr-rt5640.conf"
)
for file in "''${files[@]}"; do
substituteInPlace "$file" \
--replace-fail '/sbin/modprobe' '${kmod}/bin/modprobe'
done
''
+ lib.optionalString stdenv.hostPlatform.isLinux ''
for file in "''${files[@]}"; do
substituteInPlace "$file" \
--replace-fail '/sbin/modprobe' '${kmod}/bin/modprobe'
done
''
+ ''
mkdir -p $out/share/alsa
cp -r ucm ucm2 $out/share/alsa
mkdir -p $out/share/alsa
cp -r ucm ucm2 $out/share/alsa
runHook postInstall
'';
runHook postInstall
'';
passthru.updateScript = directoryListingUpdater {
url = "https://www.alsa-project.org/files/pub/lib/";
@@ -59,6 +64,6 @@ stdenv.mkDerivation (finalAttrs: {
license = lib.licenses.bsd3;
maintainers = [ lib.maintainers.roastiek ];
platforms = lib.platforms.linux;
platforms = lib.platforms.linux ++ lib.platforms.freebsd;
};
})
+1 -1
View File
@@ -49,6 +49,6 @@ stdenv.mkDerivation rec {
description = "Minimalist, cross-platform, shared video plugins";
license = licenses.gpl2Plus;
maintainers = [ ];
platforms = platforms.linux ++ platforms.darwin;
platforms = platforms.unix;
};
}
+1
View File
@@ -132,6 +132,7 @@ stdenv.mkDerivation rec {
changelog = "https://git.libcamera.org/libcamera/libcamera.git/tag/?h=${src.rev}";
license = licenses.lgpl2Plus;
maintainers = with maintainers; [ citadelcore ];
platforms = platforms.linux;
badPlatforms = [
# Mandatory shared libraries.
lib.systems.inspect.platformPatterns.isStatic
+1 -1
View File
@@ -53,6 +53,6 @@ stdenv.mkDerivation rec {
description = "Abstraction library for audio visualisations";
homepage = "https://sourceforge.net/projects/libvisual/";
license = lib.licenses.lgpl21Plus;
platforms = lib.platforms.linux;
platforms = lib.platforms.linux ++ lib.platforms.freebsd;
};
}
+3 -6
View File
@@ -56,8 +56,8 @@ stdenv.mkDerivation (finalAttrs: {
hash = "sha256-WLQK7vy34VmgJzppTnRjAcZoSGWVaXQSaGq9An8W0rw=";
})
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
# Disable building of linux-only demos on darwin systems
++ lib.optionals (!stdenv.hostPlatform.isLinux) [
# Disable building of linux-only demos on non-linux systems
./0001-Don-t-build-demos.patch
];
@@ -84,9 +84,6 @@ stdenv.mkDerivation (finalAttrs: {
description = "Small QR code decoding library";
license = lib.licenses.isc;
maintainers = [ lib.maintainers.raskin ];
platforms = lib.platforms.linux ++ [
"x86_64-darwin"
"aarch64-darwin"
];
platforms = lib.platforms.unix;
};
})
+7 -3
View File
@@ -25,9 +25,13 @@ stdenv.mkDerivation rec {
--replace /sbin/ifconfig ifconfig
'';
configureFlags = lib.optionals (!stdenv.hostPlatform.isLinux) [
"--disable-posixmq"
];
configureFlags =
lib.optionals (!stdenv.hostPlatform.isLinux) [
"--disable-posixmq"
]
++ lib.optionals stdenv.hostPlatform.isFreeBSD [
"--disable-dccp"
];
buildInputs = [
openssl
+1 -1
View File
@@ -87,7 +87,7 @@ stdenv.mkDerivation rec {
]
# Clang does not support the endfunc directive so use GCC.
++ lib.optional (
stdenv.cc.isClang && !stdenv.targetPlatform.isDarwin
stdenv.cc.isClang && !stdenv.targetPlatform.isDarwin && !stdenv.targetPlatform.isFreeBSD
) "-DCMAKE_ASM_COMPILER=${gccStdenv.cc}/bin/${gccStdenv.cc.targetPrefix}gcc";
cmakeStaticLibFlags =
+1 -1
View File
@@ -49,7 +49,7 @@ stdenv.mkDerivation rec {
mainProgram = "xavs";
homepage = "https://xavs.sourceforge.net/";
license = licenses.lgpl2;
platforms = platforms.linux ++ platforms.darwin;
platforms = platforms.unix;
maintainers = with maintainers; [ codyopel ];
};
}
File diff suppressed because it is too large Load Diff
@@ -20,6 +20,6 @@ stdenv.mkDerivation rec {
homepage = "http://www.videolan.org/developers/libdvdcss.html";
description = "Library for decrypting DVDs";
license = licenses.gpl2;
platforms = with platforms; linux ++ darwin;
platforms = platforms.unix;
};
}
@@ -27,6 +27,6 @@ stdenv.mkDerivation rec {
description = "Library for reading DVDs";
license = lib.licenses.gpl2;
maintainers = [ lib.maintainers.wmertens ];
platforms = with lib.platforms; linux ++ darwin;
platforms = lib.platforms.unix;
};
}
+443 -350
View File
@@ -1,105 +1,113 @@
{ lib
, stdenv
, fetchurl
, fetchFromGitHub
, cmake
, pkg-config
, unzip
, zlib
, pcre2
, hdf5
, boost
, glib
, glog
, gflags
, protobuf_29
, config
, ocl-icd
, qimgv
, opencv4
{
lib,
stdenv,
fetchurl,
fetchFromGitHub,
cmake,
pkg-config,
unzip,
zlib,
pcre2,
hdf5,
boost,
glib,
glog,
gflags,
protobuf_29,
config,
ocl-icd,
qimgv,
opencv4,
, enableJPEG ? true
, libjpeg
, enablePNG ? true
, libpng
, enableTIFF ? true
, libtiff
, enableWebP ? true
, libwebp
, enableEXR ? !stdenv.hostPlatform.isDarwin
, openexr
, ilmbase
, enableJPEG2000 ? true
, openjpeg
, enableEigen ? true
, eigen
, enableBlas ? true
, blas
, enableVA ? !stdenv.hostPlatform.isDarwin
, libva
, enableContrib ? true
enableJPEG ? true,
libjpeg,
enablePNG ? true,
libpng,
enableTIFF ? true,
libtiff,
enableWebP ? true,
libwebp,
enableEXR ? !stdenv.hostPlatform.isDarwin,
openexr,
ilmbase,
enableJPEG2000 ? true,
openjpeg,
enableEigen ? true,
eigen,
enableBlas ? true,
blas,
enableVA ? !stdenv.hostPlatform.isDarwin,
libva,
enableContrib ? true,
, enableCuda ? config.cudaSupport
, enableCublas ? enableCuda
, enableCudnn ? false # NOTE: CUDNN has a large impact on closure size so we disable it by default
, enableCufft ? enableCuda
, cudaPackages
, nvidia-optical-flow-sdk
enableCuda ? config.cudaSupport,
enableCublas ? enableCuda,
enableCudnn ? false, # NOTE: CUDNN has a large impact on closure size so we disable it by default
enableCufft ? enableCuda,
cudaPackages,
nvidia-optical-flow-sdk,
, enableLto ? true
, enableUnfree ? false
, enableIpp ? false
, enablePython ? false
, pythonPackages
, enableGtk2 ? false
, gtk2
, enableGtk3 ? false
, gtk3
, enableVtk ? false
, vtk
, enableFfmpeg ? true
, ffmpeg
, enableGStreamer ? true
, elfutils
, gst_all_1
, orc
, libunwind
, zstd
, enableTesseract ? false
, tesseract
, leptonica
, enableTbb ? false
, tbb
, enableOvis ? false
, ogre
, enableGPhoto2 ? false
, libgphoto2
, enableDC1394 ? false
, libdc1394
, enableDocs ? false
, doxygen
, graphviz-nox
enableLto ? true,
enableUnfree ? false,
enableIpp ? false,
enablePython ? false,
pythonPackages,
enableGtk2 ? false,
gtk2,
enableGtk3 ? false,
gtk3,
enableVtk ? false,
vtk,
enableFfmpeg ? true,
ffmpeg,
enableGStreamer ? true,
elfutils,
gst_all_1,
orc,
libunwind,
zstd,
enableTesseract ? false,
tesseract,
leptonica,
enableTbb ? false,
tbb,
enableOvis ? false,
ogre,
enableGPhoto2 ? false,
libgphoto2,
enableDC1394 ? false,
libdc1394,
enableDocs ? false,
doxygen,
graphviz-nox,
, runAccuracyTests ? true
, runPerformanceTests ? false
# Modules to enable via BUILD_LIST to build a customized opencv.
# An empty lists means this setting is omitted which matches upstreams default.
, enabledModules ? [ ]
runAccuracyTests ? true,
runPerformanceTests ? false,
# Modules to enable via BUILD_LIST to build a customized opencv.
# An empty lists means this setting is omitted which matches upstreams default.
enabledModules ? [ ],
, AVFoundation
, Cocoa
, VideoDecodeAcceleration
, CoreMedia
, MediaToolbox
, Accelerate
, bzip2
, callPackage
AVFoundation,
Cocoa,
VideoDecodeAcceleration,
CoreMedia,
MediaToolbox,
Accelerate,
bzip2,
callPackage,
}@inputs:
let
inherit (lib.attrsets) mapAttrsToList optionalAttrs;
inherit (lib.lists) last optionals;
inherit (lib.strings) cmakeBool cmakeFeature cmakeOptionType concatStrings concatStringsSep optionalString;
inherit (lib.strings)
cmakeBool
cmakeFeature
cmakeOptionType
concatStrings
concatStringsSep
optionalString
;
inherit (lib.trivial) flip;
version = "4.11.0";
@@ -135,13 +143,18 @@ let
# See opencv/3rdparty/ippicv/ippicv.cmake
ippicv = {
src = fetchFromGitHub {
owner = "opencv";
repo = "opencv_3rdparty";
rev = "7f55c0c26be418d494615afca15218566775c725";
hash = "sha256-XbmS+FXUL8MAG7kawbDkb2XHG9R0DpPhiYhq/18eTnY=";
} + "/ippicv";
files = let name = platform: "ippicv_2021.10.0_${platform}_20230919_general.tgz"; in
src =
fetchFromGitHub {
owner = "opencv";
repo = "opencv_3rdparty";
rev = "7f55c0c26be418d494615afca15218566775c725";
hash = "sha256-XbmS+FXUL8MAG7kawbDkb2XHG9R0DpPhiYhq/18eTnY=";
}
+ "/ippicv";
files =
let
name = platform: "ippicv_2021.10.0_${platform}_20230919_general.tgz";
in
if effectiveStdenv.hostPlatform.system == "x86_64-linux" then
{ ${name "lnx_intel64"} = ""; }
else if effectiveStdenv.hostPlatform.system == "i686-linux" then
@@ -233,15 +246,35 @@ let
};
# See opencv/cmake/OpenCVDownload.cmake
installExtraFiles = {dst, files, src, ...}: ''
mkdir -p "${dst}"
'' + concatStrings (flip mapAttrsToList files (name: md5: ''
ln -s "${src}/${name}" "${dst}/${md5}-${name}"
''));
installExtraFile = {dst, md5, name, src, ...}: ''
mkdir -p "${dst}"
ln -s "${src}" "${dst}/${md5}-${name}"
'';
installExtraFiles =
{
dst,
files,
src,
...
}:
''
mkdir -p "${dst}"
''
+ concatStrings (
flip mapAttrsToList files (
name: md5: ''
ln -s "${src}/${name}" "${dst}/${md5}-${name}"
''
)
);
installExtraFile =
{
dst,
md5,
name,
src,
...
}:
''
mkdir -p "${dst}"
ln -s "${src}" "${dst}/${md5}-${name}"
'';
withOpenblas = (enableBlas && blas.provider.pname == "openblas");
#multithreaded openblas conflicts with opencv multithreading, which manifest itself in hung tests
@@ -257,12 +290,14 @@ effectiveStdenv.mkDerivation {
pname = "opencv";
inherit version src;
outputs = [
"out"
"cxxdev"
] ++ optionals (runAccuracyTests || runPerformanceTests) [
"package_tests"
];
outputs =
[
"out"
"cxxdev"
]
++ optionals (runAccuracyTests || runPerformanceTests) [
"package_tests"
];
cudaPropagateToOutput = "cxxdev";
postUnpack = optionalString buildContrib ''
@@ -270,11 +305,13 @@ 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
] ++ optionals enableCuda [
./cuda_opt_flow.patch
];
patches =
[
./cmake-don-t-use-OpenCVFindOpenEXR.patch
]
++ optionals enableCuda [
./cuda_opt_flow.patch
];
# This prevents cmake from using libraries in impure paths (which
# causes build failure on non NixOS)
@@ -283,129 +320,163 @@ effectiveStdenv.mkDerivation {
'';
preConfigure =
installExtraFile ade +
optionalString enableIpp (installExtraFiles ippicv) + (
optionalString buildContrib ''
cmakeFlagsArray+=("-DOPENCV_EXTRA_MODULES_PATH=$NIX_BUILD_TOP/source/opencv_contrib")
installExtraFile ade
+ optionalString enableIpp (installExtraFiles ippicv)
+ (optionalString buildContrib ''
cmakeFlagsArray+=("-DOPENCV_EXTRA_MODULES_PATH=$NIX_BUILD_TOP/source/opencv_contrib")
${installExtraFiles vgg}
${installExtraFiles boostdesc}
${installExtraFiles face}
${installExtraFiles wechat_qrcode}
''
);
${installExtraFiles vgg}
${installExtraFiles boostdesc}
${installExtraFiles face}
${installExtraFiles wechat_qrcode}
'');
postConfigure = ''
[ -e modules/core/version_string.inc ]
echo '"(build info elided)"' > modules/core/version_string.inc
'';
buildInputs = [
boost
gflags
glib
glog
pcre2
protobuf_29
zlib
] ++ optionals enablePython [
pythonPackages.python
] ++ optionals (effectiveStdenv.buildPlatform == effectiveStdenv.hostPlatform) [
hdf5
] ++ optionals enableGtk2 [
gtk2
] ++ optionals enableGtk3 [
gtk3
] ++ optionals enableVtk [
vtk
] ++ optionals enableJPEG [
libjpeg
] ++ optionals enablePNG [
libpng
] ++ optionals enableTIFF [
libtiff
] ++ optionals enableWebP [
libwebp
] ++ optionals enableEXR [
openexr
ilmbase
] ++ optionals enableJPEG2000 [
openjpeg
] ++ optionals enableFfmpeg [
ffmpeg
] ++ optionals (enableFfmpeg && effectiveStdenv.hostPlatform.isDarwin) [
bzip2
VideoDecodeAcceleration
] ++ optionals (enableGStreamer && effectiveStdenv.hostPlatform.isLinux) [
elfutils
gst_all_1.gst-plugins-base
gst_all_1.gst-plugins-good
gst_all_1.gstreamer
libunwind
orc
zstd
] ++ optionals enableOvis [
ogre
] ++ optionals enableGPhoto2 [
libgphoto2
] ++ optionals enableDC1394 [
libdc1394
] ++ optionals enableEigen [
eigen
] ++ optionals enableVA [
libva
] ++ optionals enableBlas [
blas.provider
] ++ optionals enableTesseract [
# There is seemingly no compile-time flag for Tesseract. It's
# simply enabled automatically if contrib is built, and it detects
# tesseract & leptonica.
tesseract
leptonica
] ++ optionals enableTbb [
tbb
] ++ optionals effectiveStdenv.hostPlatform.isDarwin [
bzip2
AVFoundation
Cocoa
VideoDecodeAcceleration
CoreMedia
MediaToolbox
Accelerate
] ++ optionals enableDocs [
doxygen
graphviz-nox
] ++ optionals enableCuda [
cudaPackages.cuda_cudart
cudaPackages.cuda_cccl # <thrust/*>
cudaPackages.libnpp # npp.h
nvidia-optical-flow-sdk
] ++ optionals enableCublas [
# May start using the default $out instead once
# https://github.com/NixOS/nixpkgs/issues/271792
# has been addressed
cudaPackages.libcublas # cublas_v2.h
] ++ optionals enableCudnn [
cudaPackages.cudnn # cudnn.h
] ++ optionals enableCufft [
cudaPackages.libcufft # cufft.h
];
buildInputs =
[
boost
gflags
glib
glog
pcre2
protobuf_29
zlib
]
++ optionals enablePython [
pythonPackages.python
]
++ optionals (effectiveStdenv.buildPlatform == effectiveStdenv.hostPlatform) [
hdf5
]
++ optionals enableGtk2 [
gtk2
]
++ optionals enableGtk3 [
gtk3
]
++ optionals enableVtk [
vtk
]
++ optionals enableJPEG [
libjpeg
]
++ optionals enablePNG [
libpng
]
++ optionals enableTIFF [
libtiff
]
++ optionals enableWebP [
libwebp
]
++ optionals enableEXR [
openexr
ilmbase
]
++ optionals enableJPEG2000 [
openjpeg
]
++ optionals enableFfmpeg [
ffmpeg
]
++ optionals (enableFfmpeg && effectiveStdenv.hostPlatform.isDarwin) [
bzip2
VideoDecodeAcceleration
]
++ optionals (enableGStreamer && effectiveStdenv.hostPlatform.isLinux) [
elfutils
gst_all_1.gst-plugins-base
gst_all_1.gst-plugins-good
gst_all_1.gstreamer
libunwind
orc
zstd
]
++ optionals enableOvis [
ogre
]
++ optionals enableGPhoto2 [
libgphoto2
]
++ optionals enableDC1394 [
libdc1394
]
++ optionals enableEigen [
eigen
]
++ optionals enableVA [
libva
]
++ optionals enableBlas [
blas.provider
]
++ optionals enableTesseract [
# There is seemingly no compile-time flag for Tesseract. It's
# simply enabled automatically if contrib is built, and it detects
# tesseract & leptonica.
tesseract
leptonica
]
++ optionals enableTbb [
tbb
]
++ optionals effectiveStdenv.hostPlatform.isDarwin [
bzip2
AVFoundation
Cocoa
VideoDecodeAcceleration
CoreMedia
MediaToolbox
Accelerate
]
++ optionals enableDocs [
doxygen
graphviz-nox
]
++ optionals enableCuda [
cudaPackages.cuda_cudart
cudaPackages.cuda_cccl # <thrust/*>
cudaPackages.libnpp # npp.h
nvidia-optical-flow-sdk
]
++ optionals enableCublas [
# May start using the default $out instead once
# https://github.com/NixOS/nixpkgs/issues/271792
# has been addressed
cudaPackages.libcublas # cublas_v2.h
]
++ optionals enableCudnn [
cudaPackages.cudnn # cudnn.h
]
++ optionals enableCufft [
cudaPackages.libcufft # cufft.h
];
propagatedBuildInputs = optionals enablePython [ pythonPackages.numpy ];
nativeBuildInputs = [
cmake
pkg-config
unzip
] ++ optionals enablePython ([
pythonPackages.pip
pythonPackages.wheel
pythonPackages.setuptools
] ++ optionals (effectiveStdenv.hostPlatform == effectiveStdenv.buildPlatform) [
pythonPackages.pythonImportsCheckHook
]) ++ optionals enableCuda [
cudaPackages.cuda_nvcc
];
nativeBuildInputs =
[
cmake
pkg-config
unzip
]
++ optionals enablePython (
[
pythonPackages.pip
pythonPackages.wheel
pythonPackages.setuptools
]
++ optionals (effectiveStdenv.hostPlatform == effectiveStdenv.buildPlatform) [
pythonPackages.pythonImportsCheckHook
]
)
++ optionals enableCuda [
cudaPackages.cuda_nvcc
];
env.NIX_CFLAGS_COMPILE = optionalString enableEXR "-I${ilmbase.dev}/include/OpenEXR";
@@ -413,78 +484,86 @@ effectiveStdenv.mkDerivation {
OpenBLAS_HOME = optionalString withOpenblas openblas_.dev;
OpenBLAS = optionalString withOpenblas openblas_;
cmakeFlags = [
(cmakeBool "OPENCV_GENERATE_PKGCONFIG" true)
(cmakeBool "WITH_OPENMP" true)
(cmakeBool "BUILD_PROTOBUF" false)
(cmakeBool "PROTOBUF_UPDATE_FILES" true)
(cmakeBool "OPENCV_ENABLE_NONFREE" enableUnfree)
(cmakeBool "BUILD_TESTS" runAccuracyTests)
(cmakeBool "BUILD_PERF_TESTS" runPerformanceTests)
(cmakeBool "CMAKE_SKIP_BUILD_RPATH" true)
(cmakeBool "BUILD_DOCS" enableDocs)
# "OpenCV disables pkg-config to avoid using of host libraries. Consider using PKG_CONFIG_LIBDIR to specify target SYSROOT"
# but we have proper separation of build and host libs :), fixes cross
(cmakeBool "OPENCV_ENABLE_PKG_CONFIG" true)
(cmakeBool "WITH_IPP" enableIpp)
(cmakeBool "WITH_TIFF" enableTIFF)
(cmakeBool "WITH_WEBP" enableWebP)
(cmakeBool "WITH_JPEG" enableJPEG)
(cmakeBool "WITH_PNG" enablePNG)
(cmakeBool "WITH_OPENEXR" enableEXR)
(cmakeBool "WITH_OPENJPEG" enableJPEG2000)
(cmakeBool "WITH_JASPER" false) # OpenCV falls back to a vendored copy of Jasper when OpenJPEG is disabled
(cmakeBool "WITH_TBB" enableTbb)
cmakeFlags =
[
(cmakeBool "OPENCV_GENERATE_PKGCONFIG" true)
(cmakeBool "WITH_OPENMP" true)
(cmakeBool "BUILD_PROTOBUF" false)
(cmakeBool "PROTOBUF_UPDATE_FILES" true)
(cmakeBool "OPENCV_ENABLE_NONFREE" enableUnfree)
(cmakeBool "BUILD_TESTS" runAccuracyTests)
(cmakeBool "BUILD_PERF_TESTS" runPerformanceTests)
(cmakeBool "CMAKE_SKIP_BUILD_RPATH" true)
(cmakeBool "BUILD_DOCS" enableDocs)
# "OpenCV disables pkg-config to avoid using of host libraries. Consider using PKG_CONFIG_LIBDIR to specify target SYSROOT"
# but we have proper separation of build and host libs :), fixes cross
(cmakeBool "OPENCV_ENABLE_PKG_CONFIG" true)
(cmakeBool "WITH_IPP" enableIpp)
(cmakeBool "WITH_TIFF" enableTIFF)
(cmakeBool "WITH_WEBP" enableWebP)
(cmakeBool "WITH_JPEG" enableJPEG)
(cmakeBool "WITH_PNG" enablePNG)
(cmakeBool "WITH_OPENEXR" enableEXR)
(cmakeBool "WITH_OPENJPEG" enableJPEG2000)
(cmakeBool "WITH_JASPER" false) # OpenCV falls back to a vendored copy of Jasper when OpenJPEG is disabled
(cmakeBool "WITH_TBB" enableTbb)
# CUDA options
(cmakeBool "WITH_CUDA" enableCuda)
(cmakeBool "WITH_CUBLAS" enableCublas)
(cmakeBool "WITH_CUDNN" enableCudnn)
(cmakeBool "WITH_CUFFT" enableCufft)
# CUDA options
(cmakeBool "WITH_CUDA" enableCuda)
(cmakeBool "WITH_CUBLAS" enableCublas)
(cmakeBool "WITH_CUDNN" enableCudnn)
(cmakeBool "WITH_CUFFT" enableCufft)
# LTO options
(cmakeBool "ENABLE_LTO" enableLto)
(cmakeBool "ENABLE_THIN_LTO" (
enableLto && (
# Only clang supports thin LTO, so we must either be using clang through the effectiveStdenv,
effectiveStdenv.cc.isClang ||
# or through the backend effectiveStdenv.
(enableCuda && effectiveStdenv.cc.isClang)
)
))
] ++ optionals enableCuda [
(cmakeBool "CUDA_FAST_MATH" true)
(cmakeFeature "CUDA_NVCC_FLAGS" "--expt-relaxed-constexpr")
# LTO options
(cmakeBool "ENABLE_LTO" enableLto)
(cmakeBool "ENABLE_THIN_LTO" (
enableLto
&& (
# Only clang supports thin LTO, so we must either be using clang through the effectiveStdenv,
effectiveStdenv.cc.isClang
||
# or through the backend effectiveStdenv.
(enableCuda && effectiveStdenv.cc.isClang)
)
))
]
++ optionals enableCuda [
(cmakeBool "CUDA_FAST_MATH" true)
(cmakeFeature "CUDA_NVCC_FLAGS" "--expt-relaxed-constexpr")
# OpenCV respects at least three variables:
# -DCUDA_GENERATION takes a single arch name, e.g. Volta
# -DCUDA_ARCH_BIN takes a semi-colon separated list of real arches, e.g. "8.0;8.6"
# -DCUDA_ARCH_PTX takes the virtual arch, e.g. "8.6"
(cmakeFeature "CUDA_ARCH_BIN" cmakeCudaArchitecturesString)
(cmakeFeature "CUDA_ARCH_PTX" (last cudaCapabilities))
# OpenCV respects at least three variables:
# -DCUDA_GENERATION takes a single arch name, e.g. Volta
# -DCUDA_ARCH_BIN takes a semi-colon separated list of real arches, e.g. "8.0;8.6"
# -DCUDA_ARCH_PTX takes the virtual arch, e.g. "8.6"
(cmakeFeature "CUDA_ARCH_BIN" cmakeCudaArchitecturesString)
(cmakeFeature "CUDA_ARCH_PTX" (last cudaCapabilities))
(cmakeOptionType "path" "NVIDIA_OPTICAL_FLOW_2_0_HEADERS_PATH" nvidia-optical-flow-sdk.outPath)
] ++ optionals effectiveStdenv.hostPlatform.isDarwin [
(cmakeBool "WITH_OPENCL" false)
(cmakeBool "WITH_LAPACK" false)
(cmakeOptionType "path" "NVIDIA_OPTICAL_FLOW_2_0_HEADERS_PATH" nvidia-optical-flow-sdk.outPath)
]
++ optionals effectiveStdenv.hostPlatform.isDarwin [
(cmakeBool "WITH_OPENCL" false)
(cmakeBool "WITH_LAPACK" false)
# Disable unnecessary vendoring that's enabled by default only for Darwin.
# Note that the opencvFlag feature flags listed above still take
# precedence, so we can safely list everything here.
(cmakeBool "BUILD_ZLIB" false)
(cmakeBool "BUILD_TIFF" false)
(cmakeBool "BUILD_OPENJPEG" false)
(cmakeBool "BUILD_JASPER" false)
(cmakeBool "BUILD_JPEG" false)
(cmakeBool "BUILD_PNG" false)
(cmakeBool "BUILD_WEBP" false)
] ++ optionals (!effectiveStdenv.hostPlatform.isDarwin) [
(cmakeOptionType "path" "OPENCL_LIBRARY" "${ocl-icd}/lib/libOpenCL.so")
] ++ optionals enablePython [
(cmakeOptionType "path" "OPENCV_PYTHON_INSTALL_PATH" pythonPackages.python.sitePackages)
] ++ optionals (enabledModules != [ ]) [
(cmakeFeature "BUILD_LIST" (concatStringsSep "," enabledModules))
];
# Disable unnecessary vendoring that's enabled by default only for Darwin.
# Note that the opencvFlag feature flags listed above still take
# precedence, so we can safely list everything here.
(cmakeBool "BUILD_ZLIB" false)
(cmakeBool "BUILD_TIFF" false)
(cmakeBool "BUILD_OPENJPEG" false)
(cmakeBool "BUILD_JASPER" false)
(cmakeBool "BUILD_JPEG" false)
(cmakeBool "BUILD_PNG" false)
(cmakeBool "BUILD_WEBP" false)
]
++ optionals (!effectiveStdenv.hostPlatform.isDarwin) [
(cmakeOptionType "path" "OPENCL_LIBRARY" "${ocl-icd}/lib/libOpenCL.so")
]
++ optionals enablePython [
(cmakeOptionType "path" "OPENCV_PYTHON_INSTALL_PATH" pythonPackages.python.sitePackages)
]
++ optionals (enabledModules != [ ]) [
(cmakeFeature "BUILD_LIST" (concatStringsSep "," enabledModules))
];
postBuild = optionalString enableDocs ''
make doxygen
@@ -494,9 +573,11 @@ effectiveStdenv.mkDerivation {
optionalString (runAccuracyTests || runPerformanceTests) ''
mkdir $package_tests
cp -R $src/samples $package_tests/
'' + optionalString runAccuracyTests ''
''
+ optionalString runAccuracyTests ''
mv ./bin/*test* $package_tests/
'' + optionalString runPerformanceTests ''
''
+ optionalString runPerformanceTests ''
mv ./bin/*perf* $package_tests/
'';
@@ -512,62 +593,74 @@ effectiveStdenv.mkDerivation {
# Note that ${exec_prefix} is set to $out but that $out is also appended to
# ${exec_prefix}. This causes linker errors in downstream packages so we strip
# of $out after the ${exec_prefix} and ${prefix} prefixes:
postInstall = ''
sed -i "s|{exec_prefix}/$out|{exec_prefix}|;s|{prefix}/$out|{prefix}|" \
"$out/lib/pkgconfig/opencv4.pc"
mkdir "$cxxdev"
''
# fix deps not propagating from opencv4.cxxdev if cuda is disabled
# see https://github.com/NixOS/nixpkgs/issues/276691
+ optionalString (!enableCuda) ''
mkdir -p "$cxxdev/nix-support"
echo "''${!outputDev}" >> "$cxxdev/nix-support/propagated-build-inputs"
''
# remove the requirement that the exact same version of CUDA is used in packages
# consuming OpenCV's CMakes files
+ optionalString enableCuda ''
substituteInPlace "$out/lib/cmake/opencv4/OpenCVConfig.cmake" \
--replace-fail \
'find_host_package(CUDA ''${OpenCV_CUDA_VERSION} EXACT REQUIRED)' \
'find_host_package(CUDA REQUIRED)' \
--replace-fail \
'message(FATAL_ERROR "OpenCV static library was compiled with CUDA' \
'message("OpenCV static library was compiled with CUDA'
''
# install python distribution information, so other packages can `import opencv`
+ optionalString enablePython ''
pushd $NIX_BUILD_TOP/$sourceRoot/modules/python/package
python -m pip wheel --verbose --no-index --no-deps --no-clean --no-build-isolation --wheel-dir dist .
postInstall =
''
sed -i "s|{exec_prefix}/$out|{exec_prefix}|;s|{prefix}/$out|{prefix}|" \
"$out/lib/pkgconfig/opencv4.pc"
mkdir "$cxxdev"
''
# fix deps not propagating from opencv4.cxxdev if cuda is disabled
# see https://github.com/NixOS/nixpkgs/issues/276691
+ optionalString (!enableCuda) ''
mkdir -p "$cxxdev/nix-support"
echo "''${!outputDev}" >> "$cxxdev/nix-support/propagated-build-inputs"
''
# remove the requirement that the exact same version of CUDA is used in packages
# consuming OpenCV's CMakes files
+ optionalString enableCuda ''
substituteInPlace "$out/lib/cmake/opencv4/OpenCVConfig.cmake" \
--replace-fail \
'find_host_package(CUDA ''${OpenCV_CUDA_VERSION} EXACT REQUIRED)' \
'find_host_package(CUDA REQUIRED)' \
--replace-fail \
'message(FATAL_ERROR "OpenCV static library was compiled with CUDA' \
'message("OpenCV static library was compiled with CUDA'
''
# install python distribution information, so other packages can `import opencv`
+ optionalString enablePython ''
pushd $NIX_BUILD_TOP/$sourceRoot/modules/python/package
python -m pip wheel --verbose --no-index --no-deps --no-clean --no-build-isolation --wheel-dir dist .
pushd dist
python -m pip install ./*.whl --no-index --no-warn-script-location --prefix="$out" --no-cache
pushd dist
python -m pip install ./*.whl --no-index --no-warn-script-location --prefix="$out" --no-cache
popd
popd
'';
popd
popd
'';
pythonImportsCheck = [ "cv2" "cv2.sfm" ];
pythonImportsCheck = [
"cv2"
"cv2.sfm"
];
passthru = {
cudaSupport = enableCuda;
tests = {
inherit (gst_all_1) gst-plugins-bad;
}
// optionalAttrs (!effectiveStdenv.hostPlatform.isDarwin) {
inherit qimgv;
withIpp = opencv4.override { enableIpp = true; };
}
// optionalAttrs (!enablePython) { pythonEnabled = pythonPackages.opencv4; }
// optionalAttrs (effectiveStdenv.buildPlatform != "x86_64-darwin") {
opencv4-tests = callPackage ./tests.nix {
inherit enableGStreamer enableGtk2 enableGtk3 runAccuracyTests runPerformanceTests testDataSrc;
inherit opencv4;
tests =
{
inherit (gst_all_1) gst-plugins-bad;
}
// optionalAttrs (!effectiveStdenv.hostPlatform.isDarwin) {
inherit qimgv;
withIpp = opencv4.override { enableIpp = true; };
}
// optionalAttrs (!enablePython) { pythonEnabled = pythonPackages.opencv4; }
// optionalAttrs (effectiveStdenv.buildPlatform != "x86_64-darwin") {
opencv4-tests = callPackage ./tests.nix {
inherit
enableGStreamer
enableGtk2
enableGtk3
runAccuracyTests
runPerformanceTests
testDataSrc
;
inherit opencv4;
};
}
// optionalAttrs (enableCuda) {
no-libstdcxx-errors = callPackage ./libstdcxx-test.nix { attrName = "opencv4"; };
};
}
// optionalAttrs (enableCuda) {
no-libstdcxx-errors = callPackage ./libstdcxx-test.nix { attrName = "opencv4"; };
};
} // optionalAttrs enablePython { pythonPath = [ ]; };
meta = {
@@ -575,6 +668,6 @@ effectiveStdenv.mkDerivation {
homepage = "https://opencv.org/";
license = if enableUnfree then lib.licenses.unfree else lib.licenses.bsd3;
maintainers = with lib.maintainers; [ basvandijk ];
platforms = with lib.platforms; linux ++ darwin;
platforms = lib.platforms.unix;
};
}
@@ -128,6 +128,14 @@ let
DYNAMIC_ARCH = setDynamicArch true;
USE_OPENMP = true;
};
x86_64-freebsd = {
BINARY = 64;
TARGET = setTarget "ATHLON";
DYNAMIC_ARCH = setDynamicArch true;
NO_AVX512 = !enableAVX512;
USE_OPENMP = true;
};
};
in
@@ -51,6 +51,6 @@ buildPythonPackage rec {
lgpl21Only
mpl11
];
platforms = lib.platforms.linux ++ lib.platforms.darwin;
platforms = platforms.unix;
};
}