2007-06-11 00:13:12 +04:00
|
|
|
{ writeText, openssh, glibc, xauth
|
2007-01-15 20:19:41 +03:00
|
|
|
, nssModulesPath
|
2008-11-21 02:47:05 +03:00
|
|
|
, forwardX11, allowSFTP, permitRootLogin, gatewayPorts
|
2007-01-10 20:19:17 +03:00
|
|
|
}:
|
2007-01-07 13:19:16 +03:00
|
|
|
|
2008-03-14 15:53:14 +03:00
|
|
|
assert permitRootLogin == "yes" ||
|
|
|
|
permitRootLogin == "without-password" ||
|
|
|
|
permitRootLogin == "forced-commands-only" ||
|
|
|
|
permitRootLogin == "no";
|
|
|
|
|
2007-01-07 13:19:16 +03:00
|
|
|
let
|
|
|
|
|
2008-01-16 16:59:03 +03:00
|
|
|
sshdConfig = writeText "sshd_config" ''
|
2008-05-08 18:29:00 +04:00
|
|
|
|
|
|
|
Protocol 2
|
|
|
|
|
2007-01-07 13:19:16 +03:00
|
|
|
UsePAM yes
|
2007-01-10 20:19:17 +03:00
|
|
|
|
2007-01-07 13:19:16 +03:00
|
|
|
${if forwardX11 then "
|
|
|
|
X11Forwarding yes
|
|
|
|
XAuthLocation ${xauth}/bin/xauth
|
|
|
|
" else "
|
|
|
|
X11Forwarding no
|
|
|
|
"}
|
2007-01-10 20:19:17 +03:00
|
|
|
|
|
|
|
${if allowSFTP then "
|
|
|
|
Subsystem sftp ${openssh}/libexec/sftp-server
|
|
|
|
" else "
|
|
|
|
"}
|
|
|
|
|
2008-03-14 15:53:14 +03:00
|
|
|
PermitRootLogin ${permitRootLogin}
|
2008-11-21 02:47:05 +03:00
|
|
|
GatewayPorts ${gatewayPorts}
|
2008-03-14 15:53:14 +03:00
|
|
|
|
2008-01-16 16:59:03 +03:00
|
|
|
'';
|
2007-01-07 13:19:16 +03:00
|
|
|
|
2007-06-08 19:41:12 +04:00
|
|
|
sshdUid = (import ../system/ids.nix).uids.sshd;
|
|
|
|
|
2007-01-07 13:19:16 +03:00
|
|
|
in
|
2006-11-23 20:43:28 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
name = "sshd";
|
2007-06-08 19:41:12 +04:00
|
|
|
|
|
|
|
users = [
|
|
|
|
{ name = "sshd";
|
|
|
|
uid = (import ../system/ids.nix).uids.sshd;
|
|
|
|
description = "SSH privilege separation user";
|
|
|
|
home = "/var/empty";
|
|
|
|
}
|
|
|
|
];
|
2006-11-23 20:43:28 +03:00
|
|
|
|
2008-05-08 18:29:00 +04:00
|
|
|
job = ''
|
|
|
|
description "SSH server"
|
2006-11-23 20:43:28 +03:00
|
|
|
|
2008-05-08 18:29:00 +04:00
|
|
|
start on network-interfaces/started
|
|
|
|
stop on network-interfaces/stop
|
2006-11-23 20:43:28 +03:00
|
|
|
|
2008-05-08 18:29:00 +04:00
|
|
|
env LD_LIBRARY_PATH=${nssModulesPath}
|
2007-01-15 20:19:41 +03:00
|
|
|
|
2008-05-08 18:29:00 +04:00
|
|
|
start script
|
|
|
|
mkdir -m 0755 -p /etc/ssh
|
2006-11-23 20:43:28 +03:00
|
|
|
|
2008-05-08 18:29:00 +04:00
|
|
|
if ! test -f /etc/ssh/ssh_host_dsa_key; then
|
|
|
|
${openssh}/bin/ssh-keygen -t dsa -b 1024 -f /etc/ssh/ssh_host_dsa_key -N ""
|
|
|
|
fi
|
|
|
|
end script
|
2006-11-23 20:43:28 +03:00
|
|
|
|
2008-05-08 18:29:00 +04:00
|
|
|
respawn ${openssh}/sbin/sshd -D -h /etc/ssh/ssh_host_dsa_key -f ${sshdConfig}
|
|
|
|
'';
|
2006-11-23 20:43:28 +03:00
|
|
|
|
|
|
|
}
|