Skip to content

Commit 5dcffe8

Browse files
committed
fix ivp6 RA
1 parent 0496d43 commit 5dcffe8

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

modules/nixos/hetzner.nix

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
cores = 1;
3737
};
3838

39-
# Networking: DHCPv4 + static IPv6 (Hetzner doesn't provide DHCPv6 or RA)
39+
# Networking: DHCPv4 + static IPv6 from metadata API
40+
# Hetzner Cloud doesn't send Router Advertisements — the VM must configure
41+
# IPv6 statically. The address/gateway are fetched from the metadata API at
42+
# boot and written as a networkd drop-in before networkd starts.
4043
networking.usePredictableInterfaceNames = lib.mkForce false;
4144
networking.useNetworkd = true;
4245
systemd.network.networks."10-eth0" = {
@@ -48,7 +51,6 @@
4851
dhcpV4Config.UseDNS = true;
4952
};
5053

51-
# Fetch IPv6 config from Hetzner metadata API at boot and apply via networkd drop-in
5254
systemd.services.hetzner-ipv6 = {
5355
description = "Configure IPv6 from Hetzner Cloud metadata";
5456
wantedBy = [ "network-pre.target" ];
@@ -60,15 +62,13 @@
6062
};
6163
path = with pkgs; [
6264
curl
63-
jq
6465
coreutils
6566
gawk
6667
];
6768
script = ''
6869
set -euo pipefail
6970
METADATA=$(curl -sf http://169.254.169.254/hetzner/v1/metadata)
7071
71-
# Parse IPv6 address and gateway from the YAML metadata
7272
IPV6_ADDR=$(echo "$METADATA" | awk '/type: static/{found=1} found && /address:/{print $2; exit}')
7373
IPV6_GW=$(echo "$METADATA" | awk '/type: static/{found=1} found && /gateway:/{print $2; exit}')
7474
IPV6_DNS=$(echo "$METADATA" | awk '/type: static/{found=1} found && /dns_nameservers:/{dns=1; next} dns && /^ *-/{print $2; next} dns{exit}')
@@ -79,19 +79,17 @@
7979
fi
8080
8181
mkdir -p /etc/systemd/network/10-eth0.network.d
82-
cat > /etc/systemd/network/10-eth0.network.d/ipv6.conf <<EOF
83-
[Network]
84-
Address=$IPV6_ADDR
85-
DNS=$(echo "$IPV6_DNS" | head -1)
86-
DNS=$(echo "$IPV6_DNS" | tail -1)
87-
88-
[Route]
89-
Gateway=$IPV6_GW
90-
Destination=::/0
91-
EOF
92-
93-
# Remove leading whitespace from heredoc
94-
sed -i 's/^[[:space:]]*//' /etc/systemd/network/10-eth0.network.d/ipv6.conf
82+
{
83+
echo "[Network]"
84+
echo "Address=$IPV6_ADDR"
85+
echo "$IPV6_DNS" | while read -r dns; do
86+
[ -n "$dns" ] && echo "DNS=$dns"
87+
done
88+
echo ""
89+
echo "[Route]"
90+
echo "Gateway=$IPV6_GW"
91+
echo "Destination=::/0"
92+
} > /etc/systemd/network/10-eth0.network.d/ipv6.conf
9593
'';
9694
};
9795

@@ -150,7 +148,11 @@
150148
};
151149

152150
# Tailscale
153-
services.tailscale.enable = true;
151+
services.tailscale = {
152+
enable = true;
153+
useRoutingFeatures = "both";
154+
openFirewall = true;
155+
};
154156

155157
time.timeZone = "UTC";
156158
}

0 commit comments

Comments
 (0)