NixOS + home-manager configs, mirrored from GitLab SaaS. gitlab.com/andreijiroh-dev/nixops-config
nix-flake nixos home-manager nixpkgs nix-flakes
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(ssh-agent-loader): add support for YubiKey SSH agent and improve XDG_RUNTIME_DIR handling

Signed-off-by: Andrei Jiroh Halili <ajhalili2006@andreijiroh.dev>

+23 -1
+23 -1
misc/bash/lib/ssh-agent-loader
··· 1 1 #!/usr/bin/env bash 2 2 3 + # Workaround in cases where XDG_RUNTIME_DIR is undefined on login 4 + if [[ ! -n "${XDG_RUNTIME_DIR}" ]]; then 5 + echo "warning: XDG_RUNTIME_DIR is possibly undefined, see https://github.com/swaywm/sway/issues/7202" 6 + echo "warning: for context and https://wiki.archlinux.org/title/XDG_Base_Directory for docs" 7 + echo "warning: setting it up for you using the default '/run/user/$(id -u)' value in 3s..." 8 + sleep 3 9 + export XDG_RUNTIME_DIR="/run/user/$(id -u)" 10 + fi 11 + 3 12 # do feature detection if keychain is installed 4 13 if command -v keychain >> /dev/null; then 5 14 FF_KEYCHAIN=1 ··· 17 26 fi 18 27 } 19 28 29 + # Ripped off NixOS-generated set-environment on my laptop for yubikey-agent setup 30 + try_yubikey_agent() { 31 + if [[ -f "${XDG_RUNTIME_DIR}/yubikey-agent/yubikey-agent.sock" ]]; then 32 + echo "[ssh-agent-loader::yubikey-agent] using YubiKey SSH Agent" 33 + export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/yubikey-agent/yubikey-agent.sock" 34 + fi 35 + } 36 + 20 37 try_1password_ssh_agent() { 21 38 export OP_SSH_AUTH_SOCK="$HOME/.1password/agent.sock" 22 39 if [[ ! -S "$OP_SSH_AUTH_SOCK" ]]; then ··· 48 65 return 49 66 elif try_keychain_ssh_agent; then 50 67 return 68 + elif try_yubikey_agent; then 69 + return 51 70 else 52 71 echo "[ssh-agent-loader] SSH agent seems to be failed to load at the moment" 53 72 echo "[ssh-agent-loader] try again later by manually invoking the shell function" ··· 58 77 try_1password_ssh_agent 59 78 elif [[ $1 == "keychain" ]]; then 60 79 try_keychain_ssh_agent 80 + elif [[ $1 == "yubikey" ]]; then 81 + try_yubikey_agent 61 82 else 62 - echo "ssh-agent-loader [auto|[1password|op|1p]|keychain]" 83 + echo "ssh-agent-loader [auto|[1password|op|1p]|keychain|yubikey]" 63 84 return 1 64 85 fi 65 86 } 66 87 88 + # automatically detect things as we source this 67 89 ssh-agent-loader auto