mirror of
https://github.com/aviallon/nixos-lib.git
synced 2026-04-06 01:38:06 +00:00
[General+Packages] Add pinentry dynamic switcher wrapper
Dynamically accomodate different desktops
This commit is contained in:
parent
50f523ad0b
commit
3fa8298db2
2 changed files with 49 additions and 0 deletions
13
general.nix
13
general.nix
|
|
@ -108,6 +108,19 @@ in
|
||||||
enable = true;
|
enable = true;
|
||||||
enableSSHSupport = true;
|
enableSSHSupport = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
systemd.user.services.gpg-agent = let
|
||||||
|
pinentrySwitcher = pkgs.callPackage ./packages/pinentry.nix {};
|
||||||
|
cfg = config.programs.gnupg;
|
||||||
|
in {
|
||||||
|
restartTriggers = [ pinentrySwitcher ];
|
||||||
|
restartIfChanged = true;
|
||||||
|
|
||||||
|
serviceConfig.ExecStart = [ "" ''
|
||||||
|
${cfg.package}/bin/gpg-agent --supervised \
|
||||||
|
--pinentry-program ${pinentrySwitcher}/bin/pinentry
|
||||||
|
'' ];
|
||||||
|
};
|
||||||
|
|
||||||
documentation.man.generateCaches = true;
|
documentation.man.generateCaches = true;
|
||||||
|
|
||||||
|
|
|
||||||
36
packages/pinentry.nix
Normal file
36
packages/pinentry.nix
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
{ writeShellScriptBin, pinentry, ... }:
|
||||||
|
writeShellScriptBin "pinentry" ''
|
||||||
|
flavor=
|
||||||
|
if [ -n "$XDG_CURRENT_DESKTOP" ]; then
|
||||||
|
case "$XDG_CURRENT_DESKTOP" in
|
||||||
|
KDE|LXQT)
|
||||||
|
flavor="qt" ;;
|
||||||
|
XFCE)
|
||||||
|
flavor="gtk2" ;;
|
||||||
|
Gnome)
|
||||||
|
flavor="gnome3" ;;
|
||||||
|
*)
|
||||||
|
echo "Unknown desktop '$XDG_CURRENT_DESKTOP', use 'gnome3'" >&2
|
||||||
|
flavor="gnome3" ;;
|
||||||
|
esac
|
||||||
|
elif [ -z "$XAUTHORITY" -a -z "$WAYLAND_DISPLAY" ]; then
|
||||||
|
echo "No Xauthority nor Wayland display, using curses" >&2
|
||||||
|
flavor="curses"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$flavor" ]; then
|
||||||
|
echo "WARNING: pinentry flavor could not be detected, use 'curses'" >&2
|
||||||
|
flavor="curses"
|
||||||
|
fi
|
||||||
|
|
||||||
|
declare -A pinentryFlavors
|
||||||
|
pinentryFlavors["qt"]="${pinentry.qt}"
|
||||||
|
pinentryFlavors["gtk2"]="${pinentry.gtk2}"
|
||||||
|
pinentryFlavors["gnome"]="${pinentry.gnome3}"
|
||||||
|
pinentryFlavors["curses"]="${pinentry.curses}"
|
||||||
|
|
||||||
|
echo "Selected flavor: $flavor" >&2
|
||||||
|
|
||||||
|
exec ''${pinentryFlavors[$flavor]}/bin/pinentry
|
||||||
|
''
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue