git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/gnupg: add option for setting pinentry flavours

Co-authored-by: Florian Klink <flokli@flokli.de>

commitedea9fed725339a42f94f42139b8f9d2af0de5ee authorFranz Pletz <fpletz@fnordicwalking.de> dateSat 27 Oct 2018, 16:02 (8 years ago) parent66081ce
2 files changed+43−2
nixos/modules/installer/tools/tools.nix+5−1 nixos/modules/programs/gnupg.nix+38−1
nixos/modules/installer/tools/tools.nix+5−1
@@ -120,7 +120,11 @@ in
120120 # Some programs need SUID wrappers, can be configured further or are
121121 # started in user sessions.
122122 # programs.mtr.enable = true;
123− # programs.gnupg.agent = { enable = true; enableSSHSupport = true; };
123+ # programs.gnupg.agent = {
124+ # enable = true;
125+ # enableSSHSupport = true;
126+ # flavour = "gnome3";
127+ # };
124128
125129 # List services that you want to enable:
126130
nixos/modules/programs/gnupg.nix+38−1
@@ -6,6 +6,19 @@ let
66
77 cfg = config.programs.gnupg;
88
9+ xserverCfg = config.services.xserver;
10+
11+ defaultPinentryFlavor =
12+ if xserverCfg.desktopManager.lxqt.enable
13+ || xserverCfg.desktopManager.plasma5.enable then
14+ "qt"
15+ else if xserverCfg.desktopManager.xfce.enable then
16+ "gtk2"
17+ else if xserverCfg.enable then
18+ "gnome3"
19+ else
20+ null;
21+
922in
1023
1124{
@@ -54,6 +67,20 @@ in
5467 '';
5568 };
5669
70+ agent.pinentryFlavor = mkOption {
71+ type = types.nullOr (types.enum pkgs.pinentry.flavors);
72+ example = "gnome3";
73+ description = ''
74+ Which pinentry interface to use. If not null, the path to the
75+ pinentry binary will be passed to gpg-agent via commandline and
76+ thus overrides the pinentry option in gpg-agent.conf in the user's
77+ home directory.
78+ If not set at all, it'll pick an appropriate flavor depending on the
79+ system configuration (qt3 flavor for lxqt and plasma5, gtk2 for xfce
80+ 4.12, gnome3 on all other systems with X enabled, ncurses otherwise).
81+ '';
82+ };
83+
5784 dirmngr.enable = mkOption {
5885 type = types.bool;
5986 default = false;
@@ -64,6 +91,16 @@ in
6491 };
6592
6693 config = mkIf cfg.agent.enable {
94+ programs.gnupg.agent.pinentryFlavor = mkDefault defaultPinentryFlavor;
95+
96+ # This overrides the systemd user unit shipped with the gnupg package
97+ systemd.user.services.gpg-agent = mkIf (cfg.agent.pinentryFlavor != null) {
98+ serviceConfig.ExecStart = [ "" ''
99+ ${pkgs.gnupg}/bin/gpg-agent --supervised \
100+ --pinentry-program ${pkgs.pinentry.${cfg.agent.pinentryFlavor}}/bin/pinentry
101+ '' ];
102+ };
103+
67104 systemd.user.sockets.gpg-agent = {
68105 wantedBy = [ "sockets.target" ];
69106 };
@@ -83,7 +120,7 @@ in
83120 systemd.user.sockets.dirmngr = mkIf cfg.dirmngr.enable {
84121 wantedBy = [ "sockets.target" ];
85122 };
86−
123+
87124 environment.systemPackages = with pkgs; [ cfg.package ];
88125 systemd.packages = [ cfg.package ];
89126