Files
nixos/hosts/genesis/networking.nix
T

232 lines
6.1 KiB
Nix
Raw Normal View History

2023-08-21 21:22:26 -05:00
{ pkgs, config, ... }:
let
2023-09-02 20:07:12 -05:00
lan = "ens18";
2023-09-05 11:06:35 -05:00
lanIP = "10.42.1.5";
2023-09-02 20:07:12 -05:00
iot = "ens19";
2023-09-05 11:06:35 -05:00
iotIP = "192.168.66.250";
routerIP = "10.42.1.2";
2024-04-20 01:15:18 -05:00
extraHosts = builtins.readFile ./net/hosts;
2023-09-05 11:06:35 -05:00
adblockUpdate = pkgs.writeShellScriptBin "adblockUpdate" (builtins.readFile ./adblockUpdate.sh);
proxyPort = 3128;
dnsPort = 53;
dhcpPort = 67;
dnsServers = [
"9.9.9.9" # Quad 9
"1.1.1.1" # Cloudflare
"1.0.0.1" # Cloudflare
"149.112.112.112" # Quad 9
];
2023-08-21 21:22:26 -05:00
in {
2023-06-29 00:27:30 -05:00
greg.tailscale.enable = true;
2023-08-21 21:22:26 -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-06-29 00:27:30 -05:00
networking = {
2023-08-18 20:46:37 -05:00
enableIPv6 = false;
2023-08-21 21:22:26 -05:00
networkmanager.enable = pkgs.lib.mkForce false;
2023-09-05 11:06:35 -05:00
defaultGateway = routerIP;
nameservers = dnsServers;
2023-06-29 00:27:30 -05:00
interfaces = {
2023-08-18 20:46:37 -05:00
# This is our LAN port
2023-08-21 21:22:26 -05:00
"${lan}" = {
2023-09-02 20:07:12 -05:00
useDHCP = false;
2023-08-21 21:22:26 -05:00
ipv4.addresses = [ {
2023-09-05 11:06:35 -05:00
address = "${lanIP}";
2023-08-21 21:22:26 -05:00
prefixLength = 16;
} ];
};
2023-06-29 00:27:30 -05:00
2023-08-21 21:22:26 -05:00
"${iot}" = {
useDHCP = false;
ipv4.addresses = [ {
2023-09-05 11:06:35 -05:00
address = "${iotIP}";
2023-08-21 21:22:26 -05:00
prefixLength = 24;
} ];
};
2023-06-29 00:27:30 -05:00
};
2023-09-05 11:06:35 -05:00
firewall = {
2024-03-26 00:19:47 -05:00
enable = false;
2023-09-05 11:06:35 -05:00
allowedUDPPorts = [
dhcpPort
dnsPort
1900 # Jellyfin auto-discovery
7359 # Jellyfin auto-discovery
];
allowedTCPPorts = [
dnsPort
proxyPort
2024-03-26 00:19:47 -05:00
80
2023-09-05 11:06:35 -05:00
];
};
2024-03-26 00:19:47 -05:00
nftables.enable = false;
2023-06-29 00:27:30 -05:00
};
2023-12-07 11:45:03 -06:00
environment.etc."hosts.d/local".text = extraHosts;
2023-06-29 00:27:30 -05:00
2024-03-26 00:19:47 -05:00
fileSystems = {
"/media" = {
device = "10.42.1.4:/volume1/video/";
fsType = "nfs";
options = [ "ro" ];
};
"/proxy" = {
2024-04-03 15:30:14 -05:00
device = "/dev/vdb1";
fsType = "btrfs";
2024-03-26 00:19:47 -05:00
};
2023-06-29 00:27:30 -05:00
};
2023-09-05 11:06:35 -05:00
services = {
# Video services
jellyfin = {
enable = true;
openFirewall = true;
};
#########
# Blind service proxy behind the walls of the VPN
########
_3proxy = {
enable = true;
services = [ {
type = "socks";
auth = [ "strong" ];
bindPort = proxyPort;
acl = [ {
rule = "allow";
users = [ "greg" ];
} ];
} ];
#usersFile = "/run/agenix/3proxy";
denyPrivate = false;
};
#########
# dnsmasq config
########
dnsmasq = {
enable = true;
settings = {
domain = "thehellings.lan";
dhcp-range = [
"${lan},10.42.2.1,10.42.2.255,255.255.0.0,12h"
"${iot},192.168.66.3,192.168.66.150,255.255.255.0,12h"
"vlan67@${lan},192.168.67.3,192.168.67.150,12h"
];
dhcp-option = [
"${lan},option:router,${routerIP}"
"${lan},option:dns-server,${lanIP},1.1.1.1"
"${lan},option:domain-search,thehellings.lan"
"${iot},option:router,192.168.66.1"
"${iot},option:dns-server,${iotIP}"
"vlan67@${lan},option:router,192.168.67.1"
"vlan67@${lan},option:dns-server,192.168.67.1"
];
dhcp-host = [
# Static IPs for personal work
2024-04-20 01:15:18 -05:00
"2a:5d:23:10:4e:22,10.42.0.5" # SAN Switch
2023-09-05 11:06:35 -05:00
"00:00:de:ad:be:ef,10.42.2.254"
2023-12-07 11:45:03 -06:00
"01:a8:a1:59:c7:8a:12,10.42.2.253" # BMC management interface for isaiah
2023-09-05 11:06:35 -05:00
# Static IPs for things in the IOT range
"b4:b0:24:9a:02:4a,192.168.66.5" # LD125
2024-06-17 12:08:41 -05:00
"98:da:c4:20:f3:64,192.168.66.6" # Dining room light
2023-09-05 19:38:41 -05:00
"54:af:97:c1:dc:b9,192.168.66.25" # Master bedroom Kasa switch
"f0:03:8c:b3:b0:f6,192.168.66.55" # Roomba
2024-02-20 14:49:48 -06:00
"4c:a1:61:05:cd:52,192.168.66.61" # Rainbird
2023-09-05 19:38:41 -05:00
"48:d6:d5:5d:81:21,192.168.66.65" # Google Home
"6c:29:90:3e:e2:02,192.168.66.66" # wiz
2024-06-17 12:08:41 -05:00
"28:87:ba:0e:ca:da,192.168.66.74" #
"28:87:ba:0e:c9:fd,192.168.66.75" # Master closet
"54:af:97:c2:0f:a1,192.168.66.76" # Master toilet
2023-09-05 19:38:41 -05:00
"54:af:97:83:ed:33,192.168.66.80"
2024-06-17 12:08:41 -05:00
"98:da:c4:77:80:18,192.168.66.84" # Kitchen lights
"98:da:c4:21:1b:2e,192.168.66.85" # Living Room lights
"0c:80:63:41:6e:0f,192.168.66.90" # Front porch
"0c:80:63:41:6c:5d,192.168.66.98" # House number
2023-09-05 19:38:41 -05:00
"ac:84:c6:5e:4b:28,192.168.66.100"
2024-06-17 12:08:41 -05:00
"98:da:c4:77:7f:4d,192.168.66.102" # Office lights
2023-09-05 19:38:41 -05:00
"8c:85:80:1c:f9:d1,192.168.66.104"
2024-06-17 12:08:41 -05:00
"98:da:c4:77:82:7b,192.168.66.105" # Parlor lamp
2024-04-17 23:09:20 -05:00
"0c:80:63:41:74:73,192.168.66.106" # Front hall light switch
"98:da:c4:20:ea:db,192.168.66.107" # Parlor light switch
2023-09-05 19:38:41 -05:00
"8c:49:62:aa:58:60,192.168.66.108" # Roku, HiHandsome
"92:3e:11:c7:c5:be,192.168.66.109"
"d8:0d:17:19:60:62,192.168.66.112"
"b4:b0:24:9a:12:53,192.168.66.130" # KL125
"b4:b0:24:9a:14:0e,192.168.66.131"
"e4:f0:42:61:fa:b5,192.168.66.149" # Google Home-mini
2023-09-05 11:06:35 -05:00
];
expand-hosts = true;
log-dhcp = true;
log-queries = true;
2023-12-07 11:45:03 -06:00
no-hosts = true; # Do not read /etc/hosts, which makes genesis resolve to 127.0.0.2
2023-09-05 11:06:35 -05:00
addn-hosts = "/etc/adblock_hosts";
2023-12-07 11:45:03 -06:00
hostsdir = "/etc/hosts.d/";
2023-09-05 11:06:35 -05:00
server = dnsServers;
};
};
# Update adblock list
cron = {
enable = true;
systemCronJobs = [
"* * * * * root ${adblockUpdate} 2>&1 > /var/log/adblock.log"
];
};
}; # End of services configuration
2023-06-29 00:27:30 -05:00
2023-08-18 20:46:37 -05:00
greg.proxies = {
2023-09-05 11:06:35 -05:00
"jellyfin.home".target = "http://localhost:8096/";
2023-08-18 20:46:37 -05:00
};
2023-06-29 00:27:30 -05:00
2024-04-03 08:32:31 -05:00
services = {
nginx.virtualHosts."nixcache.thehellings.lan" = {
serverName = "nixcache.thehellings.lan";
serverAliases = [ "nixcache" "nixcache.home" ];
root = "/proxy";
locations = {
"~ ^/nix-cache-info" = {
proxyPass = "https://cache.nixos.org";
2024-04-03 15:30:14 -05:00
root = "/proxy/nixpkgs/nix-cache-info/store";
2024-04-03 08:32:31 -05:00
recommendedProxySettings = false;
extraConfig = ''
error_log /var/log/nginx/proxy.log debug;
proxy_store on;
proxy_store_access user:rw group:rw all:r;
2024-04-03 15:30:14 -05:00
proxy_temp_path /proxy/nixpkgs/nix-cache-info/temp;
2024-04-03 08:32:31 -05:00
proxy_pass_request_headers on;
proxy_set_header Host "cache.nixos.org";
'';
};
"~^/nar/.+$" = {
proxyPass = "https://cache.nixos.org";
2024-04-03 15:30:14 -05:00
root = "/proxy/nixpkgs/nar/store";
2024-04-03 08:32:31 -05:00
recommendedProxySettings = false;
extraConfig = ''
proxy_store on;
proxy_store_access user:rw group:rw all:r;
2024-04-03 15:30:14 -05:00
proxy_temp_path /proxy/nixpkgs/nar/temp;
2024-04-03 08:32:31 -05:00
proxy_pass_request_headers on;
proxy_set_header Host "cache.nixos.org";
'';
};
2024-03-26 00:19:47 -05:00
};
};
};
systemd.services.nginx.serviceConfig.ReadWritePaths = [ "/proxy" ];
2023-09-05 11:06:35 -05:00
environment.systemPackages = with pkgs; [
2023-12-13 15:19:42 -06:00
bind
2023-09-05 11:06:35 -05:00
curl # Used by dnsmasq fetching
2023-12-07 11:45:03 -06:00
sqlite
2023-09-05 11:06:35 -05:00
];
2023-06-29 00:27:30 -05:00
}