Skip to content

Commit 8540bfa

Browse files
committedNov 10, 2017
fetchgitPrivate: put our custom ssh on PATH
Currently we wrap ssh so it can find the config file passed in by <ssh-config-file>. If one however uses ProxyCommand ssh, then ssh that is on PATH is taken (which is also unavailable when using nix-shell --pure), which is the plain ${openssh}/bin/ssh. This commit makes sure our wrapped ssh is available on PATH. (cherry picked from commit f8eed5f)
1 parent 78eed74 commit 8540bfa

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed
 
+20-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
{ fetchgit, writeScript, openssh, stdenv }: args: derivation ((fetchgit args).drvAttrs // {
1+
{ fetchgit, runCommand, makeWrapper, openssh, stdenv }: args: derivation ((fetchgit args).drvAttrs // {
22
SSH_AUTH_SOCK = if (builtins.tryEval <ssh-auth-sock>).success
33
then builtins.toString <ssh-auth-sock>
44
else null;
5-
GIT_SSH = writeScript "fetchgit-ssh" ''
6-
#! ${stdenv.shell}
7-
exec -a ssh ${openssh}/bin/ssh -F ${let
8-
sshConfigFile = if (builtins.tryEval <ssh-config-file>).success
9-
then <ssh-config-file>
10-
else builtins.trace ''
11-
Please set your nix-path such that ssh-config-file points to a file that will allow ssh to access private repositories. The builder will not be able to see any running ssh agent sessions unless ssh-auth-sock is also set in the nix-path.
125

13-
Note that the config file and any keys it points to must be readable by the build user, which depending on your nix configuration means making it readable by the build-users-group, the user of the running nix-daemon, or the user calling the nix command which started the build. Similarly, if using an ssh agent ssh-auth-sock must point to a socket the build user can access.
6+
GIT_SSH = let
7+
config = ''${let
8+
sshConfigFile = if (builtins.tryEval <ssh-config-file>).success
9+
then <ssh-config-file>
10+
else builtins.trace ''
11+
Please set your nix-path such that ssh-config-file points to a file that will allow ssh to access private repositories. The builder will not be able to see any running ssh agent sessions unless ssh-auth-sock is also set in the nix-path.
1412
15-
You may need StrictHostKeyChecking=no in the config file. Since ssh will refuse to use a group-readable private key, if using build-users you will likely want to use something like IdentityFile /some/directory/%u/key and have a directory for each build user accessible to that user.
16-
'' "/var/lib/empty/config";
17-
in builtins.toString sshConfigFile} "$@"
18-
'';
13+
Note that the config file and any keys it points to must be readable by the build user, which depending on your nix configuration means making it readable by the build-users-group, the user of the running nix-daemon, or the user calling the nix command which started the build. Similarly, if using an ssh agent ssh-auth-sock must point to a socket the build user can access.
14+
15+
You may need StrictHostKeyChecking=no in the config file. Since ssh will refuse to use a group-readable private key, if using build-users you will likely want to use something like IdentityFile /some/directory/%u/key and have a directory for each build user accessible to that user.
16+
'' "/var/lib/empty/config";
17+
in builtins.toString sshConfigFile}'';
18+
19+
ssh-wrapped = runCommand "fetchgit-ssh" {
20+
buildInputs = [ makeWrapper ];
21+
} ''
22+
mkdir -p $out/bin
23+
makeWrapper ${openssh}/bin/ssh $out/bin/ssh --prefix PATH : "$out/bin" --add-flags "-F ${config}" "$@"
24+
'';
25+
in "${ssh-wrapped}/bin/ssh";
1926
})

0 commit comments

Comments
 (0)
Please sign in to comment.