Compare commits

Author SHA1 Message Date
CaZzzer 0cbc516fb0 WIP: router: tailscale 2026-10-11 12:08:01 -07:00
10 changed files with 111 additions and 42 deletions

No files matched your search

Generated
+6 -6
View File
@@ -60,11 +60,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1795366757, "lastModified": 1791642191,
"narHash": "sha256-Tp4Kh4R7ID1f2mMCDlb2PiFQ/DZZsnXB2u2juWN+TT4=", "narHash": "sha256-0bK0A59rVUn1SRZzo4cNi4VSqAe7vR1gL2/MZl53Frw=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "3b8140d21fa0a70b1b38c2ed29853dfe686234a6", "rev": "c58f54c733a7894d84fa2fdff26cc12088c4b78c",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -135,11 +135,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1795234589, "lastModified": 1791594108,
"narHash": "sha256-f/VVvxf5RsQgWVhUtefoca5ktVg0DA2bnkMOcmSnozo=", "narHash": "sha256-XK4KceonkwD8LuMAt/vNrz982mXJM5jeHAxMwsUXXAQ=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "2786a2a72088ecf32aea5b3ec52099e6a7cff78f", "rev": "6510408d147d8c5e6d76043e899e9251756f6a75",
"type": "github" "type": "github"
}, },
"original": { "original": {
-11
View File
@@ -12,8 +12,6 @@
]; ];
opts.kb-input.enable = true; opts.kb-input.enable = true;
boot.kernelPackages = pkgs.linuxPackages_latest;
# Bootloader. # Bootloader.
boot.kernelParams = [ boot.kernelParams = [
"amd_iommu=on" "amd_iommu=on"
@@ -31,21 +29,12 @@
# https://nixos.wiki/wiki/Accelerated_Video_Playback # https://nixos.wiki/wiki/Accelerated_Video_Playback
hardware.graphics.extraPackages = with pkgs; [ hardware.graphics.extraPackages = with pkgs; [
intel-media-driver # LIBVA_DRIVER_NAME=iHD intel-media-driver # LIBVA_DRIVER_NAME=iHD
vpl-gpu-rt
]; ];
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
lmstudio lmstudio
]; ];
services.ollama.enable = true;
services.ollama.package = pkgs.ollama-vulkan;
programs.obs-studio.enable = true;
programs.obs-studio.plugins = with pkgs.obs-studio-plugins; [
obs-vaapi
];
networking.hostName = "Yura-PC"; # Define your hostname. networking.hostName = "Yura-PC"; # Define your hostname.
networking.hostId = "110a2814"; # Required for ZFS. networking.hostId = "110a2814"; # Required for ZFS.
+5 -14
View File
@@ -14,26 +14,17 @@
boot.extraModulePackages = [ ]; boot.extraModulePackages = [ ];
fileSystems."/" = fileSystems."/" =
{ device = "/dev/mapper/luks-42b36c51-a57a-4bdb-b554-5742f1ae815a"; { device = "zroot/ROOT/nixos/default";
fsType = "btrfs"; fsType = "zfs";
};
boot.initrd.luks.devices."luks-42b36c51-a57a-4bdb-b554-5742f1ae815a".device = "/dev/disk/by-uuid/42b36c51-a57a-4bdb-b554-5742f1ae815a";
fileSystems."/home" =
{ device = "/dev/mapper/luks-42b36c51-a57a-4bdb-b554-5742f1ae815a";
fsType = "btrfs";
options = [ "subvol=home" ];
}; };
fileSystems."/nix" = fileSystems."/nix" =
{ device = "/dev/mapper/luks-42b36c51-a57a-4bdb-b554-5742f1ae815a"; { device = "zroot/data/nix";
fsType = "btrfs"; fsType = "zfs";
options = [ "subvol=nix" ];
}; };
fileSystems."/boot" = fileSystems."/boot" =
{ device = "/dev/disk/by-uuid/A043-E763"; { device = "/dev/disk/by-uuid/970C-6A15";
fsType = "vfat"; fsType = "vfat";
options = [ "fmask=0022" "dmask=0022" ]; options = [ "fmask=0022" "dmask=0022" ];
}; };
-2
View File
@@ -6,8 +6,6 @@
./hardware-configuration.nix ./hardware-configuration.nix
]; ];
boot.kernelPackages = pkgs.linuxPackages;
# Bootloader. # Bootloader.
boot.kernelParams = [ boot.kernelParams = [
"sysrq_always_enabled=1" "sysrq_always_enabled=1"
+1 -7
View File
@@ -7,6 +7,7 @@
"sysrq_always_enabled=1" "sysrq_always_enabled=1"
]; ];
boot.kernelPackages = pkgs.linuxKernel.packages.linux_7_2;
boot.loader = { boot.loader = {
efi.canTouchEfiVariables = true; efi.canTouchEfiVariables = true;
timeout = 3; timeout = 3;
@@ -72,10 +73,6 @@
programs.bat.enable = true; programs.bat.enable = true;
programs.htop.enable = true; programs.htop.enable = true;
programs.nix-ld.enable = true; programs.nix-ld.enable = true;
programs.nix-ld.libraries = with pkgs; [
stdenv.cc.cc.lib
# Add other common libraries if needed (e.g., zlib, glib)
];
# programs.steam.enable = true; # programs.steam.enable = true;
# https://nixos.wiki/wiki/Docker # https://nixos.wiki/wiki/Docker
@@ -135,9 +132,7 @@
kdePackages.filelight kdePackages.filelight
kdePackages.flatpak-kcm kdePackages.flatpak-kcm
kdePackages.kate kdePackages.kate
kdePackages.partitionmanager
kdePackages.yakuake kdePackages.yakuake
mission-center
(mpv.override { (mpv.override {
scripts = with pkgs.mpvScripts; [ scripts = with pkgs.mpvScripts; [
mpris mpris
@@ -166,7 +161,6 @@
antigravity-cli antigravity-cli
antigravity-ide-fhs antigravity-ide-fhs
codex codex
bubblewrap
# codex-acp # codex-acp
# github-copilot-cli # github-copilot-cli
# opencode # opencode
+1
View File
@@ -9,6 +9,7 @@ in
./opts.nix ./opts.nix
./ifconfig.nix ./ifconfig.nix
./wireguard.nix ./wireguard.nix
./tailscale.nix
./firewall.nix ./firewall.nix
./dns.nix ./dns.nix
./kea.nix ./kea.nix
+45 -1
View File
@@ -15,6 +15,11 @@ let
${ifs.lan50.name}, ${ifs.lan50.name},
${ifs.wg0.name}, ${ifs.wg0.name},
} }
# Tailscale is its own zone, since tailnet traffic is already filtered by tailscale ACLs
# and needs some special handling (exit node NAT with CGNAT/ULA addrs)
define ZONE_TAILSCALE_IFS = { ${ifs.ts0.name} }
define TAILSCALE_NET4 = ${ifs.ts0.net4}
define TAILSCALE_NET6 = ${ifs.ts0.net6}
define OPNSENSE_NET6 = ${vars.extra.opnsense.net6} define OPNSENSE_NET6 = ${vars.extra.opnsense.net6}
define ZONE_LAN_EXTRA_NET6 = { define ZONE_LAN_EXTRA_NET6 = {
# TODO: reevaluate this statement # TODO: reevaluate this statement
@@ -80,6 +85,8 @@ in
# Masquerade LAN addrs # Masquerade LAN addrs
oifname $ZONE_WAN_IFS ip saddr $RFC1918 masquerade oifname $ZONE_WAN_IFS ip saddr $RFC1918 masquerade
# Masquerade tailnet addrs (tailscale exit node)
oifname $ZONE_WAN_IFS ip saddr $TAILSCALE_NET4 masquerade
} }
''; '';
}; };
@@ -97,12 +104,28 @@ in
''; '';
}; };
# IPv6 masquerading for tailnet addrs only (tailscale exit node)
# Tailscale only assigns ULAs from $TAILSCALE_NET6, so NAT is unavoidable here
networking.nftables.tables.nat6_tailscale = {
family = "ip6";
content = ''
${nftIdentifiers}
chain postrouting {
type nat hook postrouting priority srcnat; policy accept;
oifname $ZONE_WAN_IFS ip6 saddr $TAILSCALE_NET6 masquerade
}
'';
};
networking.nftables.tables.firewall = { networking.nftables.tables.firewall = {
family = "inet"; family = "inet";
content = '' content = ''
${nftIdentifiers} ${nftIdentifiers}
define ALLOWED_TCP_PORTS = { ssh } define ALLOWED_TCP_PORTS = { ssh }
define ALLOWED_UDP_PORTS = { ${toString vars.ifs.wg0.listenPort} } define ALLOWED_UDP_PORTS = {
${toString vars.ifs.wg0.listenPort},
${toString vars.ifs.ts0.listenPort}, # tailscale direct connections
}
define ALLOWED_TCP_LAN_PORTS = { ssh, https } define ALLOWED_TCP_LAN_PORTS = { ssh, https }
define ALLOWED_UDP_LAN_PORTS = { bootps, dhcpv6-server, domain, https } define ALLOWED_UDP_LAN_PORTS = { bootps, dhcpv6-server, domain, https }
set port_forward_v6 { set port_forward_v6 {
@@ -161,6 +184,8 @@ in
# iifname $ZONE_LAN_IFS accept # iifname $ZONE_LAN_IFS accept
iifname $ZONE_LAN_IFS jump zone_lan_input iifname $ZONE_LAN_IFS jump zone_lan_input
ip6 saddr $ZONE_LAN_EXTRA_NET6 jump zone_lan_input ip6 saddr $ZONE_LAN_EXTRA_NET6 jump zone_lan_input
# Tailscale zone input rules
iifname $ZONE_TAILSCALE_IFS jump zone_tailscale_input
# log # log
} }
@@ -176,6 +201,8 @@ in
# LAN zone forward rules # LAN zone forward rules
iifname $ZONE_LAN_IFS jump zone_lan_forward iifname $ZONE_LAN_IFS jump zone_lan_forward
ip6 saddr $ZONE_LAN_EXTRA_NET6 jump zone_lan_forward ip6 saddr $ZONE_LAN_EXTRA_NET6 jump zone_lan_forward
# Tailscale zone forward rules
iifname $ZONE_TAILSCALE_IFS jump zone_tailscale_forward
} }
chain zone_wan_input { chain zone_wan_input {
@@ -215,6 +242,23 @@ in
# Allow traffic between LANs # Allow traffic between LANs
oifname $ZONE_LAN_IFS accept oifname $ZONE_LAN_IFS accept
# Allow LAN to reach tailnet (no SNAT, tailnet peers see real LAN addrs)
oifname $ZONE_TAILSCALE_IFS accept
}
chain zone_tailscale_input {
# Tailnet access is restricted by tailscale ACLs, treat like LAN
jump zone_lan_input
}
chain zone_tailscale_forward {
# Subnet router: allow tailnet to LANs (advertised routes)
oifname $ZONE_LAN_IFS accept
# Exit node: allow tailnet to WAN (masqueraded in nat4 / nat6_tailscale)
oifname $ZONE_WAN_IFS ip saddr $TAILSCALE_NET4 accept
oifname $ZONE_WAN_IFS ip6 saddr $TAILSCALE_NET6 accept
} }
chain output { chain output {
+1 -1
View File
@@ -60,7 +60,7 @@ in
enable = true; enable = true;
package = pkgs.caddy.withPlugins { package = pkgs.caddy.withPlugins {
plugins = [ "github.com/caddy-dns/cloudflare@v0.2.4" ]; plugins = [ "github.com/caddy-dns/cloudflare@v0.2.4" ];
hash = "sha256-QSiwKqKvSxhksWBF4/MlBOpyXba5xOQ2sRwA0R7399E="; hash = "sha256-xRJ5evsAJ2akg47j3Bt6YDXJOgX88B/rKNP50KSVyNY=";
}; };
virtualHosts."*.${domain}".extraConfig = '' virtualHosts."*.${domain}".extraConfig = ''
encode encode
+44
View File
@@ -0,0 +1,44 @@
{ config, lib, pkgs, ... }:
let
vars = import ./vars.nix config;
ifs = vars.ifs;
ts0 = ifs.ts0;
# Subnets advertised to the tailnet (still need to be approved in the admin console)
advertisedRoutes = [
"${vars.p4}.0.0/16" # all LAN v4 subnets
"${vars.ulaPrefix}::/48" # all LAN ULA subnets
];
in
{
# One-time setup after deploying: `sudo tailscale up`
# (state is persisted in /var/lib/tailscale)
services.tailscale = {
enable = true;
port = ts0.listenPort;
interfaceName = ts0.name;
# Enables ip forwarding (already enabled globally by networkd anyway).
# Not using "both", since that sets rp_filter to loose on all interfaces.
useRoutingFeatures = "server";
# Firewall is managed manually in firewall.nix (networking.firewall is disabled)
openFirewall = false;
# Applied with `tailscale set` on every start, so these stay declarative
extraSetFlags = [
# Don't let tailscale touch nftables/iptables, all rules live in firewall.nix
"--netfilter-mode=off"
# Don't SNAT tailnet -> LAN traffic, LAN hosts route back via the router anyway
# (preserves real source addrs for logging/ACLs on LAN hosts)
"--snat-subnet-routes=false"
# The router is its own DNS server, don't let tailscale mess with resolv.conf
"--accept-dns=false"
"--advertise-routes=${lib.strings.concatStringsSep "," advertisedRoutes}"
"--advertise-exit-node"
];
};
# networkd removes "foreign" ip rules when it (re)starts, which would wipe tailscale's
# policy routing rules (table 52). This is extra important since networkd is
# restarted every minute (see ifconfig.nix).
# The nixpkgs tailscale module already marks tailscale0 as unmanaged in networkd.
systemd.network.config.networkConfig.ManageForeignRoutingPolicyRules = false;
}
+8
View File
@@ -111,6 +111,14 @@ rec {
} // { } // {
listenPort = 51944; listenPort = 51944;
}; };
# Tailscale addresses are assigned by the coordination server,
# these are the fixed ranges tailscale allocates node addrs from.
ts0 = {
name = "tailscale0";
listenPort = 41641;
net4 = "100.64.0.0/10";
net6 = "fd7a:115c:a1e0::/48";
};
}; };
extra = { extra = {