2009-03-06 13:26:08 +01:00
|
|
|
{pkgs, config, ...}:
|
|
|
|
|
2007-01-07 11:19:16 +01:00
|
|
|
let
|
2009-03-06 13:26:08 +01:00
|
|
|
|
2009-07-15 17:53:39 +02:00
|
|
|
inherit (pkgs.lib) mkOption mkIf;
|
|
|
|
inherit (pkgs) openssh;
|
2009-03-06 13:26:08 +01:00
|
|
|
|
|
|
|
cfg = (config.services.sshd);
|
|
|
|
|
|
|
|
nssModules = config.system.nssModules.list;
|
|
|
|
|
|
|
|
nssModulesPath = config.system.nssModules.path;
|
2007-01-07 11:19:16 +01:00
|
|
|
|
2009-07-15 17:53:39 +02:00
|
|
|
sshdConfig = pkgs.writeText "sshd_config"
|
|
|
|
''
|
|
|
|
Protocol 2
|
|
|
|
|
|
|
|
UsePAM yes
|
|
|
|
|
|
|
|
${if cfg.forwardX11 then "
|
|
|
|
X11Forwarding yes
|
|
|
|
XAuthLocation ${pkgs.xlibs.xauth}/bin/xauth
|
|
|
|
" else "
|
|
|
|
X11Forwarding no
|
|
|
|
"}
|
|
|
|
|
|
|
|
${if cfg.allowSFTP then "
|
|
|
|
Subsystem sftp ${openssh}/libexec/sftp-server
|
|
|
|
" else "
|
|
|
|
"}
|
|
|
|
|
|
|
|
PermitRootLogin ${cfg.permitRootLogin}
|
|
|
|
GatewayPorts ${cfg.gatewayPorts}
|
|
|
|
'';
|
2007-01-07 11:19:16 +01:00
|
|
|
|
2009-05-20 12:18:54 +02:00
|
|
|
# !!! is this assertion evaluated anywhere???
|
2009-03-06 13:26:08 +01:00
|
|
|
assertion = cfg.permitRootLogin == "yes" ||
|
|
|
|
cfg.permitRootLogin == "without-password" ||
|
|
|
|
cfg.permitRootLogin == "forced-commands-only" ||
|
|
|
|
cfg.permitRootLogin == "no";
|
|
|
|
|
2007-01-07 11:19:16 +01:00
|
|
|
in
|
2006-11-23 18:43:28 +01:00
|
|
|
|
2009-07-15 17:53:39 +02:00
|
|
|
{
|
2007-06-08 17:41:12 +02:00
|
|
|
|
2009-07-15 17:53:39 +02:00
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.sshd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the Secure Shell daemon, which allows secure
|
|
|
|
remote logins.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
forwardX11 = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to allow X11 connections to be forwarded.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
allowSFTP = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the SFTP subsystem in the SSH daemon. This
|
|
|
|
enables the use of commands such as <command>sftp</command> and
|
|
|
|
<command>sshfs</command>.
|
|
|
|
'';
|
|
|
|
};
|
2006-11-23 18:43:28 +01:00
|
|
|
|
2009-07-15 17:53:39 +02:00
|
|
|
permitRootLogin = mkOption {
|
|
|
|
default = "yes";
|
|
|
|
description = ''
|
|
|
|
Whether the root user can login using ssh. Valid values are
|
|
|
|
<literal>yes</literal>, <literal>without-password</literal>,
|
|
|
|
<literal>forced-commands-only</literal> or
|
|
|
|
<literal>no</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
gatewayPorts = mkOption {
|
|
|
|
default = "no";
|
|
|
|
description = ''
|
|
|
|
Specifies whether remote hosts are allowed to connect to
|
|
|
|
ports forwarded for the client. See
|
|
|
|
<citerefentry><refentrytitle>sshd_config</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum></citerefentry>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.sshd.enable {
|
|
|
|
|
|
|
|
users.extraUsers = pkgs.lib.singleton
|
2009-03-06 13:26:13 +01:00
|
|
|
{ name = "sshd";
|
2009-05-29 16:25:56 +02:00
|
|
|
uid = config.ids.uids.sshd;
|
2009-03-06 13:26:13 +01:00
|
|
|
description = "SSH privilege separation user";
|
|
|
|
home = "/var/empty";
|
2009-07-15 17:53:39 +02:00
|
|
|
};
|
2009-03-06 13:26:13 +01:00
|
|
|
|
2009-07-15 17:53:39 +02:00
|
|
|
jobs = pkgs.lib.singleton
|
|
|
|
{ name = "sshd";
|
2006-11-23 18:43:28 +01:00
|
|
|
|
2009-07-15 17:53:39 +02:00
|
|
|
description = "OpenSSH server";
|
2007-01-15 18:19:41 +01:00
|
|
|
|
2009-07-15 17:53:39 +02:00
|
|
|
startOn = "network-interfaces/started";
|
|
|
|
stopOn = "network-interfaces/stop";
|
2006-11-23 18:43:28 +01:00
|
|
|
|
2009-07-15 17:53:39 +02:00
|
|
|
environment = { LD_LIBRARY_PATH = nssModulesPath; };
|
2006-11-23 18:43:28 +01:00
|
|
|
|
2009-07-15 17:53:39 +02:00
|
|
|
preStart =
|
|
|
|
''
|
2009-03-06 13:26:08 +01:00
|
|
|
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
|
2009-07-15 17:53:39 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
exec = "${openssh}/sbin/sshd -D -h /etc/ssh/ssh_host_dsa_key -f ${sshdConfig}";
|
|
|
|
};
|
2009-03-06 13:26:08 +01:00
|
|
|
|
2009-07-26 23:27:35 +02:00
|
|
|
networking.firewall.allowedTCPPorts = [22];
|
2009-07-25 01:12:52 +02:00
|
|
|
|
2009-03-06 13:26:08 +01:00
|
|
|
};
|
2009-07-15 17:53:39 +02:00
|
|
|
|
2006-11-23 18:43:28 +01:00
|
|
|
}
|