Vscode-remote-ssh not forwarding agent and complaining about /bin/sh

I got vscode-remote-ssh (both ends running nixos) working with @mudrii 's hack from here, slightly modified [^1].

However, when opening a remote host, my agent forwarding doesn’t appear to work, causing git access (with gitgraph) to be broken.
The issue appears to be that the agent socket is set wrongly in the remote vscode env:


instead of


which I should get with a normal forwarded ssh agent.

When opening the remote, I also get the following error (a few times):

The terminal process failed to launch: Path to shell executable "/bin/sh" does not exist.

but in the end I do get a working remote integrated terminal as expected. I suspect however, that somewhere along the failed shell starts the correct forwarded socket/env gets lost, causing me to end up with a “default”/local env.

I tried to explicitly set terminal.integrated.profiles.linux: and related settings on both ends, without effect.

[^1]: I had to add this to make the server actually start unattended correctly:

sed -i -r 's/^(.*server-main.js")\s+(.*)$/\1 --accept-server-license-terms \2/g' "$bin_dir/bin/code-server"
[[ -f "$bin_dir/server.sh" ]] && ln -sf "$bin_dir/bin/code-server" "$bin_dir/server.sh"
rm -rf "$bin_dir/../../extensions" "$bin_dir/extensions"
ln -sf ~/.vscode/extensions "$bin_dir/extensions"