2009-10-12 18:36:19 +02:00
|
|
|
{ config, pkgs, ... }:
|
2008-03-05 17:03:09 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
inherit (pkgs) lsh;
|
|
|
|
|
|
|
|
cfg = config.services.lshd;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2008-03-05 17:03:09 +01:00
|
|
|
|
2009-03-06 13:26:10 +01:00
|
|
|
options = {
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
services.lshd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the GNU lshd SSH2 daemon, which allows
|
|
|
|
secure remote login.
|
|
|
|
'';
|
|
|
|
};
|
2009-03-06 13:26:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
portNumber = mkOption {
|
|
|
|
default = 22;
|
|
|
|
description = ''
|
|
|
|
The port on which to listen for connections.
|
|
|
|
'';
|
|
|
|
};
|
2009-03-06 13:26:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
interfaces = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
List of network interfaces where listening for connections.
|
|
|
|
When providing the empty list, `[]', lshd listens on all
|
|
|
|
network interfaces.
|
|
|
|
'';
|
|
|
|
example = [ "localhost" "1.2.3.4:443" ];
|
2009-03-06 13:26:10 +01:00
|
|
|
};
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
hostKey = mkOption {
|
|
|
|
default = "/etc/lsh/host-key";
|
|
|
|
description = ''
|
|
|
|
Path to the server's private key. Note that this key must
|
|
|
|
have been created, e.g., using "lsh-keygen --server |
|
|
|
|
lsh-writekey --server", so that you can run lshd.
|
|
|
|
'';
|
|
|
|
};
|
2009-03-06 13:26:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
syslog = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to enable syslog output.'';
|
|
|
|
};
|
2009-03-06 13:26:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
passwordAuthentication = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to enable password authentication.'';
|
|
|
|
};
|
2009-03-06 13:26:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
publicKeyAuthentication = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to enable public key authentication.'';
|
|
|
|
};
|
2009-03-06 13:26:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
rootLogin = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''Whether to enable remote root login.'';
|
|
|
|
};
|
2009-03-06 13:26:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
loginShell = mkOption {
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
If non-null, override the default login shell with the
|
|
|
|
specified value.
|
|
|
|
'';
|
|
|
|
example = "/nix/store/xyz-bash-10.0/bin/bash10";
|
|
|
|
};
|
2009-03-06 13:26:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
srpKeyExchange = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable SRP key exchange and user authentication.
|
|
|
|
'';
|
|
|
|
};
|
2009-03-06 13:26:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
tcpForwarding = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to enable TCP/IP forwarding.'';
|
|
|
|
};
|
|
|
|
|
|
|
|
x11Forwarding = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to enable X11 forwarding.'';
|
|
|
|
};
|
|
|
|
|
|
|
|
subsystems = mkOption {
|
|
|
|
default = [ ["sftp" "${pkgs.lsh}/sbin/sftp-server"] ];
|
|
|
|
description = ''
|
|
|
|
List of subsystem-path pairs, where the head of the pair
|
|
|
|
denotes the subsystem name, and the tail denotes the path to
|
|
|
|
an executable implementing it.
|
|
|
|
'';
|
|
|
|
};
|
2009-03-06 13:26:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-03-06 13:26:10 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-03-06 13:26:10 +01:00
|
|
|
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.lshd =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ description = "GNU lshd SSH2 daemon";
|
|
|
|
|
2009-11-06 23:19:17 +01:00
|
|
|
startOn = "started network-interfaces";
|
|
|
|
stopOn = "stopping network-interfaces";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
environment =
|
|
|
|
{ LD_LIBRARY_PATH = config.system.nssModules.path; };
|
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
2009-03-06 13:26:10 +01:00
|
|
|
test -d /etc/lsh || mkdir -m 0755 -p /etc/lsh
|
|
|
|
test -d /var/spool/lsh || mkdir -m 0755 -p /var/spool/lsh
|
|
|
|
|
|
|
|
if ! test -f /var/spool/lsh/yarrow-seed-file
|
2009-07-02 16:05:01 +02:00
|
|
|
then
|
|
|
|
# XXX: It would be nice to provide feedback to the
|
|
|
|
# user when this fails, so that they can retry it
|
|
|
|
# manually.
|
2009-03-06 13:26:10 +01:00
|
|
|
${lsh}/bin/lsh-make-seed -o /var/spool/lsh/yarrow-seed-file
|
|
|
|
fi
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
if ! test -f "${cfg.hostKey}"
|
2009-03-06 13:26:10 +01:00
|
|
|
then
|
|
|
|
${lsh}/bin/lsh-keygen --server | \
|
2009-10-12 18:36:19 +02:00
|
|
|
${lsh}/bin/lsh-writekey --server -o "${cfg.hostKey}"
|
2009-03-06 13:26:10 +01:00
|
|
|
fi
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
exec = with cfg;
|
|
|
|
''
|
|
|
|
${lsh}/sbin/lshd --daemonic \
|
|
|
|
--password-helper="${lsh}/sbin/lsh-pam-checkpw" \
|
|
|
|
-p ${toString portNumber} \
|
|
|
|
${if interfaces == [] then ""
|
|
|
|
else (concatStrings (map (i: "--interface=\"${i}\"")
|
|
|
|
interfaces))} \
|
|
|
|
-h "${hostKey}" \
|
|
|
|
${if !syslog then "--no-syslog" else ""} \
|
|
|
|
${if passwordAuthentication then "--password" else "--no-password" } \
|
|
|
|
${if publicKeyAuthentication then "--publickey" else "--no-publickey" } \
|
|
|
|
${if rootLogin then "--root-login" else "--no-root-login" } \
|
|
|
|
${if loginShell != null then "--login-shell=\"${loginShell}\"" else "" } \
|
|
|
|
${if srpKeyExchange then "--srp-keyexchange" else "--no-srp-keyexchange" } \
|
|
|
|
${if !tcpForwarding then "--no-tcpip-forward" else "--tcpip-forward"} \
|
|
|
|
${if x11Forwarding then "--x11-forward" else "--no-x11-forward" } \
|
|
|
|
--subsystems=${concatStringsSep ","
|
|
|
|
(map (pair: (head pair) + "=" +
|
|
|
|
(head (tail pair)))
|
|
|
|
subsystems)}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-03-06 13:26:10 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-03-05 17:03:09 +01:00
|
|
|
}
|