2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-08-19 21:20:51 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2009-08-19 21:20:51 +01:00
|
|
|
|
2011-09-14 19:20:50 +01:00
|
|
|
let
|
2009-08-21 14:05:45 +01:00
|
|
|
|
|
|
|
cfg = config.services.xinetd;
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-21 14:05:45 +01:00
|
|
|
configFile = pkgs.writeText "xinetd.conf"
|
|
|
|
''
|
|
|
|
defaults
|
|
|
|
{
|
|
|
|
log_type = SYSLOG daemon info
|
|
|
|
log_on_failure = HOST
|
|
|
|
log_on_success = PID HOST DURATION EXIT
|
2012-04-19 09:28:54 +01:00
|
|
|
${cfg.extraDefaults}
|
2009-08-21 14:05:45 +01:00
|
|
|
}
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-21 14:05:45 +01:00
|
|
|
${concatMapStrings makeService cfg.services}
|
|
|
|
'';
|
|
|
|
|
|
|
|
makeService = srv:
|
|
|
|
''
|
|
|
|
service ${srv.name}
|
|
|
|
{
|
|
|
|
protocol = ${srv.protocol}
|
|
|
|
${optionalString srv.unlisted "type = UNLISTED"}
|
2010-08-06 09:49:08 +01:00
|
|
|
${optionalString (srv.flags != "") "flags = ${srv.flags}"}
|
2009-08-21 14:05:45 +01: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}"}
|
2012-04-19 09:28:54 +01:00
|
|
|
${srv.extraConfig}
|
2009-08-21 14:05:45 +01:00
|
|
|
}
|
|
|
|
'';
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-21 14:05:45 +01:00
|
|
|
in
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-21 14:05:45 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-19 21:20:51 +01:00
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-21 14:05:45 +01:00
|
|
|
services.xinetd.enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the xinetd super-server daemon.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2012-04-19 09:28:54 +01:00
|
|
|
services.xinetd.extraDefaults = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.string;
|
|
|
|
description = ''
|
|
|
|
Additional configuration lines added to the default section of xinetd's configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-08-21 14:05:45 +01:00
|
|
|
services.xinetd.services = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
A list of services provided by xinetd.
|
|
|
|
'';
|
|
|
|
|
2016-09-11 10:20:30 +01:00
|
|
|
type = with types; listOf (submodule ({
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
example = "login";
|
|
|
|
description = "Name of the service.";
|
|
|
|
};
|
|
|
|
|
|
|
|
protocol = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "tcp";
|
|
|
|
description =
|
|
|
|
"Protocol of the service. Usually <literal>tcp</literal> or <literal>udp</literal>.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
|
|
|
example = 123;
|
|
|
|
description = "Port number of the service.";
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "nobody";
|
|
|
|
description = "User account for the service";
|
|
|
|
};
|
|
|
|
|
|
|
|
server = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
example = "/foo/bin/ftpd";
|
|
|
|
description = "Path of the program that implements the service.";
|
|
|
|
};
|
|
|
|
|
|
|
|
serverArgs = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "";
|
|
|
|
description = "Command-line arguments for the server program.";
|
|
|
|
};
|
|
|
|
|
|
|
|
flags = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "";
|
|
|
|
description = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2016-10-23 18:33:41 +01:00
|
|
|
type = types.lines;
|
2016-09-11 10:20:30 +01:00
|
|
|
default = "";
|
|
|
|
description = "Extra configuration-lines added to the section of the service.";
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2012-04-19 09:28:54 +01:00
|
|
|
};
|
|
|
|
|
2016-09-11 10:20:30 +01:00
|
|
|
}));
|
2009-08-19 21:20:51 +01:00
|
|
|
|
2009-08-21 14:05:45 +01:00
|
|
|
};
|
2009-08-19 21:20:51 +01:00
|
|
|
|
2009-08-21 14:05:45 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-19 21:20:51 +01:00
|
|
|
|
2009-08-21 14:05:45 +01:00
|
|
|
###### implementation
|
2009-08-19 21:20:51 +01:00
|
|
|
|
2009-08-21 14:05:45 +01:00
|
|
|
config = mkIf cfg.enable {
|
2016-01-06 06:50:18 +00:00
|
|
|
systemd.services.xinetd = {
|
|
|
|
description = "xinetd server";
|
2016-09-10 19:19:24 +01:00
|
|
|
after = [ "network.target" ];
|
2016-01-06 06:50:18 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ pkgs.xinetd ];
|
|
|
|
script = "xinetd -syslog daemon -dontfork -stayalive -f ${configFile}";
|
|
|
|
};
|
2009-08-19 21:20:51 +01:00
|
|
|
};
|
|
|
|
}
|