8 cfg = config.services.kea;
10 format = pkgs.formats.json { };
12 chooseNotNull = x: y: if x != null then x else y;
14 ctrlAgentConfig = chooseNotNull cfg.ctrl-agent.configFile (
15 format.generate "kea-ctrl-agent.conf" {
16 Control-agent = cfg.ctrl-agent.settings;
20 dhcp4Config = chooseNotNull cfg.dhcp4.configFile (
21 format.generate "kea-dhcp4.conf" {
22 Dhcp4 = cfg.dhcp4.settings;
26 dhcp6Config = chooseNotNull cfg.dhcp6.configFile (
27 format.generate "kea-dhcp6.conf" {
28 Dhcp6 = cfg.dhcp6.settings;
32 dhcpDdnsConfig = chooseNotNull cfg.dhcp-ddns.configFile (
33 format.generate "kea-dhcp-ddns.conf" {
34 DhcpDdns = cfg.dhcp-ddns.settings;
41 options.services.kea = with lib.types; {
42 ctrl-agent = lib.mkOption {
44 Kea Control Agent configuration
49 enable = lib.mkEnableOption "Kea Control Agent";
51 extraArgs = lib.mkOption {
55 List of additional arguments to pass to the daemon.
59 configFile = lib.mkOption {
63 Kea Control Agent configuration as a path, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/agent.html>.
65 Takes preference over [settings](#opt-services.kea.ctrl-agent.settings).
66 Most users should prefer using [settings](#opt-services.kea.ctrl-agent.settings) instead.
70 settings = lib.mkOption {
74 Kea Control Agent configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/agent.html>.
81 dhcp4 = lib.mkOption {
83 DHCP4 Server configuration
88 enable = lib.mkEnableOption "Kea DHCP4 server";
90 extraArgs = lib.mkOption {
94 List of additional arguments to pass to the daemon.
98 configFile = lib.mkOption {
102 Kea DHCP4 configuration as a path, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp4-srv.html>.
104 Takes preference over [settings](#opt-services.kea.dhcp4.settings).
105 Most users should prefer using [settings](#opt-services.kea.dhcp4.settings) instead.
109 settings = lib.mkOption {
113 valid-lifetime = 4000;
116 interfaces-config = {
124 name = "/var/lib/kea/dhcp4.leases";
129 subnet = "192.0.2.0/24";
132 pool = "192.0.2.100 - 192.0.2.240";
139 Kea DHCP4 configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp4-srv.html>.
146 dhcp6 = lib.mkOption {
148 DHCP6 Server configuration
153 enable = lib.mkEnableOption "Kea DHCP6 server";
155 extraArgs = lib.mkOption {
159 List of additional arguments to pass to the daemon.
163 configFile = lib.mkOption {
167 Kea DHCP6 configuration as a path, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp6-srv.html>.
169 Takes preference over [settings](#opt-services.kea.dhcp6.settings).
170 Most users should prefer using [settings](#opt-services.kea.dhcp6.settings) instead.
174 settings = lib.mkOption {
178 valid-lifetime = 4000;
181 preferred-lifetime = 3000;
182 interfaces-config = {
190 name = "/var/lib/kea/dhcp6.leases";
195 subnet = "2001:db8:1::/64";
198 pool = "2001:db8:1::1-2001:db8:1::ffff";
205 Kea DHCP6 configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp6-srv.html>.
212 dhcp-ddns = lib.mkOption {
214 Kea DHCP-DDNS configuration
219 enable = lib.mkEnableOption "Kea DDNS server";
221 extraArgs = lib.mkOption {
225 List of additional arguments to pass to the daemon.
229 configFile = lib.mkOption {
233 Kea DHCP-DDNS configuration as a path, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/ddns.html>.
235 Takes preference over [settings](#opt-services.kea.dhcp-ddns.settings).
236 Most users should prefer using [settings](#opt-services.kea.dhcp-ddns.settings) instead.
240 settings = lib.mkOption {
244 ip-address = "127.0.0.1";
246 dns-server-timeout = 100;
247 ncr-protocol = "UDP";
258 Kea DHCP-DDNS configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/ddns.html>.
268 commonServiceConfig = {
269 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
272 ConfigurationDirectory = "kea";
273 RuntimeDirectory = "kea";
274 RuntimeDirectoryPreserve = true;
275 StateDirectory = "kea";
279 lib.mkIf (cfg.ctrl-agent.enable || cfg.dhcp4.enable || cfg.dhcp6.enable || cfg.dhcp-ddns.enable) (
282 environment.systemPackages = [ package ];
285 (lib.mkIf cfg.ctrl-agent.enable {
288 assertion = lib.xor (cfg.ctrl-agent.settings == null) (cfg.ctrl-agent.configFile == null);
289 message = "Either services.kea.ctrl-agent.settings or services.kea.ctrl-agent.configFile must be set to a non-null value.";
293 environment.etc."kea/ctrl-agent.conf".source = ctrlAgentConfig;
295 systemd.services.kea-ctrl-agent = {
296 description = "Kea Control Agent";
298 "man:kea-ctrl-agent(8)"
299 "https://kea.readthedocs.io/en/kea-${package.version}/arm/agent.html"
303 "network-online.target"
306 "network-online.target"
310 "kea-dhcp4-server.service"
311 "kea-dhcp6-server.service"
312 "kea-dhcp-ddns-server.service"
316 KEA_PIDFILE_DIR = "/run/kea";
317 KEA_LOCKFILE_DIR = "/run/kea";
325 ExecStart = "${package}/bin/kea-ctrl-agent -c /etc/kea/ctrl-agent.conf ${lib.escapeShellArgs cfg.ctrl-agent.extraArgs}";
326 KillMode = "process";
327 Restart = "on-failure";
328 } // commonServiceConfig;
332 (lib.mkIf cfg.dhcp4.enable {
335 assertion = lib.xor (cfg.dhcp4.settings == null) (cfg.dhcp4.configFile == null);
336 message = "Either services.kea.dhcp4.settings or services.kea.dhcp4.configFile must be set to a non-null value.";
340 environment.etc."kea/dhcp4-server.conf".source = dhcp4Config;
342 systemd.services.kea-dhcp4-server = {
343 description = "Kea DHCP4 Server";
346 "https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp4-srv.html"
350 "network-online.target"
354 "network-online.target"
361 KEA_PIDFILE_DIR = "/run/kea";
362 KEA_LOCKFILE_DIR = "/run/kea";
370 ExecStart = "${package}/bin/kea-dhcp4 -c /etc/kea/dhcp4-server.conf ${lib.escapeShellArgs cfg.dhcp4.extraArgs}";
371 # Kea does not request capabilities by itself
372 AmbientCapabilities = [
373 "CAP_NET_BIND_SERVICE"
376 CapabilityBoundingSet = [
377 "CAP_NET_BIND_SERVICE"
380 } // commonServiceConfig;
384 (lib.mkIf cfg.dhcp6.enable {
387 assertion = lib.xor (cfg.dhcp6.settings == null) (cfg.dhcp6.configFile == null);
388 message = "Either services.kea.dhcp6.settings or services.kea.dhcp6.configFile must be set to a non-null value.";
392 environment.etc."kea/dhcp6-server.conf".source = dhcp6Config;
394 systemd.services.kea-dhcp6-server = {
395 description = "Kea DHCP6 Server";
398 "https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp6-srv.html"
402 "network-online.target"
406 "network-online.target"
413 KEA_PIDFILE_DIR = "/run/kea";
414 KEA_LOCKFILE_DIR = "/run/kea";
422 ExecStart = "${package}/bin/kea-dhcp6 -c /etc/kea/dhcp6-server.conf ${lib.escapeShellArgs cfg.dhcp6.extraArgs}";
423 # Kea does not request capabilities by itself
424 AmbientCapabilities = [
425 "CAP_NET_BIND_SERVICE"
427 CapabilityBoundingSet = [
428 "CAP_NET_BIND_SERVICE"
430 } // commonServiceConfig;
434 (lib.mkIf cfg.dhcp-ddns.enable {
437 assertion = lib.xor (cfg.dhcp-ddns.settings == null) (cfg.dhcp-ddns.configFile == null);
438 message = "Either services.kea.dhcp-ddns.settings or services.kea.dhcp-ddns.configFile must be set to a non-null value.";
442 environment.etc."kea/dhcp-ddns.conf".source = dhcpDdnsConfig;
444 systemd.services.kea-dhcp-ddns-server = {
445 description = "Kea DHCP-DDNS Server";
447 "man:kea-dhcp-ddns(8)"
448 "https://kea.readthedocs.io/en/kea-${package.version}/arm/ddns.html"
451 wants = [ "network-online.target" ];
453 "network-online.target"
461 KEA_PIDFILE_DIR = "/run/kea";
462 KEA_LOCKFILE_DIR = "/run/kea";
470 ExecStart = "${package}/bin/kea-dhcp-ddns -c /etc/kea/dhcp-ddns.conf ${lib.escapeShellArgs cfg.dhcp-ddns.extraArgs}";
471 AmbientCapabilities = [
472 "CAP_NET_BIND_SERVICE"
474 CapabilityBoundingSet = [
475 "CAP_NET_BIND_SERVICE"
477 } // commonServiceConfig;
484 meta.maintainers = with lib.maintainers; [ hexa ];
485 # uses attributes of the linked package
486 meta.buildDocsInSandbox = false;