This recipe allows you to use the ssh-agent from nix-env with the auto generated SSH_AUTH_SOCK in /private/tmp. It works because disabling com.openssh.ssh-agent doesn't stop launchd from allocating SSH_AUTH_SOCK. com.nix.ssh-agent spawns a shell to remove the socket and then execute the homebrew ssh-agent.
- Install openssh from nix:
nix-env --install --attr nikpkgs.openssh
- Disable the built in macOS agent:
launchctl disable gui/$UID/com.openssh.ssh-agent
- Copy com.nix.ssh-agent.plist into ~/Library/LaunchAgents
- Enable the new agent:
launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.nix.ssh-agent.plist
- Ensure that the correct agent is running: