lol
1{ lib, fetchurl, perlPackages, wrapGAppsHook,
2 # libs
3 librsvg, sane-backends, sane-frontends,
4 # runtime dependencies
5 imagemagick, libtiff, djvulibre, poppler_utils, ghostscript, unpaper, pdftk,
6 # test dependencies
7 xvfb-run, liberation_ttf, file, tesseract }:
8
9with lib;
10
11perlPackages.buildPerlPackage rec {
12 pname = "gscan2pdf";
13 version = "2.13.2";
14
15 src = fetchurl {
16 url = "mirror://sourceforge/gscan2pdf/gscan2pdf-${version}.tar.xz";
17 hash = "sha256-NGz6DUa7TdChpgwmD9pcGdvYr3R+Ft3jPPSJpybCW4Q=";
18 };
19
20 nativeBuildInputs = [ wrapGAppsHook ];
21
22 buildInputs =
23 [ librsvg sane-backends sane-frontends ] ++
24 (with perlPackages; [
25 Gtk3
26 Gtk3ImageView
27 Gtk3SimpleList
28 Cairo
29 CairoGObject
30 Glib
31 GlibObjectIntrospection
32 GooCanvas2
33 GraphicsTIFF
34 IPCSystemSimple
35 LocaleCodes
36 LocaleGettext
37 PDFBuilder
38 ImagePNGLibpng
39 ImageSane
40 SetIntSpan
41 ImageMagick
42 ConfigGeneral
43 ListMoreUtils
44 HTMLParser
45 ProcProcessTable
46 LogLog4perl
47 TryTiny
48 DataUUID
49 DateCalc
50 IOString
51 FilesysDf
52 SubOverride
53 ]);
54
55 postPatch = let
56 fontSubstitute = "${liberation_ttf}/share/fonts/truetype/LiberationSans-Regular.ttf";
57 in ''
58 # Required for the program to properly load its SVG assets
59 substituteInPlace bin/gscan2pdf \
60 --replace "/usr/share" "$out/share"
61
62 # Substitute the non-free Helvetica font in the tests
63 sed -i 's|-pointsize|-font ${fontSubstitute} -pointsize|g' t/*.t
64 '';
65
66 postInstall = ''
67 # Remove impurity
68 find $out -type f -name "*.pod" -delete
69
70 # Add runtime dependencies
71 wrapProgram "$out/bin/gscan2pdf" \
72 --prefix PATH : "${sane-backends}/bin" \
73 --prefix PATH : "${imagemagick}/bin" \
74 --prefix PATH : "${libtiff}/bin" \
75 --prefix PATH : "${djvulibre}/bin" \
76 --prefix PATH : "${poppler_utils}/bin" \
77 --prefix PATH : "${ghostscript}/bin" \
78 --prefix PATH : "${unpaper}/bin" \
79 --prefix PATH : "${pdftk}/bin"
80 '';
81
82 enableParallelBuilding = true;
83
84 installTargets = [ "install" ];
85
86 outputs = [ "out" "man" ];
87
88 nativeCheckInputs = [
89 imagemagick
90 libtiff
91 djvulibre
92 poppler_utils
93 ghostscript
94 unpaper
95 pdftk
96
97 xvfb-run
98 file
99 tesseract # tests are expecting tesseract 3.x precisely
100 ] ++ (with perlPackages; [
101 TestPod
102 ]);
103
104 checkPhase = ''
105 # Temporarily disable a test failing after a patch imagemagick update.
106 # It might only due to the reporting and matching used in the test.
107 # See https://github.com/NixOS/nixpkgs/issues/223446
108 # See https://sourceforge.net/p/gscan2pdf/bugs/417/
109 #
110 # Failed test 'valid TIFF created'
111 # at t/131_save_tiff.t line 44.
112 # 'test.tif TIFF 70x46 70x46+0+0 8-bit sRGB 10024B 0.000u 0:00.000
113 # '
114 # doesn't match '(?^:test.tif TIFF 70x46 70x46\+0\+0 8-bit sRGB [7|9][.\d]+K?B)'
115 rm t/131_save_tiff.t
116
117 # Temporarily disable a dubiously failing test:
118 # t/169_import_scan.t ........................... 1/1
119 # # Failed test 'variable-height scan imported with expected size'
120 # # at t/169_import_scan.t line 50.
121 # # got: '179'
122 # # expected: '296'
123 # # Looks like you failed 1 test of 1.
124 # t/169_import_scan.t ........................... Dubious, test returned 1 (wstat 256, 0x100)
125 rm t/169_import_scan.t
126
127 # Disable a test which passes but reports an incorrect status
128 # t/0601_Dialog_Scan.t .......................... All 14 subtests passed
129 # t/0601_Dialog_Scan.t (Wstat: 139 Tests: 14 Failed: 0)
130 # Non-zero wait status: 139
131 rm t/0601_Dialog_Scan.t
132
133 # Disable a test which failed due to convert returning an exit value of 1
134 # convert: negative or zero image size `/build/KL5kTVnNCi/YfgegFM53e.pnm' @ error/resize.c/ResizeImage/3743.
135 # *** unhandled exception in callback:
136 # *** "convert" unexpectedly returned exit value 1 at t/357_unpaper_rtl.t line 63.
137 rm t/357_unpaper_rtl.t
138
139 xvfb-run -s '-screen 0 800x600x24' \
140 make test
141 '';
142
143 meta = {
144 description = "A GUI to produce PDFs or DjVus from scanned documents";
145 homepage = "https://gscan2pdf.sourceforge.net/";
146 license = licenses.gpl3;
147 maintainers = with maintainers; [ pacien ];
148 };
149}