1{ config, stdenv, lib, fetchurl, pkgconfig, zlib, expat, openssl, autoconf
2, libjpeg, libpng, libtiff, freetype, fontconfig, libpaper, jbig2dec
3, libiconv, ijs, lcms2, fetchpatch
4, cupsSupport ? config.ghostscript.cups or (!stdenv.isDarwin), cups ? null
5, x11Support ? cupsSupport, xlibsWrapper ? null # with CUPS, X11 only adds very little
6}:
7
8assert x11Support -> xlibsWrapper != null;
9assert cupsSupport -> cups != null;
10
11let
12 version = "9.${ver_min}";
13 ver_min = "52";
14 sha512 = "1ksm3v4nw8acc4j817n44l1c65ijk0mr3mp4kryy17jz41bmzzql5d8vr40h59n9dmf8b2wmnbq45bj3an1zrpfagavlf0i9s436jjc";
15
16 fonts = stdenv.mkDerivation {
17 name = "ghostscript-fonts";
18
19 srcs = [
20 (fetchurl {
21 url = "mirror://sourceforge/gs-fonts/ghostscript-fonts-std-8.11.tar.gz";
22 sha256 = "00f4l10xd826kak51wsmaz69szzm2wp8a41jasr4jblz25bg7dhf";
23 })
24 (fetchurl {
25 url = "mirror://gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz";
26 sha256 = "1cxaah3r52qq152bbkiyj2f7dx1rf38vsihlhjmrvzlr8v6cqil1";
27 })
28 # ... add other fonts here
29 ];
30
31 installPhase = ''
32 mkdir "$out"
33 mv -v * "$out/"
34 '';
35 };
36
37in
38stdenv.mkDerivation rec {
39 pname = "ghostscript";
40 inherit version;
41
42 src = fetchurl {
43 url = "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs9${ver_min}/${pname}-${version}.tar.xz";
44 inherit sha512;
45 };
46
47 patches = [
48 (fetchpatch {
49 name = "CVE-2020-15900.patch";
50 url = "https://github.com/ArtifexSoftware/ghostpdl/commit/5d499272b95a6b890a1397e11d20937de000d31b.patch";
51 sha256 = "1nnnrn8q33x7nc8227ygc60f3mj4bjzrhj40sxp6dah58rb5x5jz";
52 })
53 ./urw-font-files.patch
54 ./doc-no-ref.diff
55 # rebased version of upstream http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=1b4c3669a20c,
56 # Remove on update to version > 9.52
57 ./0001-Bug-702364-Fix-missing-echogs-dependencies.patch
58 ];
59
60 outputs = [ "out" "man" "doc" ];
61
62 enableParallelBuilding = true;
63
64 nativeBuildInputs = [ pkgconfig autoconf ];
65 buildInputs =
66 [ zlib expat openssl
67 libjpeg libpng libtiff freetype fontconfig libpaper jbig2dec
68 libiconv ijs lcms2
69 ]
70 ++ lib.optional x11Support xlibsWrapper
71 ++ lib.optional cupsSupport cups
72 ;
73
74 preConfigure = ''
75 # requires in-tree (heavily patched) openjpeg
76 rm -rf jpeg libpng zlib jasper expat tiff lcms2mt jbig2dec freetype cups/libs ijs
77
78 sed "s@if ( test -f \$(INCLUDE)[^ ]* )@if ( true )@; s@INCLUDE=/usr/include@INCLUDE=/no-such-path@" -i base/unix-aux.mak
79 sed "s@^ZLIBDIR=.*@ZLIBDIR=${zlib.dev}/include@" -i configure.ac
80
81 autoconf
82 '';
83
84 configureFlags = [
85 "--with-system-libtiff"
86 "--enable-dynamic"
87 ]
88 ++ lib.optional x11Support "--with-x"
89 ++ lib.optionals cupsSupport [
90 "--enable-cups"
91 "--with-cups-serverbin=$(out)/lib/cups"
92 "--with-cups-serverroot=$(out)/etc/cups"
93 "--with-cups-datadir=$(out)/share/cups"
94 ];
95
96 doCheck = true;
97
98 # don't build/install statically linked bin/gs
99 buildFlags = [ "so" ];
100 installTargets = [ "soinstall" ];
101
102 postInstall = ''
103 ln -s gsc "$out"/bin/gs
104
105 cp -r Resource "$out/share/ghostscript/${version}"
106
107 ln -s "${fonts}" "$out/share/ghostscript/fonts"
108 '' + stdenv.lib.optionalString stdenv.isDarwin ''
109 for file in $out/lib/*.dylib* ; do
110 install_name_tool -id "$file" $file
111 done
112 '';
113
114 preFixup = lib.optionalString stdenv.isDarwin ''
115 install_name_tool -change libgs.dylib.${version} $out/lib/libgs.dylib.${version} $out/bin/gs
116 '';
117
118 passthru = { inherit version; };
119
120 meta = {
121 homepage = "https://www.ghostscript.com/";
122 description = "PostScript interpreter (mainline version)";
123
124 longDescription = ''
125 Ghostscript is the name of a set of tools that provides (i) an
126 interpreter for the PostScript language and the PDF file format,
127 (ii) a set of C procedures (the Ghostscript library) that
128 implement the graphics capabilities that appear as primitive
129 operations in the PostScript language, and (iii) a wide variety
130 of output drivers for various file formats and printers.
131 '';
132
133 license = stdenv.lib.licenses.agpl3;
134
135 platforms = stdenv.lib.platforms.all;
136 maintainers = [ stdenv.lib.maintainers.viric ];
137 };
138}