25 , cupsSupport ? config.ghostscript.cups or (!stdenv.hostPlatform.isDarwin)
27 , x11Support ? cupsSupport
28 , xorg # with CUPS, X11 only adds very little
29 , dynamicDrivers ? true
41 fonts = stdenv.mkDerivation {
42 name = "ghostscript-fonts";
46 url = "mirror://sourceforge/gs-fonts/ghostscript-fonts-std-8.11.tar.gz";
47 hash = "sha256-DrbzVhGfLkmyVjIQhS4X9X+dzFdV81Cmmkag1kGgxAE=";
50 url = "mirror://gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz";
51 hash = "sha256-gUbMzEaZ/p2rhBRGvdFwOfR2nJA+zrVECRiLkgdUqrM=";
53 # ... add other fonts here
63 stdenv.mkDerivation rec {
64 pname = "ghostscript${lib.optionalString x11Support "-with-X"}";
68 url = "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs${lib.replaceStrings ["."] [""] version}/ghostscript-${version}.tar.xz";
69 hash = "sha256-Un7vC2zQTs8cjXoReWxppS00/+Nq/KhqQAcpovwByIc=";
73 ./urw-font-files.patch
77 outputs = [ "out" "man" "doc" "fonts" ];
79 enableParallelBuilding = true;
82 buildPackages.stdenv.cc
85 nativeBuildInputs = [ pkg-config autoconf zlib ]
86 ++ lib.optional cupsSupport cups
87 ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
91 libjpeg libpng libtiff freetype fontconfig libpaper jbig2dec
92 libiconv ijs lcms2 bash openjpeg
94 ++ lib.optionals x11Support [ xorg.libICE xorg.libX11 xorg.libXext xorg.libXt ]
95 ++ lib.optional cupsSupport cups
99 # https://ghostscript.com/doc/current/Make.htm
100 export CCAUX=$CC_FOR_BUILD
101 ${lib.optionalString cupsSupport ''export CUPSCONFIG="${cups.dev}/bin/cups-config"''}
103 rm -rf jpeg libpng zlib jasper expat tiff lcms2mt jbig2dec freetype cups/libs ijs openjpeg
105 sed "s@if ( test -f \$(INCLUDE)[^ ]* )@if ( true )@; s@INCLUDE=/usr/include@INCLUDE=/no-such-path@" -i base/unix-aux.mak
106 sed "s@^ZLIBDIR=.*@ZLIBDIR=${zlib.dev}/include@" -i configure.ac
112 "--with-system-libtiff"
113 "--without-tesseract"
114 ] ++ lib.optionals dynamicDrivers [
116 "--disable-hidden-visibility"
117 ] ++ lib.optionals x11Support [
119 ] ++ lib.optionals cupsSupport [
123 # make check does nothing useful
126 # don't build/install statically linked bin/gs
127 buildFlags = [ "so" ]
128 # without -headerpad, the following error occurs on Darwin when compiling with X11 support (as of 10.02.0)
129 # error: install_name_tool: changing install names or rpaths can't be redone for: [...]libgs.dylib.10 (the program must be relinked, and you may need to use -headerpad or -headerpad_max_install_names)
130 ++ lib.optional (x11Support && stdenv.hostPlatform.isDarwin) "LDFLAGS=-headerpad_max_install_names";
131 installTargets = [ "soinstall" ];
134 ln -s gsc "$out"/bin/gs
136 cp -r Resource "$out/share/ghostscript/${version}"
138 mkdir -p $fonts/share/fonts
139 cp -rv ${fonts}/* "$fonts/share/fonts/"
140 ln -s "$fonts/share/fonts" "$out/share/ghostscript/fonts"
143 # dynamic library name only contains major version number, eg. '10'
144 dylib_version = lib.versions.major version;
145 preFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
146 for file in $out/bin/{gs,gsc,gsx}; do
147 install_name_tool -change libgs.$dylib_version.dylib $out/lib/libgs.$dylib_version.dylib $file
151 # validate dynamic linkage
152 doInstallCheck = true;
153 installCheckPhase = ''
154 runHook preInstallCheck
156 $out/bin/gs --version
157 $out/bin/gsx --version
159 for f in *.{ps,eps,pdf}; do
165 -sOutputFile=/dev/null \
167 -dBufferSpace=100000 \
172 runHook postInstallCheck
176 test-corpus-render = callPackage ./test-corpus-render.nix {};
177 inherit graphicsmagick imagemagick libspectre lilypond pstoedit;
178 inherit (python3.pkgs) matplotlib;
182 homepage = "https://www.ghostscript.com/";
183 description = "PostScript interpreter (mainline version)";
185 Ghostscript is the name of a set of tools that provides (i) an
186 interpreter for the PostScript language and the PDF file format,
187 (ii) a set of C procedures (the Ghostscript library) that
188 implement the graphics capabilities that appear as primitive
189 operations in the PostScript language, and (iii) a wide variety
190 of output drivers for various file formats and printers.
192 license = lib.licenses.agpl3Plus;
193 platforms = lib.platforms.all;
194 maintainers = [ lib.maintainers.tobim ];