1{
2 stdenv,
3 lib,
4 fetchurl,
5 replaceVars,
6 meson,
7 ninja,
8 pkg-config,
9 babl,
10 cfitsio,
11 gegl,
12 gtk3,
13 glib,
14 gdk-pixbuf,
15 graphviz,
16 isocodes,
17 pango,
18 cairo,
19 libarchive,
20 luajit,
21 freetype,
22 fontconfig,
23 lcms,
24 libpng,
25 libiff,
26 libilbm,
27 libjpeg,
28 libjxl,
29 poppler,
30 poppler_data,
31 libtiff,
32 libmng,
33 librsvg,
34 libwmf,
35 zlib,
36 libzip,
37 ghostscript,
38 aalib,
39 shared-mime-info,
40 python3,
41 libexif,
42 gettext,
43 wrapGAppsHook3,
44 libxslt,
45 gobject-introspection,
46 vala,
47 gi-docgen,
48 perl,
49 appstream-glib,
50 desktop-file-utils,
51 xorg,
52 glib-networking,
53 json-glib,
54 libmypaint,
55 llvmPackages,
56 gexiv2,
57 harfbuzz,
58 mypaint-brushes1,
59 libwebp,
60 libheif,
61 gjs,
62 libgudev,
63 openexr,
64 xvfb-run,
65 dbus,
66 adwaita-icon-theme,
67 alsa-lib,
68 desktopToDarwinBundle,
69 fetchpatch,
70}:
71
72let
73 python = python3.withPackages (
74 pp: with pp; [
75 pygobject3
76 ]
77 );
78in
79stdenv.mkDerivation (finalAttrs: {
80 pname = "gimp";
81 version = "3.0.4";
82
83 outputs = [
84 "out"
85 "dev"
86 "devdoc"
87 ];
88
89 src = fetchurl {
90 url = "https://download.gimp.org/gimp/v${lib.versions.majorMinor finalAttrs.version}/gimp-${finalAttrs.version}.tar.xz";
91 hash = "sha256-jKouwnW/CTJldWVKwnavwIP4SR58ykXRnPKeaWrsqyU=";
92 };
93
94 patches = [
95 # to remove compiler from the runtime closure, reference was retained via
96 # gimp --version --verbose output
97 (replaceVars ./remove-cc-reference.patch {
98 cc_version = stdenv.cc.cc.name;
99 })
100
101 # Use absolute paths instead of relying on PATH
102 # to make sure plug-ins are loaded by the correct interpreter.
103 # TODO: This now only appears to be used on Windows.
104 (replaceVars ./hardcode-plugin-interpreters.patch {
105 python_interpreter = python.interpreter;
106 PYTHON_EXE = null;
107 })
108
109 # D-Bus configuration is not available in the build sandbox
110 # so we need to pick up the one from the package.
111 (replaceVars ./tests-dbus-conf.patch {
112 session_conf = "${dbus.out}/share/dbus-1/session.conf";
113 })
114
115 # Fix a crash that occurs when trying to pick a color for text outline
116 # TODO: remove after GIMP 3.2 is released, per https://gitlab.gnome.org/GNOME/gimp/-/issues/14047#note_2491655
117 (fetchpatch {
118 url = "https://gitlab.gnome.org/GNOME/gimp/-/commit/1685c86af5d6253151d0056a9677ba469ea10164.diff";
119 hash = "sha256-Rb3ANXWki21thByEIWkBgWEml4x9Qq2HAIB9ho1bygw=";
120 })
121 ];
122
123 nativeBuildInputs = [
124 meson
125 ninja
126 pkg-config
127 gettext
128 wrapGAppsHook3
129 libxslt # for xsltproc
130 gobject-introspection
131 perl
132 vala
133
134 # for docs
135 gi-docgen
136
137 # for tests
138 desktop-file-utils
139 ]
140 ++ lib.optionals stdenv.hostPlatform.isLinux [
141 dbus
142 xvfb-run
143 ]
144 ++ lib.optionals stdenv.hostPlatform.isDarwin [
145 desktopToDarwinBundle
146 ];
147
148 buildInputs = [
149 appstream-glib # for library
150 babl
151 cfitsio
152 gegl
153 gtk3
154 glib
155 gdk-pixbuf
156 pango
157 cairo
158 libarchive
159 gexiv2
160 harfbuzz
161 isocodes
162 freetype
163 fontconfig
164 lcms
165 libpng
166 libiff
167 libilbm
168 libjpeg
169 libjxl
170 poppler
171 poppler_data
172 libtiff
173 openexr
174 libmng
175 librsvg
176 libwmf
177 zlib
178 libzip
179 ghostscript
180 aalib
181 shared-mime-info
182 json-glib
183 libwebp
184 libheif
185 python
186 libexif
187 xorg.libXpm
188 xorg.libXmu
189 glib-networking
190 libmypaint
191 mypaint-brushes1
192
193 # New file dialogue crashes with “Icon 'image-missing' not present in theme Symbolic” without an icon theme.
194 adwaita-icon-theme
195
196 # for Lua plug-ins
197 (luajit.withPackages (pp: [
198 pp.lgi
199 ]))
200 ]
201 ++ lib.optionals stdenv.hostPlatform.isLinux [
202 alsa-lib
203
204 # for JavaScript plug-ins
205 gjs
206 ]
207 ++ lib.optionals stdenv.hostPlatform.isDarwin [
208 llvmPackages.openmp
209 ]
210 ++ lib.optionals stdenv.hostPlatform.isLinux [
211 libgudev
212 ];
213
214 propagatedBuildInputs = [
215 # needed by gimp-3.0.pc
216 gegl
217 cairo
218 pango
219 gexiv2
220 ];
221
222 mesonFlags = [
223 "-Dbug-report-url=https://github.com/NixOS/nixpkgs/issues/new"
224 "-Dicc-directory=/run/current-system/sw/share/color/icc"
225 "-Dcheck-update=no"
226 (lib.mesonEnable "gudev" stdenv.hostPlatform.isLinux)
227 (lib.mesonEnable "headless-tests" stdenv.hostPlatform.isLinux)
228 (lib.mesonEnable "linux-input" stdenv.hostPlatform.isLinux)
229 # Not very important to do downstream, save a dependency.
230 "-Dappdata-test=disabled"
231 ]
232 ++ lib.optionals stdenv.hostPlatform.isDarwin [
233 "-Dalsa=disabled"
234 "-Djavascript=disabled"
235 ];
236
237 doCheck = true;
238
239 env = {
240 # The check runs before glib-networking is registered
241 GIO_EXTRA_MODULES = "${glib-networking}/lib/gio/modules";
242
243 NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-DGDK_OSX_BIG_SUR=16";
244
245 # Check if librsvg was built with --disable-pixbuf-loader.
246 PKG_CONFIG_GDK_PIXBUF_2_0_GDK_PIXBUF_MODULEDIR = "${librsvg}/${gdk-pixbuf.moduleDir}";
247 };
248
249 postPatch = ''
250 patchShebangs tools/gimp-mkenums
251
252 # GIMP is executed at build time so we need to fix this.
253 # TODO: Look into if we can fix the interp thing.
254 chmod +x plug-ins/python/{colorxhtml,file-openraster,foggify,gradients-save-as-css,histogram-export,palette-offset,palette-sort,palette-to-gradient,python-eval,spyro-plus}.py
255 patchShebangs \
256 plug-ins/python/{colorxhtml,file-openraster,foggify,gradients-save-as-css,histogram-export,palette-offset,palette-sort,palette-to-gradient,python-eval,spyro-plus}.py
257 '';
258
259 preBuild =
260 let
261 librarySuffix =
262 if stdenv.hostPlatform.extensions.library == ".so" then
263 "3.0.so.0"
264 else if stdenv.hostPlatform.extensions.library == ".dylib" then
265 "3.0.0.dylib"
266 else
267 throw "Unsupported library extension ‘${stdenv.hostPlatform.extensions.library}’";
268 in
269 ''
270 # Our gobject-introspection patches make the shared library paths absolute
271 # in the GIR files. When running GIMP in build or check phase, it will try
272 # to use plug-ins, which import GIMP introspection files which will try
273 # to load the GIMP libraries which will not be installed yet.
274 # So we need to replace the absolute path with a local one.
275 # We are using a symlink that will be overridden during installation.
276 mkdir -p "$out/lib"
277 ln -s "$PWD/libgimp/libgimp-${librarySuffix}" \
278 "$PWD/libgimpbase/libgimpbase-${librarySuffix}" \
279 "$PWD/libgimpcolor/libgimpcolor-${librarySuffix}" \
280 "$PWD/libgimpconfig/libgimpconfig-${librarySuffix}" \
281 "$PWD/libgimpmath/libgimpmath-${librarySuffix}" \
282 "$PWD/libgimpmodule/libgimpmodule-${librarySuffix}" \
283 "$out/lib/"
284 '';
285
286 preCheck = ''
287 # Avoid “Error retrieving accessibility bus address”
288 export NO_AT_BRIDGE=1
289 # Fix storing recent file list in tests
290 export HOME="$TMPDIR"
291 export XDG_DATA_DIRS="${glib.getSchemaDataDirPath gtk3}:${adwaita-icon-theme}/share:$XDG_DATA_DIRS"
292 '';
293
294 preFixup = ''
295 gappsWrapperArgs+=(--prefix PATH : "${
296 lib.makeBinPath [
297 # for dot for gegl:introspect (Debug » Show Image Graph, hidden by default on stable release)
298 graphviz
299 # for gimp-script-fu-interpreter-3.0 invoked by shebang of some plug-ins
300 "$out"
301 ]
302 }")
303 '';
304
305 postFixup = ''
306 # Cannot be in postInstall, otherwise _multioutDocs hook in preFixup will move right back.
307 moveToOutput "share/doc" "$devdoc"
308 '';
309
310 passthru = {
311 # The declarations for `gimp-with-plugins` wrapper,
312 # used for determining plug-in installation paths
313 majorVersion = "${lib.versions.major finalAttrs.version}.0";
314 targetLibDir = "lib/gimp/${finalAttrs.passthru.majorVersion}";
315 targetDataDir = "share/gimp/${finalAttrs.passthru.majorVersion}";
316 targetPluginDir = "${finalAttrs.passthru.targetLibDir}/plug-ins";
317 targetScriptDir = "${finalAttrs.passthru.targetDataDir}/scripts";
318
319 # probably its a good idea to use the same gtk in plugins ?
320 gtk = gtk3;
321 };
322
323 meta = with lib; {
324 description = "GNU Image Manipulation Program";
325 homepage = "https://www.gimp.org/";
326 maintainers = with maintainers; [ jtojnar ];
327 license = licenses.gpl3Plus;
328 platforms = platforms.linux;
329 mainProgram = "gimp";
330 };
331})