{
  pkgs,
  lib,
  ...
}: let
  gpgUpdateTty = pkgs.writeShellScript "gpgUpdateTty" ''
    ${pkgs.gnupg}/bin/gpg-connect-agent updatestartuptty /bye > /dev/null
  '';
  writeGpgWrapper = pkg: let
    bin = lib.getExe pkg;
    binName = lib.last (lib.splitString "/" bin);
  in
    pkgs.writeShellScriptBin binName ''
      ${gpgUpdateTty}
      exec ${bin} "$@"
    '';
  wrapForGpg = pkg:
    pkgs.symlinkJoin {
      name = "${lib.getName pkg}-wrapped-for-gpg";
      paths = [
        (writeGpgWrapper pkg)
        pkg
      ];
    };
in {
  nixpkgs.overlays = [
    (final: prev: {
      openssh-wrapped = wrapForGpg final.openssh;
      git-wrapped = wrapForGpg final.git;
      pijul-wrapped = wrapForGpg final.pijul;
    })
  ];
}