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