1# Module for the IPv6 Router Advertisement Daemon.
2
3{ config, lib, pkgs, ... }:
4
5with lib;
6
7let
8
9 cfg = config.services.radvd;
10
11 confFile = pkgs.writeText "radvd.conf" cfg.config;
12
13in
14
15{
16
17 ###### interface
18
19 options.services.radvd = {
20
21 enable = mkOption {
22 type = types.bool;
23 default = false;
24 description = ''
25 Whether to enable the Router Advertisement Daemon
26 ({command}`radvd`), which provides link-local
27 advertisements of IPv6 router addresses and prefixes using
28 the Neighbor Discovery Protocol (NDP). This enables
29 stateless address autoconfiguration in IPv6 clients on the
30 network.
31 '';
32 };
33
34 package = mkPackageOption pkgs "radvd" { };
35
36 debugLevel = mkOption {
37 type = types.int;
38 default = 0;
39 example = 5;
40 description = ''
41 The debugging level is an integer in the range from 1 to 5,
42 from quiet to very verbose. A debugging level of 0 completely
43 turns off debugging.
44 '';
45 };
46
47 config = mkOption {
48 type = types.lines;
49 example =
50 ''
51 interface eth0 {
52 AdvSendAdvert on;
53 prefix 2001:db8:1234:5678::/64 { };
54 };
55 '';
56 description = ''
57 The contents of the radvd configuration file.
58 '';
59 };
60
61 };
62
63
64 ###### implementation
65
66 config = mkIf cfg.enable {
67
68 users.users.radvd =
69 {
70 isSystemUser = true;
71 group = "radvd";
72 description = "Router Advertisement Daemon User";
73 };
74 users.groups.radvd = {};
75
76 systemd.services.radvd =
77 { description = "IPv6 Router Advertisement Daemon";
78 wantedBy = [ "multi-user.target" ];
79 after = [ "network.target" ];
80 serviceConfig =
81 { ExecStart = "@${cfg.package}/bin/radvd radvd -n -u radvd -d ${toString cfg.debugLevel} -C ${confFile}";
82 Restart = "always";
83 };
84 };
85
86 };
87
88}