2010-02-01 17:05:02 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2009-03-06 12:26:08 +00:00
|
|
|
|
2007-01-07 10:19:16 +00:00
|
|
|
let
|
2009-03-06 12:26:08 +00:00
|
|
|
|
2009-07-15 15:53:39 +00:00
|
|
|
inherit (pkgs) openssh;
|
2009-03-06 12:26:08 +00:00
|
|
|
|
2009-08-11 01:35:56 +00:00
|
|
|
cfg = config.services.sshd;
|
2009-03-06 12:26:08 +00:00
|
|
|
|
|
|
|
nssModulesPath = config.system.nssModules.path;
|
2007-01-07 10:19:16 +00:00
|
|
|
|
2009-07-15 15:53:39 +00:00
|
|
|
sshdConfig = pkgs.writeText "sshd_config"
|
|
|
|
''
|
|
|
|
Protocol 2
|
|
|
|
|
|
|
|
UsePAM yes
|
|
|
|
|
2010-02-01 17:05:02 +00:00
|
|
|
${ concatMapStrings (port : ''Port ${toString port}
|
2009-12-10 14:45:41 +00:00
|
|
|
'') cfg.ports}
|
|
|
|
|
2009-07-15 15:53:39 +00:00
|
|
|
${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 10:19:16 +00:00
|
|
|
|
2009-08-19 15:04:05 +00:00
|
|
|
permitRootLoginCheck = v:
|
|
|
|
v == "yes" ||
|
|
|
|
v == "without-password" ||
|
|
|
|
v == "forced-commands-only" ||
|
|
|
|
v == "no";
|
2009-03-06 12:26:08 +00:00
|
|
|
|
2007-01-07 10:19:16 +00:00
|
|
|
in
|
2006-11-23 17:43:28 +00:00
|
|
|
|
2009-07-15 15:53:39 +00:00
|
|
|
{
|
2007-06-08 15:41:12 +00:00
|
|
|
|
2009-07-15 15:53:39 +00: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 17:43:28 +00:00
|
|
|
|
2009-07-15 15:53:39 +00:00
|
|
|
permitRootLogin = mkOption {
|
|
|
|
default = "yes";
|
2009-08-19 15:04:05 +00:00
|
|
|
check = permitRootLoginCheck;
|
2009-07-15 15:53:39 +00:00
|
|
|
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>.
|
2009-12-11 00:51:13 +00:00
|
|
|
If without-password doesn't work try <literal>yes</literal>.
|
2009-07-15 15:53:39 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
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>.
|
|
|
|
'';
|
|
|
|
};
|
2009-12-10 14:45:41 +00:00
|
|
|
|
|
|
|
ports = mkOption {
|
|
|
|
default = [22];
|
|
|
|
description = ''
|
|
|
|
Specifies on which ports the SSH daemon listens.
|
|
|
|
'';
|
|
|
|
};
|
2009-07-15 15:53:39 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.sshd.enable {
|
|
|
|
|
2010-02-01 17:05:02 +00:00
|
|
|
users.extraUsers = singleton
|
2009-03-06 12:26:13 +00:00
|
|
|
{ name = "sshd";
|
2009-05-29 14:25:56 +00:00
|
|
|
uid = config.ids.uids.sshd;
|
2009-03-06 12:26:13 +00:00
|
|
|
description = "SSH privilege separation user";
|
|
|
|
home = "/var/empty";
|
2009-07-15 15:53:39 +00:00
|
|
|
};
|
2009-03-06 12:26:13 +00:00
|
|
|
|
2010-02-01 17:05:02 +00:00
|
|
|
environment.etc = singleton
|
|
|
|
{ source = "${openssh}/etc/ssh/moduli";
|
|
|
|
target = "ssh/moduli";
|
|
|
|
};
|
|
|
|
|
2009-10-12 18:09:34 +00:00
|
|
|
jobs.sshd = {
|
2006-11-23 17:43:28 +00:00
|
|
|
|
2009-07-15 15:53:39 +00:00
|
|
|
description = "OpenSSH server";
|
2007-01-15 17:19:41 +00:00
|
|
|
|
2009-11-06 15:46:56 +00:00
|
|
|
startOn = "started network-interfaces";
|
2006-11-23 17:43:28 +00:00
|
|
|
|
2009-07-15 15:53:39 +00:00
|
|
|
environment = { LD_LIBRARY_PATH = nssModulesPath; };
|
2006-11-23 17:43:28 +00:00
|
|
|
|
2009-07-15 15:53:39 +00:00
|
|
|
preStart =
|
|
|
|
''
|
2009-03-06 12:26:08 +00: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 15:53:39 +00:00
|
|
|
'';
|
|
|
|
|
2009-11-06 15:46:56 +00:00
|
|
|
daemonType = "fork";
|
|
|
|
|
|
|
|
exec = "${openssh}/sbin/sshd -h /etc/ssh/ssh_host_dsa_key -f ${sshdConfig}";
|
2009-07-15 15:53:39 +00:00
|
|
|
};
|
2009-03-06 12:26:08 +00:00
|
|
|
|
2010-02-01 17:05:02 +00:00
|
|
|
networking.firewall.allowedTCPPorts = cfg.ports;
|
2009-07-24 23:12:52 +00:00
|
|
|
|
2009-03-06 12:26:08 +00:00
|
|
|
};
|
2009-07-15 15:53:39 +00:00
|
|
|
|
2006-11-23 17:43:28 +00:00
|
|
|
}
|