1 { stdenv, lib, fetchFromGitHub
21 , enablePlugins ? true
25 loadersPath = "${gdk-pixbuf.binaryDir}/jxl-loaders.cache";
28 stdenv.mkDerivation rec {
32 outputs = [ "out" "dev" ];
34 src = fetchFromGitHub {
38 hash = "sha256-lBc0zP+f44YadwOU9+I+YYWzTrAg7FSfF3IQuh4LjM4=";
39 # There are various submodules in `third_party/`.
40 fetchSubmodules = true;
59 # Functionality not currently provided by this package
60 # that the cmake build can apparently use:
61 # OpenGL/GLUT (for Examples -> comparison with sjpeg)
62 # viewer (see `cmakeFlags`)
63 # plugins like for GDK and GIMP (see `cmakeFlags`)
66 # `libjxl` currently vendors many libraries as git submodules that they
67 # might patch often (e.g. test/gmock, see
68 # https://github.com/NixOS/nixpkgs/pull/103160#discussion_r519487734).
69 # When it has stabilised in the future, we may want to tell the build
70 # to use use nixpkgs system libraries.
72 # As of writing, libjxl does not point out all its dependencies
73 # conclusively in its README or otherwise; they can best be determined
74 # by checking the CMake output for "Could NOT find".
78 gperftools # provides `libtcmalloc`
88 propagatedBuildInputs = [
94 # For C dependencies like brotli, which are dynamically linked,
95 # we want to use the system libraries, so that we don't have to care about
96 # installing their .so files generated by this build.
97 # The other C++ dependencies are statically linked in, so there
98 # using the vendorered ones is easier.
99 "-DJPEGXL_FORCE_SYSTEM_BROTLI=ON"
101 # Use our version of highway, though it is still statically linked in
102 "-DJPEGXL_FORCE_SYSTEM_HWY=ON"
104 # Use our version of gtest
105 "-DJPEGXL_FORCE_SYSTEM_GTEST=ON"
107 # TODO: Update this package to enable this (overridably via an option):
108 # Viewer tools for evaluation.
109 # "-DJPEGXL_ENABLE_VIEWERS=ON"
110 ] ++ lib.optionals enablePlugins [
111 # Enable plugins, such as:
112 # * the `gdk-pixbuf` one, which allows applications like `eog` to load jpeg-xl files
113 # * the `gimp` one, which allows GIMP to load jpeg-xl files
114 "-DJPEGXL_ENABLE_PLUGINS=ON"
115 ] ++ lib.optionals stdenv.hostPlatform.isStatic [
117 ] ++ lib.optionals stdenv.hostPlatform.isAarch32 [
118 "-DJPEGXL_FORCE_NEON=ON"
121 # the second substitution fix regex for a2x script
122 # https://github.com/libjxl/libjxl/pull/3842
124 substituteInPlace plugins/gdk-pixbuf/jxl.thumbnailer \
125 --replace '/usr/bin/gdk-pixbuf-thumbnailer' "$out/libexec/gdk-pixbuf-thumbnailer-jxl"
126 substituteInPlace CMakeLists.txt \
127 --replace 'sh$' 'sh( -e$|$)'
130 postInstall = lib.optionalString enablePlugins ''
131 GDK_PIXBUF_MODULEDIR="$out/${gdk-pixbuf.moduleDir}" \
132 GDK_PIXBUF_MODULE_FILE="$out/${loadersPath}" \
133 gdk-pixbuf-query-loaders --update-cache
135 # Cross-compiled gdk-pixbuf doesn't support thumbnailers
136 + lib.optionalString (enablePlugins && stdenv.hostPlatform == stdenv.buildPlatform) ''
138 makeWrapper ${gdk-pixbuf}/bin/gdk-pixbuf-thumbnailer "$out/libexec/gdk-pixbuf-thumbnailer-jxl" \
139 --set GDK_PIXBUF_MODULE_FILE "$out/${loadersPath}"
142 CXXFLAGS = lib.optionalString stdenv.hostPlatform.isAarch32 "-mfp16-format=ieee";
144 # FIXME x86_64-darwin:
145 # https://github.com/NixOS/nixpkgs/pull/204030#issuecomment-1352768690
146 doCheck = with stdenv; !(hostPlatform.isi686 || isDarwin && isx86_64);
149 homepage = "https://github.com/libjxl/libjxl";
150 description = "JPEG XL image format reference implementation";
151 license = licenses.bsd3;
152 maintainers = with maintainers; [ nh2 ];
153 platforms = platforms.all;