From 538fb0390a114f9edc609162a49a99b895f52bf5 Mon Sep 17 00:00:00 2001 From: Alexander Heldt Date: Thu, 23 Jul 2026 10:56:01 +0200 Subject: [PATCH] pinwheel: set `ASKPASS` And cache the git signing key --- hosts/pinwheel/modules/git/default.nix | 37 ++++++++++++++++++++++++++ hosts/pinwheel/modules/ssh/default.nix | 14 ++++++++++ hosts/pinwheel/modules/zsh/default.nix | 8 ++++++ 3 files changed, 59 insertions(+) diff --git a/hosts/pinwheel/modules/git/default.nix b/hosts/pinwheel/modules/git/default.nix index ae17f47..94feecf 100644 --- a/hosts/pinwheel/modules/git/default.nix +++ b/hosts/pinwheel/modules/git/default.nix @@ -6,6 +6,38 @@ }: let enabled = config.mod.git.enable; + + # Wrapper around `ssh-keygen` used as git's SSH signing program. Before a + # signing operation it ensures the passphrase-protected signing key is loaded + # into the agent — `ssh-keygen -Y sign` reads the key from disk and re-prompts + # every commit otherwise, since `AddKeysToAgent` only ever caches auth keys. + # Loading it once (through the GUI askpass) lets later commits reuse the + # cached key from the agent. Verification and every other op pass straight + # through to the real ssh-keygen untouched. + sshSignWrapper = pkgs.writeShellApplication { + name = "git-ssh-sign"; + runtimeInputs = [ + pkgs.openssh + pkgs.gawk + pkgs.gnugrep + ]; + text = '' + key="${config.age.secrets."alex.pinwheel-github.com-signing".path}" + + case " $* " in + *" -Y sign "*) + fp="" + fp="$(ssh-keygen -lf "$key.pub" 2>/dev/null | awk '{print $2}')" || true + if [ -n "$fp" ] && ! ssh-add -l 2>/dev/null | grep -qF "$fp"; then + #