···6363 matchBlocks = {
6464 # For git/jj over SSH, try the local YubiKey-backed security key
6565 # first. If the key is not plugged in, OpenSSH will continue on to
6666- # identities exposed by the 1Password SSH agent.
6666+ # whatever agent SSH_AUTH_SOCK points at (1Password locally, or a
6767+ # forwarded agent inside `ssh -A` sessions).
6768 "git-forges" = {
6869 host = "github.com gist.github.com codeberg.org gitlab.com";
6970 identityFile = [
7071 "${config.home.homeDirectory}/.ssh/id_ed25519_sk_rk"
7171- ];
7272- identityAgent = [
7373- "${config.home.homeDirectory}/.1password/agent.sock"
7472 ];
7573 };
7674 "*" = {
···10199 AWS_SHARED_CREDENTIALS_FILE = config.age.secrets.aws-credentials.path;
102100 };
103101104104- # Only point at the local 1Password agent when not inside an SSH
105105- # session — otherwise we'd clobber the forwarded agent from `ssh -A`
106106- # and lose access to the laptop's YubiKey.
102102+ # Prefer forwarded agents inside SSH sessions. Some login shells source
103103+ # hm-session-vars after sshd has set SSH_AUTH_SOCK, so recover sshd's
104104+ # original value from the parent process before falling back to the local
105105+ # 1Password GUI agent on graphical/local sessions.
107106 home.sessionVariablesExtra = ''
108108- if [ -z "$SSH_CONNECTION" ]; then
107107+ if [ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ]; then
108108+ forwarded_sock=$(tr '\0' '\n' < "/proc/$PPID/environ" 2>/dev/null | sed -n 's/^SSH_AUTH_SOCK=//p' | head -n1)
109109+ if [ -n "$forwarded_sock" ] && [ -S "$forwarded_sock" ]; then
110110+ export SSH_AUTH_SOCK="$forwarded_sock"
111111+ fi
112112+ elif [ -S "${config.home.homeDirectory}/.1password/agent.sock" ]; then
109113 export SSH_AUTH_SOCK="${config.home.homeDirectory}/.1password/agent.sock"
110114 fi
111115 '';
+8-4
modules/shell.nix
···8989 };
9090 interactiveShellInit = ''
9191 set fish_greeting
9292- # Set 1Password SSH agent socket, but only when not inside an
9393- # SSH session — otherwise preserve the forwarded agent from
9494- # `ssh -A` so YubiKey signing keeps working on remote hosts.
9595- if not set -q SSH_CONNECTION
9292+ # Prefer forwarded agents inside SSH sessions. Otherwise use the
9393+ # local 1Password GUI agent when available.
9494+ if set -q SSH_CONNECTION; or set -q SSH_CLIENT
9595+ set forwarded_sock (tr '\0' '\n' < /proc/$PPID/environ 2>/dev/null | sed -n 's/^SSH_AUTH_SOCK=//p' | head -n1)
9696+ if test -n "$forwarded_sock"; and test -S "$forwarded_sock"
9797+ set -gx SSH_AUTH_SOCK "$forwarded_sock"
9898+ end
9999+ else if test -S ${config.home.homeDirectory}/.1password/agent.sock
96100 set -gx SSH_AUTH_SOCK ${config.home.homeDirectory}/.1password/agent.sock
97101 end
98102 # Load 1Password CLI plugins