1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8with lib;
9
10let
11
12 cfg = config.services.xinetd;
13
14 configFile = pkgs.writeText "xinetd.conf" ''
15 defaults
16 {
17 log_type = SYSLOG daemon info
18 log_on_failure = HOST
19 log_on_success = PID HOST DURATION EXIT
20 ${cfg.extraDefaults}
21 }
22
23 ${concatMapStrings makeService cfg.services}
24 '';
25
26 makeService = srv: ''
27 service ${srv.name}
28 {
29 protocol = ${srv.protocol}
30 ${optionalString srv.unlisted "type = UNLISTED"}
31 ${optionalString (srv.flags != "") "flags = ${srv.flags}"}
32 socket_type = ${if srv.protocol == "udp" then "dgram" else "stream"}
33 ${optionalString (srv.port != 0) "port = ${toString srv.port}"}
34 wait = ${if srv.protocol == "udp" then "yes" else "no"}
35 user = ${srv.user}
36 server = ${srv.server}
37 ${optionalString (srv.serverArgs != "") "server_args = ${srv.serverArgs}"}
38 ${srv.extraConfig}
39 }
40 '';
41
42in
43
44{
45
46 ###### interface
47
48 options = {
49
50 services.xinetd.enable = mkEnableOption "the xinetd super-server daemon";
51
52 services.xinetd.extraDefaults = mkOption {
53 default = "";
54 type = types.lines;
55 description = ''
56 Additional configuration lines added to the default section of xinetd's configuration.
57 '';
58 };
59
60 services.xinetd.services = mkOption {
61 default = [ ];
62 description = ''
63 A list of services provided by xinetd.
64 '';
65
66 type =
67 with types;
68 listOf (submodule ({
69
70 options = {
71
72 name = mkOption {
73 type = types.str;
74 example = "login";
75 description = "Name of the service.";
76 };
77
78 protocol = mkOption {
79 type = types.str;
80 default = "tcp";
81 description = "Protocol of the service. Usually `tcp` or `udp`.";
82 };
83
84 port = mkOption {
85 type = types.port;
86 default = 0;
87 example = 123;
88 description = "Port number of the service.";
89 };
90
91 user = mkOption {
92 type = types.str;
93 default = "nobody";
94 description = "User account for the service";
95 };
96
97 server = mkOption {
98 type = types.str;
99 example = "/foo/bin/ftpd";
100 description = "Path of the program that implements the service.";
101 };
102
103 serverArgs = mkOption {
104 type = types.separatedString " ";
105 default = "";
106 description = "Command-line arguments for the server program.";
107 };
108
109 flags = mkOption {
110 type = types.str;
111 default = "";
112 description = "";
113 };
114
115 unlisted = mkOption {
116 type = types.bool;
117 default = false;
118 description = ''
119 Whether this server is listed in
120 {file}`/etc/services`. If so, the port
121 number can be omitted.
122 '';
123 };
124
125 extraConfig = mkOption {
126 type = types.lines;
127 default = "";
128 description = "Extra configuration-lines added to the section of the service.";
129 };
130
131 };
132
133 }));
134
135 };
136
137 };
138
139 ###### implementation
140
141 config = mkIf cfg.enable {
142 systemd.services.xinetd = {
143 description = "xinetd server";
144 after = [ "network.target" ];
145 wantedBy = [ "multi-user.target" ];
146 path = [ pkgs.xinetd ];
147 script = "exec xinetd -syslog daemon -dontfork -stayalive -f ${configFile}";
148 };
149 };
150}