2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.xinetd;
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "xinetd.conf"
|
|
|
|
''
|
|
|
|
defaults
|
|
|
|
{
|
|
|
|
log_type = SYSLOG daemon info
|
|
|
|
log_on_failure = HOST
|
|
|
|
log_on_success = PID HOST DURATION EXIT
|
|
|
|
${cfg.extraDefaults}
|
|
|
|
}
|
|
|
|
|
|
|
|
${concatMapStrings makeService cfg.services}
|
|
|
|
'';
|
|
|
|
|
|
|
|
makeService = srv:
|
|
|
|
''
|
|
|
|
service ${srv.name}
|
|
|
|
{
|
|
|
|
protocol = ${srv.protocol}
|
|
|
|
${optionalString srv.unlisted "type = UNLISTED"}
|
|
|
|
${optionalString (srv.flags != "") "flags = ${srv.flags}"}
|
|
|
|
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}"}
|
|
|
|
${srv.extraConfig}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.xinetd.enable = mkEnableOption "the xinetd super-server daemon";
|
|
|
|
|
|
|
|
services.xinetd.extraDefaults = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Additional configuration lines added to the default section of xinetd's configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
services.xinetd.services = mkOption {
|
|
|
|
default = [];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
A list of services provided by xinetd.
|
|
|
|
'';
|
|
|
|
|
|
|
|
type = with types; listOf (submodule ({
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "login";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Name of the service.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
protocol = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "tcp";
|
|
|
|
description =
|
2022-08-12 12:06:08 +00:00
|
|
|
lib.mdDoc "Protocol of the service. Usually `tcp` or `udp`.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
|
|
|
example = 123;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Port number of the service.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "nobody";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "User account for the service";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
server = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "/foo/bin/ftpd";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Path of the program that implements the service.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
serverArgs = mkOption {
|
|
|
|
type = types.separatedString " ";
|
|
|
|
default = "";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Command-line arguments for the server program.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
flags = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
description = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
unlisted = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether this server is listed in
|
2022-08-12 12:06:08 +00:00
|
|
|
{file}`/etc/services`. If so, the port
|
2020-04-24 23:36:52 +00:00
|
|
|
number can be omitted.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Extra configuration-lines added to the section of the service.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.xinetd = {
|
|
|
|
description = "xinetd server";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ pkgs.xinetd ];
|
|
|
|
script = "exec xinetd -syslog daemon -dontfork -stayalive -f ${configFile}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|