❄️ Dotfiles for our NixOS system configuration.
1{ lib, pkgs, osConfig, ... }: 2 3let 4 inherit (pkgs) ps util-linux socat; 5 grep = pkgs.gnugrep; 6in 7{ 8 # WSL-specific SSH agent forwarding configuration 9 # Forwards the Windows SSH agent to a Unix socket in WSL 10 programs.zsh.initContent = lib.mkIf (osConfig ? wsl) '' 11 export SSH_AUTH_SOCK=$HOME/.1password/agent.sock 12 13 ALREADY_RUNNING=$(${ps}/bin/ps -auxww | ${grep}/bin/grep -q "[n]piperelay.exe -ei -s //./pipe/openssh-ssh-agent"; echo $?) 14 15 if [[ $ALREADY_RUNNING != "0" ]]; then 16 if [[ -S $SSH_AUTH_SOCK ]]; then 17 # not expecting the socket to exist as the forwarding command isn't running (http://www.tldp.org/LDP/abs/html/fto.html) 18 rm $SSH_AUTH_SOCK 19 fi 20 21 # otherwise, we start a new ssh-agent relay 22 (${util-linux}/bin/setsid ${socat}/bin/socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &) >/dev/null 2>&1 23 fi 24 ''; 25}