forked from chayleaf/nixos-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorerad.nix
61 lines (60 loc) · 2.44 KB
/
corerad.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{ lib
, config
, pkgs
, utils
, router-lib
, ... }:
let
cfg = config.router;
in {
config = lib.mkIf cfg.enable {
systemd.services = lib.mapAttrs' (interface: icfg: let
cfg = icfg.ipv6.corerad;
settingsFormat = pkgs.formats.toml {};
ifaceConfig = {
name = interface;
monitor = false;
advertise = true;
managed = icfg.ipv6.kea.enable && icfg.ipv6.addresses != [ ];
other_config = icfg.ipv6.kea.enable && icfg.ipv6.addresses != [ ];
} // cfg.interfaceSettings;
configFile = if cfg.configFile != null then cfg.configFile else settingsFormat.generate "corerad-${interface}.toml" ({
interfaces = [
(ifaceConfig // {
prefix = map ({ address, prefixLength, coreradSettings, ... }: {
prefix = "${address}/${toString prefixLength}";
autonomous = !ifaceConfig.managed;
} // coreradSettings) icfg.ipv6.addresses;
route = builtins.concatLists (map ({ address, prefixLength, gateways, ... }: map (gateway: {
prefix = "${if builtins.isString gateway then gateway else gateway.address}/${toString (if gateway.prefixLength or null != null then gateway.prefixLength else prefixLength)}";
} // (gateway.coreradSettings or { })) gateways) icfg.ipv6.addresses);
rdnss = builtins.concatLists (map ({ dns, ... }: map (dns: {
servers = if builtins.isString dns then dns else dns.address;
} // (dns.coreradSettings or { })) dns) icfg.ipv6.addresses);
} // cfg.interfaceSettings)
];
} // cfg.settings);
package = pkgs.corerad;
in {
name = "corerad-${utils.escapeSystemdPath interface}";
value = lib.mkIf icfg.ipv6.corerad.enable (router-lib.mkServiceForIf interface {
description = "CoreRAD IPv6 NDP RA daemon (${interface})";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
LimitNPROC = 512;
LimitNOFILE = 1048576;
CapabilityBoundingSet = "CAP_NET_ADMIN CAP_NET_RAW";
AmbientCapabilities = "CAP_NET_ADMIN CAP_NET_RAW";
NoNewPrivileges = true;
DynamicUser = true;
Type = "notify";
NotifyAccess = "main";
ExecStart = "${lib.getBin package}/bin/corerad -c=${configFile}";
Restart = "on-failure";
RestartKillSignal = "SIGHUP";
};
});
}) cfg.interfaces;
};
}