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