1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 fetchpatch,
6 imagemagickBig,
7 pkg-config,
8 withXorg ? true,
9 libX11,
10 libv4l,
11 qtbase,
12 qtx11extras,
13 wrapQtAppsHook,
14 wrapGAppsHook3,
15 gtk3,
16 xmlto,
17 docbook_xsl,
18 autoreconfHook,
19 dbus,
20 enableVideo ? stdenv.hostPlatform.isLinux,
21 # The implementation is buggy and produces an error like
22 # Name Error (Connection ":1.4380" is not allowed to own the service "org.linuxtv.Zbar" due to security policies in the configuration file)
23 # for every scanned code.
24 # see https://github.com/mchehab/zbar/issues/104
25 enableDbus ? false,
26 libintl,
27 libiconv,
28 bash,
29 python3,
30 argp-standalone,
31}:
32
33stdenv.mkDerivation rec {
34 pname = "zbar";
35 version = "0.23.93";
36
37 outputs = [
38 "out"
39 "lib"
40 "dev"
41 "doc"
42 "man"
43 ];
44
45 src = fetchFromGitHub {
46 owner = "mchehab";
47 repo = "zbar";
48 rev = version;
49 sha256 = "sha256-6gOqMsmlYy6TK+iYPIBsCPAk8tYDliZYMYeTOidl4XQ=";
50 };
51
52 patches = [
53 # Fix build, remove these two patches on a release beyond 0.23.93.
54 (fetchpatch {
55 name = "variable-pkg-config-path.patch";
56 url = "https://github.com/mchehab/zbar/commit/368571ffa1a0f6cc41f708dd0d27f9b6e9409df8.patch";
57 hash = "sha256-4VEuGAyR7rcIijPLlh4pzL82ESm99Wb35PV/FbY9H6Y=";
58 })
59 (fetchpatch {
60 name = "qt5-detection-fix.patch";
61 url = "https://github.com/mchehab/zbar/commit/a549566ea11eb03622bd4458a1728ffe3f589163.patch";
62 hash = "sha256-NY3bAElwNvGP9IR6JxUf62vbjx3hONrqu9pMSqaZcLY=";
63 })
64 ];
65
66 nativeBuildInputs = [
67 pkg-config
68 xmlto
69 autoreconfHook
70 docbook_xsl
71 ]
72 ++ lib.optionals enableVideo [
73 wrapGAppsHook3
74 wrapQtAppsHook
75 qtbase
76 ];
77
78 buildInputs = [
79 imagemagickBig
80 libintl
81 ]
82 ++ lib.optionals stdenv.hostPlatform.isDarwin [
83 libiconv
84 ]
85 ++ lib.optionals enableDbus [
86 dbus
87 ]
88 ++ lib.optionals withXorg [
89 libX11
90 ]
91 ++ lib.optionals enableVideo [
92 libv4l
93 gtk3
94 qtbase
95 qtx11extras
96 ];
97
98 nativeCheckInputs = [
99 bash
100 python3
101 ];
102
103 checkInputs = lib.optionals stdenv.hostPlatform.isDarwin [
104 argp-standalone
105 ];
106
107 # fix iconv linking on macOS
108 preConfigure = lib.optionalString stdenv.hostPlatform.isDarwin ''
109 export LDFLAGS="-liconv"
110 '';
111
112 # Note: postConfigure instead of postPatch in order to include some
113 # autoconf-generated files. The template files for the autogen'd scripts are
114 # not chmod +x, so patchShebangs misses them.
115 postConfigure = ''
116 patchShebangs test
117 '';
118
119 # Disable assertions which include -dev QtBase file paths.
120 env.NIX_CFLAGS_COMPILE = "-DQT_NO_DEBUG";
121
122 configureFlags = [
123 "--without-python"
124 ]
125 ++ (
126 if enableDbus then
127 [
128 "--with-dbusconfdir=${placeholder "out"}/share"
129 ]
130 else
131 [
132 "--without-dbus"
133 ]
134 )
135 ++ (
136 if enableVideo then
137 [
138 "--with-gtk=gtk3"
139 ]
140 else
141 [
142 "--disable-video"
143 "--without-gtk"
144 "--without-qt"
145 ]
146 );
147
148 doCheck = true;
149
150 preCheck = lib.optionalString stdenv.hostPlatform.isDarwin ''
151 export NIX_LDFLAGS="$NIX_LDFLAGS -largp"
152 '';
153
154 dontWrapQtApps = true;
155 dontWrapGApps = true;
156
157 postFixup = lib.optionalString enableVideo ''
158 wrapGApp "$out/bin/zbarcam-gtk"
159 wrapQtApp "$out/bin/zbarcam-qt"
160 '';
161
162 enableParallelBuilding = true;
163
164 meta = with lib; {
165 description = "Bar code reader";
166 longDescription = ''
167 ZBar is an open source software suite for reading bar codes from various
168 sources, such as video streams, image files and raw intensity sensors. It
169 supports many popular symbologies (types of bar codes) including
170 EAN-13/UPC-A, UPC-E, EAN-8, Code 128, Code 39, Interleaved 2 of 5 and QR
171 Code.
172 '';
173 maintainers = with maintainers; [ raskin ];
174 platforms = platforms.unix;
175 license = licenses.lgpl21;
176 homepage = "https://github.com/mchehab/zbar";
177 mainProgram = "zbarimg";
178 };
179}