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 = {
20
21 services.radvd.enable = mkOption {
22 default = false;
23 description =
24 ''
25 Whether to enable the Router Advertisement Daemon
26 (<command>radvd</command>), 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 services.radvd.config = mkOption {
35 example =
36 ''
37 interface eth0 {
38 AdvSendAdvert on;
39 prefix 2001:db8:1234:5678::/64 { };
40 };
41 '';
42 description =
43 ''
44 The contents of the radvd configuration file.
45 '';
46 };
47
48 };
49
50
51 ###### implementation
52
53 config = mkIf cfg.enable {
54
55 users.extraUsers.radvd =
56 { uid = config.ids.uids.radvd;
57 description = "Router Advertisement Daemon User";
58 };
59
60 systemd.services.radvd =
61 { description = "IPv6 Router Advertisement Daemon";
62
63 wantedBy = [ "multi-user.target" ];
64
65 after = [ "network.target" ];
66
67 path = [ pkgs.radvd ];
68
69 preStart = ''
70 mkdir -m 755 -p /run/radvd
71 chown radvd /run/radvd
72 '';
73
74 serviceConfig =
75 { ExecStart = "@${pkgs.radvd}/sbin/radvd radvd"
76 + " -p /run/radvd/radvd.pid -m syslog -u radvd -C ${confFile}";
77 Restart = "always";
78 Type = "forking";
79 PIDFile = "/run/radvd/radvd.pid";
80 };
81 };
82
83 };
84
85}