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