Personal Nix setup

Add IPv6 options

Changed files
+47 -22
machines
modules
+1
machines/ramune/configuration.nix
···
external = {
name = "extern0";
macAddress = "5c:1b:f4:7f:dc:cd";
+
adoptMacAddress = "64:20:9f:16:70:a6";
};
internal = {
name = "intern0";
+1 -3
modules/router/kernel.nix
···
"net.ipv4.tcp_syncookies" = true;
"net.ipv6.conf.all.forwarding" = true;
-
"net.ipv6.conf.all.use_tempaddr" = false;
-
"net.ipv6.conf.all.autoconf" = false;
-
"net.ipv6.conf.all.accept_ra" = false;
+
"net.ipv6.conf.all.accept_ra" = 2;
"kernel.kptr_restrict" = 2;
"kernel.dmesg_restrict" = 0;
+40 -11
modules/router/network.nix
···
type = types.str;
example = "00:00:00:00:00:00";
};
+
adoptMacAddress = mkOption {
+
type = types.nullOr types.str;
+
example = "00:00:00:00:00:00";
+
};
cidr = mkOption {
type = types.str;
default = "0.0.0.0/0";
···
type = types.bool;
default = !config.services.avahi.enable;
};
+
ipv6 = mkOption {
+
type = types.bool;
+
default = false;
+
};
interfaces = {
external = mkOption {
type = interfaceType;
···
linkConfig = {
Description = "External Network Interface";
Name = extern.name;
-
# MACAddress = "64:20:9f:16:70:a6";
+
MACAddress = extern.adoptMacAddress;
MTUBytes = "1500";
};
};
···
};
nameservers = [
"1.1.1.1#cloudflare-dns.com"
-
"2606:4700:4700::1111#cloudflare-dns.com"
-
];
+
] ++ (if cfg.ipv6 then [ "2606:4700:4700::1111#cloudflare-dns.com" ] else []);
};
boot.initrd.systemd.network = {
···
systemd.network = {
enable = true;
inherit links;
-
networks = {
+
networks = let
+
gatewayAddress = ipv4.prettyIp (ipv4.cidrToIpAddress intern.cidr);
+
in {
"10-${extern.name}" = {
name = extern.name;
networkConfig = {
-
DHCP = "ipv4";
+
DHCP = if cfg.ipv6 then "yes" else "ipv4";
IPv4Forwarding = true;
IPv6Forwarding = true;
};
···
UseDomains = false;
UseNTP = !cfg.timeserver.enable;
};
+
dhcpV6Config = mkIf cfg.ipv6 {
+
WithoutRA = "solicit";
+
UseDNS = false;
+
UseDomains = false;
+
UseAddress = false;
+
DUIDType = "link-layer";
+
DUIDRawData = mkIf (extern.adoptMacAddress != null) "00:01:${extern.adoptMacAddress}";
+
};
+
ipv6AcceptRAConfig = mkIf cfg.ipv6 {
+
UseDNS = false;
+
UseDomains = false;
+
DHCPv6Client = "always";
+
};
};
} // (optionalAttrs (intern != null) {
"11-${intern.name}" = {
···
DHCPServer = true;
IPv4Forwarding = true;
IPv6Forwarding = true;
+
IPMasquerade = "both";
ConfigureWithoutCarrier = true;
MulticastDNS = cfg.mdns;
+
DHCPPrefixDelegation = cfg.ipv6;
+
IPv6SendRA = cfg.ipv6;
};
-
dhcpServerConfig = let
-
gatewayAddress = ipv4.prettyIp (ipv4.cidrToIpAddress intern.cidr);
-
in {
+
dhcpServerConfig = {
EmitDNS = true;
EmitNTP = true;
DNS = gatewayAddress;
···
Address = lease.ipAddress;
MACAddress = lease.macAddress;
}) cfg.leases;
+
+
dhcpPrefixDelegationConfig = mkIf cfg.ipv6 {
+
Announce = true;
+
};
};
});
};
···
enable = true;
fallbackDns = [
"1.0.0.1"
-
"2606:4700:4700::1001"
-
];
+
] ++ (if cfg.ipv6 then [ "2606:4700:4700::1001" ] else []);
dnsovertls = "opportunistic";
extraConfig = strings.concatStringsSep "\n" [
-
"[Resolve]"
+
''
+
[Resolve]
+
ReadEtcHosts=no
+
''
(optionalString cfg.mdns ''
MulticastDNS=yes
'')
+3 -7
modules/router/nftables.nix
···
ip protocol icmp \
icmp type { destination-unreachable, echo-reply, echo-request, source-quench, time-exceeded } \
accept
-
ip6 nexthdr icmpv6 accept
-
udp dport 546 ct state { new, untracked } accept
-
udp dport dhcpv6-client accept
+
meta l4proto ipv6-icmp accept
+
ip6 ecn not-ect accept
+
udp dport dhcpv6-client ct state { new, untracked } accept
udp dport { http, https } ct state new accept
tcp dport { http, https } ct state new accept
udp dport 41641 ct state new accept
···
chain forward {
type filter hook forward priority 0; policy drop;
-
ip6 nexthdr ipv6-icmp accept
-
udp dport dhcpv6-client accept
${blockForwardRules}
iifname { ${concatIfnames trustedInterfaces} } accept
oifname { ${concatIfnames trustedInterfaces} } ct state { established, related } accept
···
chain output {
type filter hook output priority 0; policy accept;
-
ip6 nexthdr ipv6-icmp accept
-
udp dport dhcpv6-client accept
iifname lo accept
ct state invalid drop
}
+2 -1
modules/server/tailscale.nix
···
config = mkIf (cfg.enable && cfgRoot.enable) {
networking = {
domain = "fable-pancake.ts.net";
+
search = [ "fable-pancake.ts.net" ];
firewall.trustedInterfaces = [ "tailscale0" ];
hosts."${address}" = [ "${hostname}.fable-pancake.ts.net" hostname ];
};
···
services.tailscale = {
enable = true;
-
useRoutingFeatures = "both";
+
useRoutingFeatures = "server";
extraUpFlags = [ "--advertise-exit-node" "--ssh" "--accept-dns=false" ];
extraDaemonFlags = [ "--no-logs-no-support" ];
authKeyFile = "/run/secrets/tailscale";