11 cfg = config.services.trafficserver;
12 user = config.users.users.trafficserver.name;
13 group = config.users.groups.trafficserver.name;
16 name: "https://docs.trafficserver.apache.org/en/latest/admin-guide/files/${name}.en.html";
18 yaml = pkgs.formats.yaml { };
24 "trafficserver/${name}.yaml".source = yaml.generate "${name}.yaml" cfg;
28 "trafficserver/${name}.yaml".text = "";
34 lib.mapAttrsToList (n: v: mkRecordLines (path ++ [ n ]) v) value
35 else if isInt value then
36 "CONFIG ${concatStringsSep "." path} INT ${toString value}"
37 else if isFloat value then
38 "CONFIG ${concatStringsSep "." path} FLOAT ${toString value}"
40 "CONFIG ${concatStringsSep "." path} STRING ${toString value}";
42 mkRecordsConfig = cfg: concatStringsSep "\n" (flatten (mkRecordLines [ ] cfg));
43 mkPluginConfig = cfg: concatStringsSep "\n" (map (p: "${p.path} ${p.arg}") cfg);
46 options.services.trafficserver = {
47 enable = mkEnableOption "Apache Traffic Server";
52 example = "dest_domain=example.com suffix=js action=never-cache";
54 Caching rules that overrule the origin's caching policy.
57 documentation](${getManualUrl "cache.config"}) for more details.
64 example = "domain=example.com volume=1";
66 Partition the cache according to origin server or domain
69 upstream documentation](${getManualUrl "hosting.config"}) for more details.
74 type = types.nullOr yaml.type;
75 default = lib.importJSON ./ip_allow.json;
76 defaultText = literalMD "upstream defaults";
77 example = literalExpression ''
81 ip_addrs = "127.0.0.1";
88 Control client access to Traffic Server and Traffic Server connections
92 documentation](${getManualUrl "ip_allow.yaml"}) for more details.
97 type = types.nullOr yaml.type;
98 default = lib.importJSON ./logging.json;
99 defaultText = literalMD "upstream defaults";
104 Consult the [upstream
105 documentation](${getManualUrl "logging.yaml"}) for more details.
113 dest_domain=. method=get parent="p1.example:8080; p2.example:8080" round_robin=true
116 Identify the parent proxies used in an cache hierarchy.
118 Consult the [upstream
119 documentation](${getManualUrl "parent.config"}) for more details.
127 Controls run-time loadable plugins available to Traffic Server, as
128 well as their configuration.
130 Consult the [upstream
131 documentation](${getManualUrl "plugin.config"}) for more details.
137 options.path = mkOption {
139 example = "xdebug.so";
141 Path to plugin. The path can either be absolute, or relative to
142 the plugin directory.
145 options.arg = mkOption {
148 example = "--header=ATS-My-Debug";
149 description = "arguments to pass to the plugin";
166 description = "Traffic Server records value";
172 proxy.config.proxy_name = "my_server";
175 List of configurable variables used by Traffic Server.
178 upstream documentation](${getManualUrl "records.config"}) for more details.
185 example = "map http://from.example http://origin.example";
187 URL remapping rules used by Traffic Server.
190 upstream documentation](${getManualUrl "remap.config"}) for more details.
194 splitDns = mkOption {
198 dest_domain=internal.corp.example named="255.255.255.255:212 255.255.255.254" def_domain=corp.example search_list="corp.example corp1.example"
199 dest_domain=!internal.corp.example named=255.255.255.253
202 Specify the DNS server that Traffic Server should use under specific
206 upstream documentation](${getManualUrl "splitdns.config"}) for more details.
210 sslMulticert = mkOption {
213 example = "dest_ip=* ssl_cert_name=default.pem";
215 Configure SSL server certificates to terminate the SSL sessions.
218 upstream documentation](${getManualUrl "ssl_multicert.config"}) for more details.
223 type = types.nullOr yaml.type;
225 example = literalExpression ''
228 fqdn = "no-http2.example.com";
234 Configure aspects of TLS connection handling for both inbound and
235 outbound connections.
237 Consult the [upstream
238 documentation](${getManualUrl "sni.yaml"}) for more details.
244 default = "/var/cache/trafficserver 256M";
245 example = "/dev/disk/by-id/XXXXX volume=1";
247 List all the storage that make up the Traffic Server cache.
250 upstream documentation](${getManualUrl "storage.config"}) for more details.
254 strategies = mkOption {
255 type = types.nullOr yaml.type;
258 Specify the next hop proxies used in an cache hierarchy and the
259 algorithms used to select the next proxy.
262 upstream documentation](${getManualUrl "strategies.yaml"}) for more details.
267 type = types.nullOr yaml.type;
269 example = "volume=1 scheme=http size=20%";
271 Manage cache space more efficiently and restrict disk usage by
272 creating cache volumes of different sizes.
275 upstream documentation](${getManualUrl "volume.config"}) for more details.
280 config = mkIf cfg.enable {
283 "trafficserver/cache.config".text = cfg.cache;
284 "trafficserver/hosting.config".text = cfg.hosting;
285 "trafficserver/parent.config".text = cfg.parent;
286 "trafficserver/plugin.config".text = mkPluginConfig cfg.plugins;
287 "trafficserver/records.config".text = mkRecordsConfig cfg.records;
288 "trafficserver/remap.config".text = cfg.remap;
289 "trafficserver/splitdns.config".text = cfg.splitDns;
290 "trafficserver/ssl_multicert.config".text = cfg.sslMulticert;
291 "trafficserver/storage.config".text = cfg.storage;
292 "trafficserver/volume.config".text = cfg.volume;
294 // (mkYamlConf "ip_allow" cfg.ipAllow)
295 // (mkYamlConf "logging" cfg.logging)
296 // (mkYamlConf "sni" cfg.sni)
297 // (mkYamlConf "strategies" cfg.strategies);
299 environment.systemPackages = [ pkgs.trafficserver ];
300 systemd.packages = [ pkgs.trafficserver ];
302 # Traffic Server does privilege handling independently of systemd, and
303 # therefore should be started as root
304 systemd.services.trafficserver = {
306 wantedBy = [ "multi-user.target" ];
309 # These directories can't be created by systemd because:
311 # 1. Traffic Servers starts as root and switches to an unprivileged user
312 # afterwards. The runtime directories defined below are assumed to be
313 # owned by that user.
314 # 2. The bin/trafficserver script assumes these directories exist.
315 systemd.tmpfiles.rules = [
316 "d '/run/trafficserver' - ${user} ${group} - -"
317 "d '/var/cache/trafficserver' - ${user} ${group} - -"
318 "d '/var/lib/trafficserver' - ${user} ${group} - -"
319 "d '/var/log/trafficserver' - ${user} ${group} - -"
322 services.trafficserver = {
323 records.proxy.config.admin.user_id = user;
324 records.proxy.config.body_factory.template_sets_dir =
325 "${pkgs.trafficserver}/etc/trafficserver/body_factory";
328 users.users.trafficserver = {
329 description = "Apache Traffic Server";
333 users.groups.trafficserver = { };