2007-06-10 20:13:12 +00:00
|
|
|
{ writeText, openssh, glibc, xauth
|
2007-01-15 17:19:41 +00:00
|
|
|
, nssModulesPath
|
2008-03-14 12:53:14 +00:00
|
|
|
, forwardX11, allowSFTP, permitRootLogin
|
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" ''
|
|
|
|
|
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-01-16 13:59:03 +00:00
|
|
|
'';
|
2007-01-07 10:19:16 +00:00
|
|
|
|
2007-06-08 15:41:12 +00: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 15:41:12 +00: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
|
|
|
|
|
|
|
job = "
|
|
|
|
description \"SSH server\"
|
|
|
|
|
|
|
|
start on network-interfaces/started
|
|
|
|
stop on network-interfaces/stop
|
|
|
|
|
2007-01-15 17:19:41 +00:00
|
|
|
env LD_LIBRARY_PATH=${nssModulesPath}
|
|
|
|
|
2006-11-23 17:43:28 +00:00
|
|
|
start script
|
|
|
|
mkdir -m 0755 -p /etc/ssh
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2007-01-07 10:19:16 +00:00
|
|
|
respawn ${openssh}/sbin/sshd -D -h /etc/ssh/ssh_host_dsa_key -f ${sshdConfig}
|
2006-11-23 17:43:28 +00:00
|
|
|
";
|
|
|
|
|
|
|
|
}
|