1{
2 lib,
3 stdenv,
4 fetchurl,
5 fetchFromGitLab,
6 cairo,
7 cmake,
8 boost,
9 curl,
10 fontconfig,
11 freetype,
12 glib,
13 lcms,
14 libiconv,
15 libintl,
16 libjpeg,
17 libtiff,
18 ninja,
19 openjpeg,
20 pkg-config,
21 python3,
22 zlib,
23 withData ? true,
24 poppler_data,
25 qt5Support ? false,
26 qt6Support ? false,
27 qtbase ? null,
28 introspectionSupport ? false,
29 gobject-introspection ? null,
30 gpgmeSupport ? false,
31 gpgme ? null,
32 utils ? false,
33 nss ? null,
34 minimal ? false,
35 suffix ? "glib",
36
37 # for passthru.tests
38 cups-filters,
39 gdal,
40 gegl,
41 inkscape,
42 pdfslicer,
43 scribus,
44 vips,
45}:
46
47let
48 mkFlag = optset: flag: "-DENABLE_${flag}=${if optset then "on" else "off"}";
49
50 # unclear relationship between test data repo versions and poppler
51 # versions, though files don't appear to be updated after they're
52 # added, so it's probably safe to just always use the latest available
53 # version.
54 testData = fetchFromGitLab {
55 domain = "gitlab.freedesktop.org";
56 owner = "poppler";
57 repo = "test";
58 rev = "91ee031c882634c36f2f0f2f14eb6646dd542fb9";
59 hash = "sha256-bImTdlhMAA79kwbKPrHN3a9vVrtsgBh3rFjH3B7tEbQ=";
60 };
61in
62stdenv.mkDerivation (finalAttrs: {
63 pname = "poppler-${suffix}";
64 version = "25.05.0"; # beware: updates often break cups-filters build, check scribus too!
65
66 outputs = [
67 "out"
68 "dev"
69 ];
70
71 src = fetchurl {
72 url = "https://poppler.freedesktop.org/poppler-${finalAttrs.version}.tar.xz";
73 hash = "sha256-mxYnxbdoFqxeQFKgP1tgW6QLRc8GsCyt0EeWILSZqzg=";
74 };
75
76 nativeBuildInputs = [
77 cmake
78 ninja
79 pkg-config
80 python3
81 ]
82 ++ lib.optionals (!minimal) [
83 glib # for glib-mkenums
84 ];
85
86 buildInputs = [
87 boost
88 libiconv
89 libintl
90 ]
91 ++ lib.optionals withData [
92 poppler_data
93 ];
94
95 # TODO: reduce propagation to necessary libs
96 propagatedBuildInputs = [
97 zlib
98 freetype
99 fontconfig
100 libjpeg
101 openjpeg
102 ]
103 ++ lib.optionals (!minimal) [
104 cairo
105 lcms
106 libtiff
107 curl
108 nss
109 ]
110 ++ lib.optionals (qt5Support || qt6Support) [
111 qtbase
112 ]
113 ++ lib.optionals introspectionSupport [
114 gobject-introspection
115 ]
116 ++ lib.optionals gpgmeSupport [
117 gpgme
118 ];
119
120 cmakeFlags = [
121 (mkFlag true "UNSTABLE_API_ABI_HEADERS") # previously "XPDF_HEADERS"
122 (mkFlag (!minimal) "GLIB")
123 (mkFlag (!minimal) "CPP")
124 (mkFlag (!minimal) "LIBCURL")
125 (mkFlag (!minimal) "LCMS")
126 (mkFlag (!minimal) "LIBTIFF")
127 (mkFlag (!minimal) "NSS3")
128 (mkFlag utils "UTILS")
129 (mkFlag qt5Support "QT5")
130 (mkFlag qt6Support "QT6")
131 (mkFlag gpgmeSupport "GPGME")
132 ]
133 ++ lib.optionals finalAttrs.finalPackage.doCheck [
134 "-DTESTDATADIR=${testData}"
135 ];
136 disallowedReferences = lib.optional finalAttrs.finalPackage.doCheck testData;
137
138 dontWrapQtApps = true;
139
140 # Workaround #54606
141 preConfigure = lib.optionalString stdenv.hostPlatform.isDarwin ''
142 sed -i -e '1i cmake_policy(SET CMP0025 NEW)' CMakeLists.txt
143 '';
144
145 # Work around gpgme trying to write to $HOME during qt5 and qt6 tests:
146 preCheck = lib.optionalString gpgmeSupport ''
147 HOME_orig="$HOME"
148 export HOME="$(mktemp -d)"
149 '';
150
151 postCheck = lib.optionalString gpgmeSupport ''
152 export HOME="$HOME_orig"
153 unset -v HOME_orig
154 '';
155
156 doCheck = true;
157
158 passthru = {
159 inherit testData;
160 tests = {
161 # These depend on internal poppler code that frequently changes.
162 inherit
163 cups-filters
164 inkscape
165 scribus
166 ;
167
168 inherit
169 gegl
170 pdfslicer
171 vips
172 ;
173 gdal = gdal.override { usePoppler = true; };
174 python-poppler-qt5 = python3.pkgs.poppler-qt5;
175 };
176 };
177
178 meta = {
179 homepage = "https://poppler.freedesktop.org/";
180 changelog = "https://gitlab.freedesktop.org/poppler/poppler/-/blob/poppler-${finalAttrs.version}/NEWS";
181 description = "PDF rendering library";
182 longDescription = ''
183 Poppler is a PDF rendering library based on the xpdf-3.0 code base. In
184 addition it provides a number of tools that can be installed separately.
185 '';
186 license = with lib.licenses; [ gpl2Plus ];
187 platforms = lib.platforms.all;
188 maintainers = with lib.maintainers; [ ttuegel ];
189 teams = [ lib.teams.freedesktop ];
190 };
191})