10 cfg = config.services.kea;
12 xor = x: y: (!x && y) || (x && !y);
13 format = pkgs.formats.json {};
15 chooseNotNull = x: y: if x != null then x else y;
17 ctrlAgentConfig = chooseNotNull cfg.ctrl-agent.configFile (format.generate "kea-ctrl-agent.conf" {
18 Control-agent = cfg.ctrl-agent.settings;
21 dhcp4Config = chooseNotNull cfg.dhcp4.configFile (format.generate "kea-dhcp4.conf" {
22 Dhcp4 = cfg.dhcp4.settings;
25 dhcp6Config = chooseNotNull cfg.dhcp6.configFile (format.generate "kea-dhcp6.conf" {
26 Dhcp6 = cfg.dhcp6.settings;
29 dhcpDdnsConfig = chooseNotNull cfg.dhcp-ddns.configFile (format.generate "kea-dhcp-ddns.conf" {
30 DhcpDdns = cfg.dhcp-ddns.settings;
36 options.services.kea = with types; {
37 ctrl-agent = mkOption {
38 description = lib.mdDoc ''
39 Kea Control Agent configuration
44 enable = mkEnableOption (lib.mdDoc "Kea Control Agent");
46 extraArgs = mkOption {
49 description = lib.mdDoc ''
50 List of additonal arguments to pass to the daemon.
54 configFile = mkOption {
57 description = lib.mdDoc ''
58 Kea Control Agent configuration as a path, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/agent.html>.
60 Takes preference over [settings](#opt-services.kea.ctrl-agent.settings).
61 Most users should prefer using [settings](#opt-services.kea.ctrl-agent.settings) instead.
68 description = lib.mdDoc ''
69 Kea Control Agent configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/agent.html>.
77 description = lib.mdDoc ''
78 DHCP4 Server configuration
83 enable = mkEnableOption (lib.mdDoc "Kea DHCP4 server");
85 extraArgs = mkOption {
88 description = lib.mdDoc ''
89 List of additonal arguments to pass to the daemon.
93 configFile = mkOption {
96 description = lib.mdDoc ''
97 Kea DHCP4 configuration as a path, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp4-srv.html>.
99 Takes preference over [settings](#opt-services.kea.dhcp4.settings).
100 Most users should prefer using [settings](#opt-services.kea.dhcp4.settings) instead.
104 settings = mkOption {
108 valid-lifetime = 4000;
111 interfaces-config = {
119 name = "/var/lib/kea/dhcp4.leases";
122 subnet = "192.0.2.0/24";
124 pool = "192.0.2.100 - 192.0.2.240";
128 description = lib.mdDoc ''
129 Kea DHCP4 configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp4-srv.html>.
137 description = lib.mdDoc ''
138 DHCP6 Server configuration
143 enable = mkEnableOption (lib.mdDoc "Kea DHCP6 server");
145 extraArgs = mkOption {
148 description = lib.mdDoc ''
149 List of additonal arguments to pass to the daemon.
153 configFile = mkOption {
156 description = lib.mdDoc ''
157 Kea DHCP6 configuration as a path, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp6-srv.html>.
159 Takes preference over [settings](#opt-services.kea.dhcp6.settings).
160 Most users should prefer using [settings](#opt-services.kea.dhcp6.settings) instead.
164 settings = mkOption {
168 valid-lifetime = 4000;
171 preferred-lifetime = 3000;
172 interfaces-config = {
180 name = "/var/lib/kea/dhcp6.leases";
183 subnet = "2001:db8:1::/64";
185 pool = "2001:db8:1::1-2001:db8:1::ffff";
189 description = lib.mdDoc ''
190 Kea DHCP6 configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp6-srv.html>.
197 dhcp-ddns = mkOption {
198 description = lib.mdDoc ''
199 Kea DHCP-DDNS configuration
204 enable = mkEnableOption (lib.mdDoc "Kea DDNS server");
206 extraArgs = mkOption {
209 description = lib.mdDoc ''
210 List of additonal arguments to pass to the daemon.
214 configFile = mkOption {
217 description = lib.mdDoc ''
218 Kea DHCP-DDNS configuration as a path, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/ddns.html>.
220 Takes preference over [settings](#opt-services.kea.dhcp-ddns.settings).
221 Most users should prefer using [settings](#opt-services.kea.dhcp-ddns.settings) instead.
225 settings = mkOption {
229 ip-address = "127.0.0.1";
231 dns-server-timeout = 100;
232 ncr-protocol = "UDP";
242 description = lib.mdDoc ''
243 Kea DHCP-DDNS configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/ddns.html>.
252 commonServiceConfig = {
253 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
256 ConfigurationDirectory = "kea";
257 RuntimeDirectory = "kea";
258 StateDirectory = "kea";
261 in mkIf (cfg.ctrl-agent.enable || cfg.dhcp4.enable || cfg.dhcp6.enable || cfg.dhcp-ddns.enable) (mkMerge [
263 environment.systemPackages = [ package ];
266 (mkIf cfg.ctrl-agent.enable {
268 assertion = xor (cfg.ctrl-agent.settings == null) (cfg.ctrl-agent.configFile == null);
269 message = "Either services.kea.ctrl-agent.settings or services.kea.ctrl-agent.configFile must be set to a non-null value.";
272 environment.etc."kea/ctrl-agent.conf".source = ctrlAgentConfig;
274 systemd.services.kea-ctrl-agent = {
275 description = "Kea Control Agent";
277 "man:kea-ctrl-agent(8)"
278 "https://kea.readthedocs.io/en/kea-${package.version}/arm/agent.html"
282 "network-online.target"
286 "kea-dhcp4-server.service"
287 "kea-dhcp6-server.service"
288 "kea-dhcp-ddns-server.service"
292 KEA_PIDFILE_DIR = "/run/kea";
293 KEA_LOCKFILE_DIR = "/run/kea";
301 ExecStart = "${package}/bin/kea-ctrl-agent -c /etc/kea/ctrl-agent.conf ${lib.escapeShellArgs cfg.ctrl-agent.extraArgs}";
302 KillMode = "process";
303 Restart = "on-failure";
304 } // commonServiceConfig;
308 (mkIf cfg.dhcp4.enable {
310 assertion = xor (cfg.dhcp4.settings == null) (cfg.dhcp4.configFile == null);
311 message = "Either services.kea.dhcp4.settings or services.kea.dhcp4.configFile must be set to a non-null value.";
314 environment.etc."kea/dhcp4-server.conf".source = dhcp4Config;
316 systemd.services.kea-dhcp4-server = {
317 description = "Kea DHCP4 Server";
320 "https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp4-srv.html"
324 "network-online.target"
332 KEA_PIDFILE_DIR = "/run/kea";
333 KEA_LOCKFILE_DIR = "/run/kea";
341 ExecStart = "${package}/bin/kea-dhcp4 -c /etc/kea/dhcp4-server.conf ${lib.escapeShellArgs cfg.dhcp4.extraArgs}";
342 # Kea does not request capabilities by itself
343 AmbientCapabilities = [
344 "CAP_NET_BIND_SERVICE"
347 CapabilityBoundingSet = [
348 "CAP_NET_BIND_SERVICE"
351 } // commonServiceConfig;
355 (mkIf cfg.dhcp6.enable {
357 assertion = xor (cfg.dhcp6.settings == null) (cfg.dhcp6.configFile == null);
358 message = "Either services.kea.dhcp6.settings or services.kea.dhcp6.configFile must be set to a non-null value.";
361 environment.etc."kea/dhcp6-server.conf".source = dhcp6Config;
363 systemd.services.kea-dhcp6-server = {
364 description = "Kea DHCP6 Server";
367 "https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp6-srv.html"
371 "network-online.target"
379 KEA_PIDFILE_DIR = "/run/kea";
380 KEA_LOCKFILE_DIR = "/run/kea";
388 ExecStart = "${package}/bin/kea-dhcp6 -c /etc/kea/dhcp6-server.conf ${lib.escapeShellArgs cfg.dhcp6.extraArgs}";
389 # Kea does not request capabilities by itself
390 AmbientCapabilities = [
391 "CAP_NET_BIND_SERVICE"
393 CapabilityBoundingSet = [
394 "CAP_NET_BIND_SERVICE"
396 } // commonServiceConfig;
400 (mkIf cfg.dhcp-ddns.enable {
402 assertion = xor (cfg.dhcp-ddns.settings == null) (cfg.dhcp-ddns.configFile == null);
403 message = "Either services.kea.dhcp-ddns.settings or services.kea.dhcp-ddns.configFile must be set to a non-null value.";
406 environment.etc."kea/dhcp-ddns.conf".source = dhcpDdnsConfig;
408 systemd.services.kea-dhcp-ddns-server = {
409 description = "Kea DHCP-DDNS Server";
411 "man:kea-dhcp-ddns(8)"
412 "https://kea.readthedocs.io/en/kea-${package.version}/arm/ddns.html"
416 "network-online.target"
424 KEA_PIDFILE_DIR = "/run/kea";
425 KEA_LOCKFILE_DIR = "/run/kea";
433 ExecStart = "${package}/bin/kea-dhcp-ddns -c /etc/kea/dhcp-ddns.conf ${lib.escapeShellArgs cfg.dhcp-ddns.extraArgs}";
434 AmbientCapabilities = [
435 "CAP_NET_BIND_SERVICE"
437 CapabilityBoundingSet = [
438 "CAP_NET_BIND_SERVICE"
440 } // commonServiceConfig;
446 meta.maintainers = with maintainers; [ hexa ];
447 # uses attributes of the linked package
448 meta.buildDocsInSandbox = false;