2009-08-21 15:05:45 +02:00
|
|
|
{ config, pkgs, ... }:
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
with pkgs.lib;
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.xinetd;
|
|
|
|
|
|
|
|
inherit (pkgs) xinetd;
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "xinetd.conf"
|
|
|
|
''
|
|
|
|
defaults
|
|
|
|
{
|
|
|
|
log_type = SYSLOG daemon info
|
|
|
|
log_on_failure = HOST
|
|
|
|
log_on_success = PID HOST DURATION EXIT
|
|
|
|
}
|
|
|
|
|
|
|
|
${concatMapStrings makeService cfg.services}
|
|
|
|
'';
|
|
|
|
|
|
|
|
makeService = srv:
|
|
|
|
''
|
|
|
|
service ${srv.name}
|
|
|
|
{
|
|
|
|
protocol = ${srv.protocol}
|
|
|
|
${optionalString srv.unlisted "type = UNLISTED"}
|
2010-08-06 10:49:08 +02:00
|
|
|
${optionalString (srv.flags != "") "flags = ${srv.flags}"}
|
2009-08-21 15:05:45 +02:00
|
|
|
socket_type = ${if srv.protocol == "udp" then "dgram" else "stream"}
|
|
|
|
${if srv.port != 0 then "port = ${toString srv.port}" else ""}
|
|
|
|
wait = ${if srv.protocol == "udp" then "yes" else "no"}
|
|
|
|
user = ${srv.user}
|
|
|
|
server = ${srv.server}
|
|
|
|
${optionalString (srv.serverArgs != "") "server_args = ${srv.serverArgs}"}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
2009-08-19 22:20:51 +02:00
|
|
|
options = {
|
2009-08-21 15:05:45 +02:00
|
|
|
|
|
|
|
services.xinetd.enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the xinetd super-server daemon.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
services.xinetd.services = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
A list of services provided by xinetd.
|
|
|
|
'';
|
|
|
|
|
|
|
|
type = types.list types.optionSet;
|
|
|
|
|
|
|
|
options = {
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
name = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
example = "login";
|
|
|
|
description = "Name of the service.";
|
2009-08-19 22:20:51 +02:00
|
|
|
};
|
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
protocol = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "tcp";
|
|
|
|
description =
|
|
|
|
"Protocol of the service. Usually <literal>tcp</literal> or <literal>udp</literal>.";
|
|
|
|
};
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
|
|
|
example = 123;
|
|
|
|
description = "Port number of the service.";
|
|
|
|
};
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
user = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "nobody";
|
|
|
|
description = "User account for the service";
|
|
|
|
};
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
server = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
example = "/foo/bin/ftpd";
|
|
|
|
description = "Path of the program that implements the service.";
|
|
|
|
};
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
serverArgs = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "";
|
|
|
|
description = "Command-line arguments for the server program.";
|
|
|
|
};
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2010-08-06 10:49:08 +02:00
|
|
|
flags = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "";
|
|
|
|
description = "";
|
|
|
|
};
|
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
unlisted = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether this server is listed in
|
|
|
|
<filename>/etc/services</filename>. If so, the port
|
|
|
|
number can be omitted.
|
|
|
|
'';
|
|
|
|
};
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
};
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
};
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
};
|
|
|
|
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
###### implementation
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2009-08-21 15:05:45 +02:00
|
|
|
config = mkIf cfg.enable {
|
2009-08-19 22:20:51 +02:00
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.xinetd =
|
2009-10-12 19:27:57 +02:00
|
|
|
{ description = "xinetd server";
|
2009-08-21 15:05:45 +02:00
|
|
|
|
2009-11-06 23:19:17 +01:00
|
|
|
startOn = "started network-interfaces";
|
|
|
|
stopOn = "stopping network-interfaces";
|
2009-08-21 15:05:45 +02:00
|
|
|
|
|
|
|
exec = "${xinetd}/sbin/xinetd -syslog daemon -dontfork -stayalive -f ${configFile}";
|
|
|
|
};
|
|
|
|
|
2009-08-19 22:20:51 +02:00
|
|
|
};
|
2009-08-21 15:05:45 +02:00
|
|
|
|
2009-08-19 22:20:51 +02:00
|
|
|
}
|