Personal Nix setup

Replace ntpd with chrony

Changed files
+24 -19
modules
+10 -10
modules/router/nftables.nix
···
cfg = config.modules.router;
intern = cfg.interfaces.internal;
-
extern = cfg.interfaces.external;
+
trustedInterfaces = config.networking.firewall.trustedInterfaces;
+
internalInterfaces = lists.remove "lo" trustedInterfaces;
-
trustedInterfaces =
-
strings.concatMapStringsSep ", " strings.escapeNixIdentifier config.networking.firewall.trustedInterfaces;
+
concatIfnames = strings.concatMapStringsSep ", " strings.escapeNixIdentifier;
capturePortsRules =
strings.concatStringsSep "\n"
-
(builtins.map (port: " iifname { ${trustedInterfaces} } udp dport ${toString port} redirect to ${toString port}") cfg.nftables.capturePorts);
+
(builtins.map (port: " iifname { ${concatIfnames internalInterfaces} } udp dport ${toString port} redirect to ${toString port}") cfg.nftables.capturePorts);
blockForwardRules =
if intern != null then
···
chain postrouting {
type nat hook postrouting priority 0; policy accept;
-
oifname != { ${trustedInterfaces} } masquerade
+
oifname != { ${concatIfnames trustedInterfaces} } masquerade
}
chain input {
type filter hook input priority 0;
ct state { established, related } accept
ct state invalid drop
-
iifname { ${trustedInterfaces} } accept
-
iifname { ${trustedInterfaces} } pkttype { broadcast, multicast } accept
+
iifname { ${concatIfnames trustedInterfaces} } accept
+
iifname { ${concatIfnames trustedInterfaces} } pkttype { broadcast, multicast } accept
tcp flags & (fin|syn|rst|ack) != syn ct state new counter drop
tcp flags & (fin|syn|rst|psh|ack|urg) == fin|syn|rst|psh|ack|urg counter drop
tcp flags & (fin|syn|rst|psh|ack|urg) == 0x0 counter drop
···
ip6 nexthdr ipv6-icmp accept
udp dport dhcpv6-client accept
${blockForwardRules}
-
iifname { ${trustedInterfaces} } accept
-
oifname { ${trustedInterfaces} } ct state { established, related } accept
+
iifname { ${concatIfnames trustedInterfaces} } accept
+
oifname { ${concatIfnames trustedInterfaces} } ct state { established, related } accept
ct state invalid drop
}
···
content = ''
chain input {
type filter hook input priority 0; policy accept;
-
iifname != { ${trustedInterfaces} } limit rate 1/second burst 2 packets accept
+
iifname != { ${concatIfnames trustedInterfaces} } limit rate 1/second burst 2 packets accept
}
chain output {
+14 -9
modules/router/timeserver.nix
···
let
cfg = config.modules.router;
-
listenInterfaces =
-
strings.concatStringsSep "\n"
-
(builtins.map (ifname: "interface listen ${ifname}") config.networking.firewall.trustedInterfaces);
+
intern = cfg.interfaces.internal;
-
ntpExtraConfig = ''
-
${listenInterfaces}
-
interface ignore ${cfg.interfaces.external.name}
-
'';
+
bindDevices =
+
strings.concatStringsSep "\n"
+
(builtins.map (ifname: "binddevice ${ifname}")
+
(lists.remove "lo" config.networking.firewall.trustedInterfaces));
in {
options.modules.router = {
timeserver.enable = mkOption {
···
config = mkIf cfg.timeserver.enable {
networking.timeServers = [ "time.cloudflare.com" ];
-
services.ntp = {
+
services.chrony = {
enable = true;
-
extraConfig = ntpExtraConfig;
+
enableNTS = true;
+
extraConfig = ''
+
allow ${intern.cidr}
+
${bindDevices}
+
'';
};
+
+
services.ntp.enable = false;
+
services.openntpd.enable = false;
};
}