1{
2 stdenv,
3 fetchurl,
4 nixosTests,
5 fixDarwinDylibNames,
6 meson,
7 ninja,
8 pkg-config,
9 gettext,
10 python3,
11 docutils,
12 gi-docgen,
13 glib,
14 libtiff,
15 libjpeg,
16 libpng,
17 gnome,
18 doCheck ? false,
19 makeWrapper,
20 lib,
21 testers,
22 buildPackages,
23 withIntrospection ?
24 lib.meta.availableOn stdenv.hostPlatform gobject-introspection
25 && stdenv.hostPlatform.emulatorAvailable buildPackages,
26 gobject-introspection,
27}:
28
29stdenv.mkDerivation (finalAttrs: {
30 pname = "gdk-pixbuf";
31 version = "2.42.12";
32
33 outputs = [
34 "out"
35 "dev"
36 "man"
37 ]
38 ++ lib.optional withIntrospection "devdoc"
39 ++ lib.optional (stdenv.buildPlatform == stdenv.hostPlatform) "installedTests";
40
41 src =
42 let
43 inherit (finalAttrs) pname version;
44 in
45 fetchurl {
46 url = "mirror://gnome/sources/${pname}/${lib.versions.majorMinor version}/${pname}-${version}.tar.xz";
47 hash = "sha256-uVBbNEW5p+SM7TR2DDvLc+lm3zrJTJWhSMtmmrdI48c=";
48 };
49
50 patches = [
51 # Move installed tests to a separate output
52 ./installed-tests-path.patch
53
54 ./static-deps.patch
55 ];
56
57 # gdk-pixbuf-thumbnailer is not wrapped therefore strictDeps will work
58 strictDeps = true;
59
60 depsBuildBuild = [
61 pkg-config
62 ];
63
64 nativeBuildInputs = [
65 meson
66 ninja
67 pkg-config
68 gettext
69 python3
70 makeWrapper
71 glib
72
73 # for man pages
74 docutils
75 ]
76 ++ lib.optionals stdenv.hostPlatform.isDarwin [
77 fixDarwinDylibNames
78 ]
79 ++ lib.optionals withIntrospection [
80 gi-docgen
81 gobject-introspection
82 ];
83
84 propagatedBuildInputs = [
85 glib
86 libtiff
87 libjpeg
88 libpng
89 ];
90
91 mesonFlags = [
92 "-Dgio_sniffing=false"
93 (lib.mesonBool "gtk_doc" withIntrospection)
94 (lib.mesonEnable "introspection" withIntrospection)
95 (lib.mesonEnable "others" true)
96 ]
97 ++ lib.optionals stdenv.hostPlatform.isStatic [
98 "-Dbuiltin_loaders=all"
99 ];
100
101 postPatch = ''
102 chmod +x build-aux/* # patchShebangs only applies to executables
103 patchShebangs build-aux
104
105 substituteInPlace tests/meson.build --subst-var-by installedtestsprefix "$installedTests"
106
107 # Run-time dependency gi-docgen found: NO (tried pkgconfig and cmake)
108 # it should be a build-time dep for build
109 # TODO: send upstream
110 substituteInPlace docs/meson.build \
111 --replace "dependency('gi-docgen'," "dependency('gi-docgen', native:true," \
112 --replace "'gi-docgen', req" "'gi-docgen', native:true, req"
113
114 # Remove 'ani' loader until proper fix for CVE-2022-48622
115 substituteInPlace meson.build --replace-fail "'ani'," ""
116 '';
117
118 postInstall = ''
119 # All except one utility seem to be only useful during building.
120 moveToOutput "bin" "$dev"
121 moveToOutput "bin/gdk-pixbuf-thumbnailer" "$out"
122
123 ''
124 + lib.optionalString stdenv.hostPlatform.isDarwin ''
125 # meson erroneously installs loaders with .dylib extension on Darwin.
126 # Their @rpath has to be replaced before gdk-pixbuf-query-loaders looks at them.
127 for f in $out/${finalAttrs.passthru.moduleDir}/*.dylib; do
128 install_name_tool -change @rpath/libgdk_pixbuf-2.0.0.dylib $out/lib/libgdk_pixbuf-2.0.0.dylib $f
129 mv $f ''${f%.dylib}.so
130 done
131 ''
132 + lib.optionalString withIntrospection ''
133 # We need to install 'loaders.cache' in lib/gdk-pixbuf-2.0/2.10.0/
134 ${stdenv.hostPlatform.emulator buildPackages} $dev/bin/gdk-pixbuf-query-loaders --update-cache
135 '';
136
137 # The fixDarwinDylibNames hook doesn't patch binaries.
138 preFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
139 for f in $out/bin/* $dev/bin/*; do
140 install_name_tool -change @rpath/libgdk_pixbuf-2.0.0.dylib $out/lib/libgdk_pixbuf-2.0.0.dylib $f
141 done
142 '';
143
144 postFixup = lib.optionalString withIntrospection ''
145 # Cannot be in postInstall, otherwise _multioutDocs hook in preFixup will move right back.
146 moveToOutput "share/doc" "$devdoc"
147 '';
148
149 # The tests take an excessive amount of time (> 1.5 hours) and memory (> 6 GB).
150 inherit doCheck;
151
152 setupHook = ./setup-hook.sh;
153
154 separateDebugInfo = stdenv.hostPlatform.isLinux;
155
156 passthru = {
157 updateScript = gnome.updateScript {
158 packageName = finalAttrs.pname;
159 versionPolicy = "odd-unstable";
160 };
161
162 tests = {
163 installedTests = nixosTests.installed-tests.gdk-pixbuf;
164 pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
165 };
166
167 # gdk_pixbuf_binarydir and gdk_pixbuf_moduledir variables from gdk-pixbuf-2.0.pc
168 binaryDir = "lib/gdk-pixbuf-2.0/2.10.0";
169 moduleDir = "${finalAttrs.passthru.binaryDir}/loaders";
170 };
171
172 meta = with lib; {
173 description = "Library for image loading and manipulation";
174 homepage = "https://gitlab.gnome.org/GNOME/gdk-pixbuf";
175 license = licenses.lgpl21Plus;
176 teams = [ teams.gnome ];
177 mainProgram = "gdk-pixbuf-thumbnailer";
178 pkgConfigModules = [ "gdk-pixbuf-2.0" ];
179 platforms = platforms.unix;
180 };
181})