From f14038a703f7dfe066382771d20023163ee8bff1 Mon Sep 17 00:00:00 2001 From: Franz Pletz Date: Wed, 11 Aug 2021 22:06:36 +0200 Subject: [PATCH] pinentry: remove multiple outputs package fixes #133156 #124753 --- nixos/modules/programs/gnupg.nix | 5 +- pkgs/tools/security/pinentry/default.nix | 166 +++++++++++------------ pkgs/top-level/aliases.nix | 3 + pkgs/top-level/all-packages.nix | 14 +- 4 files changed, 90 insertions(+), 98 deletions(-) diff --git a/nixos/modules/programs/gnupg.nix b/nixos/modules/programs/gnupg.nix index ce8799b21d6926e..ad040408644483d 100644 --- a/nixos/modules/programs/gnupg.nix +++ b/nixos/modules/programs/gnupg.nix @@ -68,9 +68,10 @@ 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 = ""; description = '' Which pinentry interface to use. If not null, the path to the pinentry binary will be passed to gpg-agent via commandline and @@ -96,7 +97,7 @@ in systemd.user.services.gpg-agent = mkIf (cfg.agent.pinentryFlavor != null) { serviceConfig.ExecStart = [ "" '' ${cfg.package}/bin/gpg-agent --supervised \ - --pinentry-program ${pkgs.pinentry.${cfg.agent.pinentryFlavor}}/bin/pinentry + --pinentry-program ${pkgs.pinentryFlavors.${cfg.agent.pinentryFlavor}}/bin/pinentry '' ]; }; diff --git a/pkgs/tools/security/pinentry/default.nix b/pkgs/tools/security/pinentry/default.nix index 97426e0be80d961..9f7f30a6f14be89 100644 --- a/pkgs/tools/security/pinentry/default.nix +++ b/pkgs/tools/security/pinentry/default.nix @@ -1,105 +1,93 @@ -{ fetchurl, mkDerivation, fetchpatch, stdenv, lib, pkg-config, autoreconfHook, wrapGAppsHook -, libgpgerror, libassuan, qtbase, wrapQtAppsHook +{ stdenv, lib, fetchurl, fetchpatch, pkg-config, autoreconfHook, wrapGAppsHook +, libgpgerror, libassuan, libsForQt5 , ncurses, gtk2, gcr , libcap ? null, libsecret ? null -, enabledFlavors ? [ "curses" "tty" "gtk2" "emacs" ] - ++ lib.optionals stdenv.isLinux [ "gnome3" ] - ++ lib.optionals (stdenv.hostPlatform.system != "aarch64-darwin") [ "qt" ] }: -with lib; - -assert isList enabledFlavors && enabledFlavors != []; - let - pinentryMkDerivation = - if (builtins.elem "qt" enabledFlavors) - then mkDerivation - else stdenv.mkDerivation; - mkFlag = pfxTrue: pfxFalse: cond: name: "--${if cond then pfxTrue else pfxFalse}-${name}"; mkEnable = mkFlag "enable" "disable"; mkWith = mkFlag "with" "without"; - mkEnablePinentry = f: - let - info = flavorInfo.${f}; - flag = flavorInfo.${f}.flag or null; - in - optionalString (flag != null) - (mkEnable (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 = []; }; - }; - -in - -pinentryMkDerivation rec { - pname = "pinentry"; - version = "1.1.0"; - - src = fetchurl { - url = "mirror://gnupg/pinentry/${pname}-${version}.tar.bz2"; - sha256 = "0w35ypl960pczg5kp6km3dyr000m1hf0vpwwlh72jjkjza36c1v8"; + 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 ]; }; }; - nativeBuildInputs = [ pkg-config autoreconfHook ] - ++ concatMap(f: flavorInfo.${f}.nativeBuildInputs or []) enabledFlavors; - buildInputs = [ libgpgerror libassuan libcap libsecret ] - ++ concatMap(f: flavorInfo.${f}.buildInputs or []) enabledFlavors; - - dontWrapGApps = true; - dontWrapQtApps = true; - - patches = [ - ./autoconf-ar.patch - ] ++ optionals (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 = [ - (mkWith (libcap != null) "libcap") - (mkEnable (libsecret != null) "libsecret") - ] ++ (map mkEnablePinentry (attrNames flavorInfo)); - - postInstall = - concatStrings (flip map enabledFlavors (f: + buildPinentry = pnameExtra: buildFlavors: let + mkFlavorFlag = f: let - binary = "pinentry-" + flavorInfo.${f}.bin; - in '' - moveToOutput bin/${binary} ${placeholder f} - ln -sf ${placeholder f}/bin/${binary} ${placeholder f}/bin/pinentry - '' + optionalString (f == "gnome3") '' - wrapGApp ${placeholder f}/bin/${binary} - '' + optionalString (f == "qt") '' - wrapQtApp ${placeholder f}/bin/${binary} - '')) + '' - ln -sf ${placeholder (head enabledFlavors)}/bin/pinentry-${flavorInfo.${head enabledFlavors}.bin} $out/bin/pinentry - ''; - - outputs = [ "out" ] ++ enabledFlavors; - - passthru = { flavors = enabledFlavors; }; + info = flavorInfo.${f}; + flag = flavorInfo.${f}.flag or null; + in + lib.optionalString (flag != null) + (mkEnable (lib.elem f buildFlavors) ("pinentry-" + flag)); + + in stdenv.mkDerivation rec { + pname = "pinentry-${pnameExtra}"; + version = "1.1.1"; + + src = fetchurl { + url = "mirror://gnupg/pinentry/pinentry-${version}.tar.bz2"; + sha256 = "0zx5vg6wws2sp2yxwi01b8i1pnsqkydncpj7x0p8xl9y05ja04nd"; + }; + + nativeBuildInputs = [ pkg-config autoreconfHook ] + ++ lib.concatMap (f: flavorInfo.${f}.nativeBuildInputs or []) buildFlavors; + buildInputs = [ libgpgerror libassuan libcap 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 = [ + (mkWith (libcap != null) "libcap") + (mkEnable (libsecret != null) "libsecret") + ] ++ (map mkFlavorFlag (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; [ ttuegel 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); } diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix index 5a16b3c9e552fb0..bc2c10f0e8dcb3f 100644 --- a/pkgs/top-level/aliases.nix +++ b/pkgs/top-level/aliases.nix @@ -647,6 +647,9 @@ mapAliases ({ pg_hll = postgresqlPackages.pg_hll; pg_cron = postgresqlPackages.pg_cron; pg_topn = postgresqlPackages.pg_topn; + pinentry = + pinentryFlavors.all // pinentryFlavors + // { flavors = lib.attrNames pinentryFlavors; }; # added 2021-08-11 pinentry_curses = pinentry-curses; # added 2019-10-14 pinentry_emacs = pinentry-emacs; # added 2019-10-14 pinentry_gtk2 = pinentry-gtk2; # added 2019-10-14 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index dbfbd62173ccd7e..45812b41d57eaa6 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8054,15 +8054,15 @@ with pkgs; phosh = callPackage ../applications/window-managers/phosh { }; - pinentry = libsForQt5.callPackage ../tools/security/pinentry { + pinentryFlavors = lib.recurseIntoAttrs (callPackages ../tools/security/pinentry { libcap = if stdenv.isDarwin then null else libcap; - }; + }); - 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-gnome = pinentryFlavors.gnome3; + pinentry-qt = pinentryFlavors.qt; pinentry_mac = callPackage ../tools/security/pinentry/mac.nix { inherit (darwin.apple_sdk.frameworks) Cocoa;