all repos — nixfiles @ 5e1526822af149847da5f947cffad6b074c0f16d

System and user configuration, managed by nix and home-manager

extract and generalise tailscale subnet route advertisement

Alin
commit

5e1526822af149847da5f947cffad6b074c0f16d

parent

5172a249c73d1982400310389e32769d5b94b608

3 files changed, 28 insertions(+), 13 deletions(-)

changed files
M system/hosts/r5.nix → system/hosts/r5.nix
@@ -14,6 +14,7 @@ imports = [
../roles/home.nix ../roles/server.nix ../roles/router.nix + ../roles/tailscale-subnet-router.nix ../settings/hardware/usb-serial-tty.nix ]; age.secrets = {
@@ -60,12 +61,6 @@ RequiredForOnline = "routable";
}; }; }; - }; - - services.tailscale = { - extraSetFlags = [ - "--advertise-routes 10.0.0.0/16" - ]; }; environment.systemPackages = with pkgs; [
M system/hosts/r6.nix → system/hosts/r6.nix
@@ -88,13 +88,6 @@ # };
# }; # }; - services.tailscale = { - extraSetFlags = [ - "--advertise-exit-node" - "--advertise-routes=10.0.0.0/16,fd12:d04f:65d:42::/56" - ]; - }; - environment.systemPackages = with pkgs; [ file tree
A system/roles/tailscale-subnet-router.nix
@@ -0,0 +1,27 @@
+{ + config, + lib, + ... +}: +let + lan = builtins.head config.networking.nat.internalInterfaces; + withArg = + arg: list: + if list == [ ] || builtins.length list == 1 then + list + else + lib.concatMap (x: [ + arg + x + ]) list; +in +{ + networking.firewall.extraForwardRules = '' + iifname "tailscale0" oifname "${lan}" accept + iifname "${lan}" oifname "tailscale0" accept + ''; + + services.tailscale.extraSetFlags = + withArg "--advertise-routes" + config.systemd.network.networks."40-${lan}".address; +}