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