Skip to content

Commit

Permalink
pinentry: remove multiple outputs package
Browse files Browse the repository at this point in the history
  • Loading branch information
fpletz committed Jan 15, 2024
1 parent 031182b commit 25b85b8
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 99 deletions.
4 changes: 2 additions & 2 deletions nixos/modules/programs/gnupg.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ in
};

agent.pinentryFlavor = mkOption {
type = types.nullOr (types.enum pkgs.pinentry.flavors);
type = types.nullOr (types.enum (lib.attrNames pkgs.pinentryFlavors));
example = "gnome3";
default = defaultPinentryFlavor;
defaultText = literalMD ''matching the configured desktop environment'';
Expand Down Expand Up @@ -103,7 +103,7 @@ in
config = mkIf cfg.agent.enable {
programs.gnupg.agent.settings = {
pinentry-program = lib.mkIf (cfg.agent.pinentryFlavor != null)
"${pkgs.pinentry.${cfg.agent.pinentryFlavor}}/bin/pinentry";
"${pkgs.pinentryFlavors.${cfg.agent.pinentryFlavor}}/bin/pinentry";
};

environment.etc."gnupg/gpg-agent.conf".source =
Expand Down
176 changes: 86 additions & 90 deletions pkgs/tools/security/pinentry/default.nix
Original file line number Diff line number Diff line change
@@ -1,100 +1,96 @@
{ fetchurl, mkDerivation, fetchpatch, stdenv, lib, pkg-config, autoreconfHook, wrapGAppsHook
, libgpg-error, libassuan, qtbase, wrapQtAppsHook
{ stdenv, lib, fetchurl, fetchpatch, pkg-config, autoreconfHook, wrapGAppsHook
, libgpg-error, libassuan, libsForQt5
, ncurses, gtk2, gcr
, withLibsecret ? true, libsecret
, enabledFlavors ? [ "curses" "tty" "gtk2" "emacs" ]
++ lib.optionals stdenv.isLinux [ "gnome3" ]
++ lib.optionals (!stdenv.isDarwin) [ "qt" ]
, withLibcap ? !stdenv.isDarwin, libcap ? null
, withLibsecret ? true, libsecret ? null
}:

assert lib.isList enabledFlavors && enabledFlavors != [];

let
pinentryMkDerivation =
if (builtins.elem "qt" enabledFlavors)
then mkDerivation
else stdenv.mkDerivation;

enableFeaturePinentry = f:
let
flag = flavorInfo.${f}.flag or null;
in
lib.optionalString (flag != null)
(lib.enableFeature (lib.elem f enabledFlavors) ("pinentry-" + flag));

flavorInfo = {
curses = { bin = "curses"; flag = "curses"; buildInputs = [ ncurses ]; };
tty = { bin = "tty"; flag = "tty"; };
gtk2 = { bin = "gtk-2"; flag = "gtk2"; buildInputs = [ gtk2 ]; };
gnome3 = { bin = "gnome3"; flag = "gnome3"; buildInputs = [ gcr ]; nativeBuildInputs = [ wrapGAppsHook ]; };
qt = { bin = "qt"; flag = "qt"; buildInputs = [ qtbase ]; nativeBuildInputs = [ wrapQtAppsHook ]; };
emacs = { bin = "emacs"; flag = "emacs"; buildInputs = []; };
tty = { flag = "tty"; };
curses = { flag = "curses"; buildInputs = [ ncurses ]; };
gtk2 = { flag = "gtk2"; buildInputs = [ gtk2 ]; };
gnome3 = { flag = "gnome3"; buildInputs = [ gcr ]; nativeBuildInputs = [ wrapGAppsHook ]; };
qt = { flag = "qt"; buildInputs = [ libsForQt5.qtbase ]; nativeBuildInputs = [ libsForQt5.wrapQtAppsHook ]; };
};

in

pinentryMkDerivation rec {
pname = "pinentry";
version = "1.2.1";

src = fetchurl {
url = "mirror://gnupg/pinentry/${pname}-${version}.tar.bz2";
sha256 = "sha256-RXoYXlqFI4+5RalV3GNSq5YtyLSHILYvyfpIx1QKQGc=";
};

nativeBuildInputs = [ pkg-config autoreconfHook ]
++ lib.concatMap(f: flavorInfo.${f}.nativeBuildInputs or []) enabledFlavors;

buildInputs = [ libgpg-error libassuan ]
++ lib.optional withLibsecret libsecret
++ lib.concatMap(f: flavorInfo.${f}.buildInputs or []) enabledFlavors;

dontWrapGApps = true;
dontWrapQtApps = true;

patches = [
./autoconf-ar.patch
] ++ lib.optionals (lib.elem "gtk2" enabledFlavors) [
(fetchpatch {
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";
sha256 = "15r1axby3fdlzz9wg5zx7miv7gqx2jy4immaw4xmmw5skiifnhfd";
})
];

configureFlags = [
"--with-libgpg-error-prefix=${libgpg-error.dev}"
"--with-libassuan-prefix=${libassuan.dev}"
(lib.enableFeature withLibsecret "libsecret")
] ++ (map enableFeaturePinentry (lib.attrNames flavorInfo));

postInstall =
lib.concatStrings (lib.flip map enabledFlavors (f:
buildPinentry = pnameExtra: buildFlavors: let
enableFeaturePinentry = f:
let
binary = "pinentry-" + flavorInfo.${f}.bin;
in ''
moveToOutput bin/${binary} ${placeholder f}
ln -sf ${placeholder f}/bin/${binary} ${placeholder f}/bin/pinentry
'' + lib.optionalString (f == "gnome3") ''
wrapGApp ${placeholder f}/bin/${binary}
'' + lib.optionalString (f == "qt") ''
wrapQtApp ${placeholder f}/bin/${binary}
'')) + ''
ln -sf ${placeholder (lib.head enabledFlavors)}/bin/pinentry-${flavorInfo.${lib.head enabledFlavors}.bin} $out/bin/pinentry
'';

outputs = [ "out" ] ++ enabledFlavors;

passthru = { flavors = enabledFlavors; };
flag = flavorInfo.${f}.flag;
in
lib.enableFeature (lib.elem f buildFlavors) ("pinentry-" + flag);

pinentryMkDerivation =
if (builtins.elem "qt" buildFlavors)
then libsForQt5.mkDerivation
else stdenv.mkDerivation;

in pinentryMkDerivation rec {
pname = "pinentry-${pnameExtra}";
version = "1.2.1";

src = fetchurl {
url = "mirror://gnupg/pinentry/pinentry-${version}.tar.bz2";
sha256 = "sha256-RXoYXlqFI4+5RalV3GNSq5YtyLSHILYvyfpIx1QKQGc=";
};

nativeBuildInputs = [ pkg-config autoreconfHook ]
++ lib.concatMap (f: flavorInfo.${f}.nativeBuildInputs or []) buildFlavors;
buildInputs = [ libgpg-error libassuan ]
++ lib.optional withLibcap libcap
++ lib.optional withLibsecret libsecret
++ lib.concatMap (f: flavorInfo.${f}.buildInputs or []) buildFlavors;

dontWrapGApps = true;
dontWrapQtApps = true;

patches = [
./autoconf-ar.patch
] ++ lib.optionals (lib.elem "gtk2" buildFlavors) [
(fetchpatch {
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";
sha256 = "15r1axby3fdlzz9wg5zx7miv7gqx2jy4immaw4xmmw5skiifnhfd";
})
];

configureFlags = [
"--with-libgpg-error-prefix=${libgpg-error.dev}"
"--with-libassuan-prefix=${libassuan.dev}"
(lib.withFeature withLibcap "libcap")
(lib.enableFeature withLibsecret "libsecret")
] ++ (map enableFeaturePinentry (lib.attrNames flavorInfo));

postInstall =
lib.optionalString (lib.elem "gnome3" buildFlavors) ''
wrapGApp $out/bin/pinentry-gnome3
'' + lib.optionalString (lib.elem "qt" buildFlavors) ''
wrapQtApp $out/bin/pinentry-qt
'';

passthru = { flavors = buildFlavors; };

meta = with lib; {
homepage = "http://gnupg.org/aegypten2/";
description = "GnuPG’s interface to passphrase input";
license = licenses.gpl2Plus;
platforms =
if elem "gnome3" buildFlavors then platforms.linux else
if elem "qt" buildFlavors then (remove "aarch64-darwin" platforms.all) else
platforms.all;
longDescription = ''
Pinentry provides a console and (optional) GTK and Qt GUIs allowing users
to enter a passphrase when `gpg' or `gpg2' is run and needs it.
'';
maintainers = with maintainers; [ fpletz ];
};
};
in

meta = with lib; {
homepage = "http://gnupg.org/aegypten2/";
description = "GnuPG’s interface to passphrase input";
license = licenses.gpl2Plus;
platforms = platforms.all;
longDescription = ''
Pinentry provides a console and (optional) GTK and Qt GUIs allowing users
to enter a passphrase when `gpg' or `gpg2' is run and needs it.
'';
maintainers = with maintainers; [ ttuegel fpletz ];
};
{
curses = buildPinentry "curses" [ "curses" "tty" ];
gtk2 = buildPinentry "gtk2" [ "gtk2" "curses" "tty" ];
gnome3 = buildPinentry "gnome3" [ "gnome3" "curses" "tty" ];
qt = buildPinentry "qt" [ "qt" "curses" "tty" ];
all = buildPinentry "all" (lib.attrNames flavorInfo);
}
5 changes: 4 additions & 1 deletion pkgs/top-level/aliases.nix
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,10 @@ mapAliases ({
postgis = postgresqlPackages.postgis;
timescaledb = postgresqlPackages.timescaledb;
tsearch_extras = postgresqlPackages.tsearch_extras;

pinentry =
pinentryFlavors.all // pinentryFlavors
// { flavors = lib.attrNames pinentryFlavors; }; # added 2024-01-15
# alternatively: throw "'pinentry' has been removed. Pick an approprivate version from 'pinentryFlavors'";
pinentry_curses = throw "'pinentry_curses' has been renamed to/replaced by 'pinentry-curses'"; # Converted to throw 2023-09-10
pinentry_emacs = throw "'pinentry_emacs' has been renamed to/replaced by 'pinentry-emacs'"; # Converted to throw 2023-09-10
pinentry_gnome = throw "'pinentry_gnome' has been renamed to/replaced by 'pinentry-gnome'"; # Converted to throw 2023-09-10
Expand Down
12 changes: 6 additions & 6 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12068,13 +12068,13 @@ with pkgs;

piknik = callPackage ../tools/networking/piknik { };

pinentry = libsForQt5.callPackage ../tools/security/pinentry { };
pinentryFlavors = lib.recurseIntoAttrs (callPackages ../tools/security/pinentry {});

pinentry-curses = (lib.getOutput "curses" pinentry);
pinentry-emacs = (lib.getOutput "emacs" pinentry);
pinentry-gtk2 = (lib.getOutput "gtk2" pinentry);
pinentry-qt = (lib.getOutput "qt" pinentry);
pinentry-gnome = (lib.getOutput "gnome3" pinentry);
pinentry-curses = pinentryFlavors.curses;
pinentry-emacs = pinentryFlavors.curses;
pinentry-gtk2 = pinentryFlavors.gtk2;
pinentry-gnome3 = pinentryFlavors.gnome3;
pinentry-qt = pinentryFlavors.qt;

pinentry_mac = callPackage ../tools/security/pinentry/mac.nix {
inherit (darwin.apple_sdk.frameworks) Cocoa;
Expand Down

0 comments on commit 25b85b8

Please sign in to comment.