Files
nixos/hosts/unstable/genesis/networking.nix
T

151 lines
3.7 KiB
Nix
Raw Normal View History

2025-12-28 21:18:13 -06:00
{
config,
2026-04-19 01:04:41 -05:00
lib,
lib',
2025-12-28 21:18:13 -06:00
metadata,
2026-04-19 01:04:41 -05:00
pkgs,
2025-12-28 21:18:13 -06:00
...
}:
2023-08-21 21:22:26 -05:00
let
2025-12-28 21:18:13 -06:00
lan = "enp1s0";
lanIP = metadata.hosts.${config.networking.hostName}.ip;
iot = "enp2s0";
iotIP = "192.168.66.250";
extraHosts = builtins.readFile ./net/hosts;
2023-09-05 11:06:35 -05:00
proxyPort = 3128;
dnsPort = 53;
dhcpPort = 67;
dnsServers = [
2025-12-28 21:18:13 -06:00
#"9.9.9.9" # Quad 9
#"1.1.1.1" # Cloudflare
#"1.0.0.1" # Cloudflare
#"149.112.112.112" # Quad 9
metadata.infra.gw # Currently using our UniFi router for DNS as well
2026-05-30 00:24:36 -05:00
"100.100.100.100"
];
in
{
2026-04-24 18:56:10 -05:00
greg = {
nebula = {
enable = true;
# genesis IS the routing node for the home LAN — it does not route through itself.
# Override the module default (which points at genesis) to avoid a routing loop.
unsafeRoutes = [ ];
# genesis routes the home LAN (10.42.0.0/16) into the Nebula overlay.
# Sign genesis's cert with -subnets '10.42.0.0/16' (see secrets/nebula/README.md).
routesSubnet = "10.42.0.0/16";
};
tailscale = {
enable = true;
tags = [ "home" ];
};
2025-11-15 14:08:34 -06:00
};
2023-06-29 00:27:30 -05:00
# Really, why do I still have to force-disable this crap?
boot.kernel.sysctl = {
"net.ipv6.conf.${lan}.disable_ipv6" = true;
"net.ipv6.conf.${iot}.disable_ipv6" = true;
"net.ipv6.conf.lo.disable_ipv6" = true;
};
2023-08-21 21:22:26 -05:00
networking = {
2025-12-28 21:18:13 -06:00
defaultGateway = metadata.infra.gw;
enableIPv6 = false;
networkmanager.enable = pkgs.lib.mkForce false;
nameservers = dnsServers;
interfaces = {
# This is our LAN port
"${lan}" = {
useDHCP = false;
2024-10-19 01:19:59 -05:00
ipv4.addresses = [
{
address = "${lanIP}";
prefixLength = 16;
}
];
};
2023-06-29 00:27:30 -05:00
"${iot}" = {
useDHCP = false;
2024-10-19 01:19:59 -05:00
ipv4.addresses = [
{
address = "${iotIP}";
prefixLength = 24;
}
];
};
};
firewall = {
2026-08-05 22:57:58 -05:00
enable = true;
allowedUDPPorts = [
dhcpPort
dnsPort
];
allowedTCPPorts = [
dnsPort
proxyPort
80
];
};
2026-08-05 22:57:58 -05:00
nftables.enable = true;
};
2023-06-29 00:27:30 -05:00
environment.etc."hosts.d/local".text = extraHosts;
2023-06-29 00:27:30 -05:00
services = {
#########
# dnsmasq config
########
2026-04-19 01:04:41 -05:00
bind = {
enable = true;
2026-04-19 01:04:41 -05:00
cacheNetworks = [
metadata.infra.lan
metadata.infra.tailscale
metadata.infra.nebula
2026-04-29 16:11:20 -05:00
"127.0.0.0/8"
2026-04-19 01:04:41 -05:00
];
zones =
let
makeZoneFile =
hosts: domain:
let
preamble = [
"$ORIGIN\t${domain}."
"$TTL\t1h"
"@\tIN\tSOA\t${config.networking.hostName}\tgreg@thehellings.com (1 1m 1m 1m 1m)"
"\tIN\tNS\t${config.networking.hostName}"
];
2026-05-19 23:47:42 -05:00
makeHost =
host:
[ "${host.name}\tIN\tA\t${host.address}" ]
++ lib.map (a: "${a}\tIN\tA\t${host.address}") (
if builtins.hasAttr "aliases" host then host.aliases else [ ]
);
2026-04-19 01:04:41 -05:00
in
pkgs.writeText "${domain}" (
2026-05-19 23:47:42 -05:00
builtins.concatStringsSep "\n" (preamble ++ (lib.flatten (lib.map makeHost hosts)) ++ [ "" ])
2026-04-19 01:04:41 -05:00
);
in
lib.mapAttrs
(domain: net: {
master = true;
2026-07-25 15:18:15 -05:00
file = makeZoneFile (lib'.hostsByNet net (metadata.hosts // metadata.external)) domain;
2026-04-19 01:04:41 -05:00
})
{
2026-07-25 11:40:35 -05:00
"shire-zebra.ts.net" = "tailscale";
2026-04-19 01:04:41 -05:00
"nebula.thehellings.com" = "nebula";
nebula = "nebula";
"thehellings.lan" = "lan";
lan = "lan";
};
};
}; # End of services configuration
2023-06-29 00:27:30 -05:00
environment.systemPackages = with pkgs; [
bind
curl # Used by dnsmasq fetching
sqlite
];
2023-06-29 00:27:30 -05:00
}