2
Setting up `ssh-agent` from `nix-env` on macOS
Matej Focko edited this page 2025-08-02 09:40:34 +02:00
-
Install the
openssh.$ nix-env -iA nixpkgs.openssh -
Disable the built-in macOS SSH agent.
$ launchctl disable gui/$UID/com.openssh.ssh-agent -
Add definition of the new
ssh-agentto~/Library/LaunchAgents/org.nix.ssh-agent.plist.<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>org.nix.ssh-agent</string> <key>ProgramArguments</key> <array> <string>/bin/sh</string> <string>-c</string> <!-- We reuse SSH_AUTH_SOCK from com.openssh.ssh-agent --> <string>rm -f $SSH_AUTH_SOCK; exec $HOME/.nix-profile/bin/ssh-agent -D -a $SSH_AUTH_SOCK</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> -
Enable the new
ssh-agent.$ launchctl bootstrap gui/$UID ~/Library/LaunchAgents/org.nix.ssh-agent.plist -
Check it's running.
$ launchctl list | grep ssh