@@ -1,60 +1,93 @@
1−{ fetchurl, fetchpatch, stdenv, lib, pkgconfig, autoreconfHook
2−, libgpgerror, libassuan
3−, libcap ? null, libsecret ? null, ncurses ? null, gtk2 ? null, gcr ? null
4−, qt4 ? null, qt5 ? null
5−, enableEmacs ? false
1+{ fetchurl, mkDerivation, fetchpatch, stdenv, lib, pkgconfig, autoreconfHook, wrapGAppsHook
2+, libgpgerror, libassuan, qtbase, wrapQtAppsHook
3+, ncurses, gtk2, gcr
4+, libcap ? null, libsecret ? null
5+, enabledFlavors ? [ "curses" "tty" "gtk2" "qt" "gnome3" "emacs" ]
66}:
77
8−assert qt5 != null -> qt4 == null;
9−assert qt4 != null -> qt5 == null;
8+with stdenv.lib;
9+
10+assert isList enabledFlavors && enabledFlavors != [];
1011
1112let
12− mkDerivation =
13− if qt5 != null
14− then qt5.mkDerivation
13+ pinentryMkDerivation =
14+ if (builtins.elem "qt" enabledFlavors)
15+ then mkDerivation
1516 else stdenv.mkDerivation;
17+
18+ mkFlag = pfxTrue: pfxFalse: cond: name:
19+ "--${if cond then pfxTrue else pfxFalse}-${name}";
20+ mkEnable = mkFlag "enable" "disable";
21+ mkWith = mkFlag "with" "without";
22+
23+ mkEnablePinentry = f:
24+ let
25+ info = flavorInfo.${f};
26+ flag = flavorInfo.${f}.flag or null;
27+ in
28+ optionalString (flag != null)
29+ (mkEnable (elem f enabledFlavors) ("pinentry-" + flag));
30+
31+ flavorInfo = {
32+ curses = { bin = "curses"; flag = "curses"; buildInputs = [ ncurses ]; };
33+ tty = { bin = "tty"; flag = "tty"; };
34+ gtk2 = { bin = "gtk-2"; flag = "gtk2"; buildInputs = [ gtk2 ]; };
35+ gnome3 = { bin = "gnome3"; flag = "gnome3"; buildInputs = [ gcr ]; nativeBuildInputs = [ wrapGAppsHook ]; };
36+ qt = { bin = "qt"; flag = "qt"; buildInputs = [ qtbase ]; nativeBuildInputs = [ wrapQtAppsHook ]; };
37+ emacs = { bin = "emacs"; flag = "emacs"; buildInputs = []; };
38+ };
39+
1640in
1741
18−mkDerivation rec {
19− name = "pinentry-1.1.0";
42+pinentryMkDerivation rec {
43+ pname = "pinentry";
44+ version = "1.1.0";
2045
2146 src = fetchurl {
22− url = "mirror://gnupg/pinentry/${name}.tar.bz2";
47+ url = "mirror://gnupg/pinentry/${pname}-${version}.tar.bz2";
2348 sha256 = "0w35ypl960pczg5kp6km3dyr000m1hf0vpwwlh72jjkjza36c1v8";
2449 };
2550
26− nativeBuildInputs = [ pkgconfig autoreconfHook ];
27− buildInputs =
28− [ libgpgerror libassuan libcap libsecret gtk2 gcr ncurses qt4 ]
29− ++ stdenv.lib.optional (qt5 != null) qt5.qtbase;
51+ nativeBuildInputs = [ pkgconfig autoreconfHook ]
52+ ++ concatMap(f: flavorInfo.${f}.nativeBuildInputs or []) enabledFlavors;
53+ buildInputs = [ libgpgerror libassuan libcap libsecret ]
54+ ++ concatMap(f: flavorInfo.${f}.buildInputs or []) enabledFlavors;
3055
31− prePatch = ''
32− substituteInPlace pinentry/pinentry-curses.c --replace ncursesw ncurses
33− '';
56+ dontWrapGApps = true;
57+ dontWrapQtApps = true;
3458
3559 patches = [
3660 ./autoconf-ar.patch
37− ] ++ lib.optionals (gtk2 != null) [
61+ ] ++ optionals (elem "gtk2" enabledFlavors) [
3862 (fetchpatch {
39− url = "https://salsa.debian.org/debian/pinentry/raw/debian/1.1.0-1/debian/patches/"
40− + "0007-gtk2-When-X11-input-grabbing-fails-try-again-over-0..patch";
63+ url = "https://salsa.debian.org/debian/pinentry/raw/debian/1.1.0-1/debian/patches/0007-gtk2-When-X11-input-grabbing-fails-try-again-over-0..patch";
4164 sha256 = "15r1axby3fdlzz9wg5zx7miv7gqx2jy4immaw4xmmw5skiifnhfd";
4265 })
4366 ];
4467
4568 configureFlags = [
46− (stdenv.lib.withFeature (libcap != null) "libcap")
47− (stdenv.lib.enableFeature (libsecret != null) "libsecret")
48− (stdenv.lib.enableFeature (ncurses != null) "pinentry-curses")
49− (stdenv.lib.enableFeature true "pinentry-tty")
50− (stdenv.lib.enableFeature enableEmacs "pinentry-emacs")
51− (stdenv.lib.enableFeature (gtk2 != null) "pinentry-gtk2")
52− (stdenv.lib.enableFeature (gcr != null) "pinentry-gnome3")
53− (stdenv.lib.enableFeature (qt4 != null || qt5 != null) "pinentry-qt")
54−
55− "--with-libassuan-prefix=${libassuan.dev}"
56− "--with-libgpg-error-prefix=${libgpgerror.dev}"
57− ];
69+ (mkWith (libcap != null) "libcap")
70+ (mkEnable (libsecret != null) "libsecret")
71+ ] ++ (map mkEnablePinentry (attrNames flavorInfo));
72+
73+ postInstall =
74+ concatStrings (flip map enabledFlavors (f:
75+ let
76+ binary = "pinentry-" + flavorInfo.${f}.bin;
77+ in ''
78+ moveToOutput bin/${binary} ${placeholder f}
79+ ln -sf ${placeholder f}/bin/${binary} ${placeholder f}/bin/pinentry
80+ '' + optionalString (f == "gnome3") ''
81+ wrapGApp ${placeholder f}/bin/${binary}
82+ '' + optionalString (f == "qt") ''
83+ wrapQtApp ${placeholder f}/bin/${binary}
84+ '')) + ''
85+ ln -sf ${placeholder (head enabledFlavors)}/bin/pinentry-${flavorInfo.${head enabledFlavors}.bin} $out/bin/pinentry
86+ '';
87+
88+ outputs = [ "out" ] ++ enabledFlavors;
89+
90+ passthru = { flavors = enabledFlavors; };
5891
5992 meta = with stdenv.lib; {
6093 homepage = http://gnupg.org/aegypten2/;
@@ -65,6 +98,6 @@ mkDerivation rec {
6598 Pinentry provides a console and (optional) GTK and Qt GUIs allowing users
6699 to enter a passphrase when `gpg' or `gpg2' is run and needs it.
67100 '';
68− maintainers = [ maintainers.ttuegel ];
101+ maintainers = with maintainers; [ ttuegel fpletz ];
69102 };
70103}