28 loadersPath = "${gdk-pixbuf.binaryDir}/jxl-loaders.cache";
31 stdenv.mkDerivation rec {
40 src = fetchFromGitHub {
44 hash = "sha256-ORwhKOp5Nog366UkLbuWpjz/6sJhxUO6+SkoJGH+3fE=";
45 # There are various submodules in `third_party/`.
46 fetchSubmodules = true;
65 # Functionality not currently provided by this package
66 # that the cmake build can apparently use:
67 # OpenGL/GLUT (for Examples -> comparison with sjpeg)
68 # viewer (see `cmakeFlags`)
69 # plugins like for GDK and GIMP (see `cmakeFlags`)
72 # `libjxl` currently vendors many libraries as git submodules that they
73 # might patch often (e.g. test/gmock, see
74 # https://github.com/NixOS/nixpkgs/pull/103160#discussion_r519487734).
75 # When it has stabilised in the future, we may want to tell the build
76 # to use use nixpkgs system libraries.
78 # As of writing, libjxl does not point out all its dependencies
79 # conclusively in its README or otherwise; they can best be determined
80 # by checking the CMake output for "Could NOT find".
84 gperftools # provides `libtcmalloc`
94 propagatedBuildInputs = [
101 # For C dependencies like brotli, which are dynamically linked,
102 # we want to use the system libraries, so that we don't have to care about
103 # installing their .so files generated by this build.
104 # The other C++ dependencies are statically linked in, so there
105 # using the vendorered ones is easier.
106 "-DJPEGXL_FORCE_SYSTEM_BROTLI=ON"
108 # Use our version of highway, though it is still statically linked in
109 "-DJPEGXL_FORCE_SYSTEM_HWY=ON"
111 # Use our version of gtest
112 "-DJPEGXL_FORCE_SYSTEM_GTEST=ON"
114 "-DJPEGXL_ENABLE_SKCMS=OFF"
115 "-DJPEGXL_FORCE_SYSTEM_LCMS2=ON"
117 # TODO: Update this package to enable this (overridably via an option):
118 # Viewer tools for evaluation.
119 # "-DJPEGXL_ENABLE_VIEWERS=ON"
121 ++ lib.optionals enablePlugins [
122 # Enable plugins, such as:
123 # * the `gdk-pixbuf` one, which allows applications like `eog` to load jpeg-xl files
124 # * the `gimp` one, which allows GIMP to load jpeg-xl files
125 "-DJPEGXL_ENABLE_PLUGINS=ON"
127 ++ lib.optionals stdenv.hostPlatform.isStatic [
130 ++ lib.optionals stdenv.hostPlatform.isAarch32 [
131 "-DJPEGXL_FORCE_NEON=ON"
134 # the second substitution fix regex for a2x script
135 # https://github.com/libjxl/libjxl/pull/3842
137 # Make sure we do not accidentally build against some of the vendored dependencies
138 # If it asks you to "run deps.sh to fetch the build dependencies", then you are probably missing a JPEGXL_FORCE_SYSTEM_* flag
140 rm -rf third_party/!(sjpeg)/
143 substituteInPlace plugins/gdk-pixbuf/jxl.thumbnailer \
144 --replace '/usr/bin/gdk-pixbuf-thumbnailer' "$out/libexec/gdk-pixbuf-thumbnailer-jxl"
145 substituteInPlace CMakeLists.txt \
146 --replace 'sh$' 'sh( -e$|$)'
150 lib.optionalString enablePlugins ''
151 GDK_PIXBUF_MODULEDIR="$out/${gdk-pixbuf.moduleDir}" \
152 GDK_PIXBUF_MODULE_FILE="$out/${loadersPath}" \
153 gdk-pixbuf-query-loaders --update-cache
155 # Cross-compiled gdk-pixbuf doesn't support thumbnailers
156 + lib.optionalString (enablePlugins && stdenv.hostPlatform == stdenv.buildPlatform) ''
158 makeWrapper ${gdk-pixbuf}/bin/gdk-pixbuf-thumbnailer "$out/libexec/gdk-pixbuf-thumbnailer-jxl" \
159 --set GDK_PIXBUF_MODULE_FILE "$out/${loadersPath}"
162 CXXFLAGS = lib.optionalString stdenv.hostPlatform.isAarch32 "-mfp16-format=ieee";
164 # FIXME x86_64-darwin:
165 # https://github.com/NixOS/nixpkgs/pull/204030#issuecomment-1352768690
166 doCheck = with stdenv; !(hostPlatform.isi686 || isDarwin && isx86_64);
169 homepage = "https://github.com/libjxl/libjxl";
170 description = "JPEG XL image format reference implementation";
171 license = licenses.bsd3;
172 maintainers = with maintainers; [ nh2 ];
173 platforms = platforms.all;