2019-11-06 23:04:16 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
2019-12-09 05:57:30 +01:00
|
|
|
|
2023-12-05 10:34:31 +01:00
|
|
|
let wireguard_port = 1194;
|
2022-06-06 19:03:18 +02:00
|
|
|
|
|
|
|
in {
|
2022-12-20 15:04:11 +01:00
|
|
|
# Enable systemd-networkd
|
2022-01-05 13:54:59 +01:00
|
|
|
networking = {
|
|
|
|
hostName = "zion";
|
|
|
|
hostId = "4e74ea68";
|
2022-12-20 15:04:11 +01:00
|
|
|
useDHCP = false;
|
|
|
|
useNetworkd = true;
|
|
|
|
dhcpcd.enable = false;
|
|
|
|
};
|
2023-06-08 18:30:16 +02:00
|
|
|
systemd.network.wait-online.enable = false;
|
2022-12-20 15:04:11 +01:00
|
|
|
|
|
|
|
# Assign a static IP
|
|
|
|
systemd.network.networks."24-home" = {
|
2023-06-08 18:30:16 +02:00
|
|
|
name = "end0";
|
|
|
|
matchConfig.Name = "end0";
|
2022-12-20 15:04:11 +01:00
|
|
|
address = [ "192.168.13.2/24" ];
|
|
|
|
gateway = [ "192.168.13.1" ];
|
2023-12-05 10:32:35 +01:00
|
|
|
dns = [ "1.1.1.1" "9.9.9.9" ];
|
2022-12-20 15:04:11 +01:00
|
|
|
networkConfig.DNSSEC = "no";
|
2022-01-05 13:54:59 +01:00
|
|
|
};
|
|
|
|
|
2019-11-06 23:04:16 +01:00
|
|
|
# Dynamic DNS configuration
|
|
|
|
services.ddclient = {
|
|
|
|
enable = true;
|
|
|
|
quiet = true;
|
2023-06-23 15:24:47 +02:00
|
|
|
use = "web, web=freedns";
|
|
|
|
interval = "30min";
|
2019-11-10 17:47:46 +01:00
|
|
|
protocol = "duckdns";
|
|
|
|
domains = [ "coolneng.duckdns.org" ];
|
2022-06-06 23:12:54 +02:00
|
|
|
passwordFile = config.age.secrets.ddclient.path;
|
2023-12-05 10:34:31 +01:00
|
|
|
extraConfig = "";
|
2019-11-06 23:04:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
# Firewall configuration
|
|
|
|
networking.firewall = {
|
2019-11-11 03:29:00 +01:00
|
|
|
allowedTCPPorts = [
|
2020-11-30 02:03:58 +01:00
|
|
|
80 # HTTP
|
|
|
|
443 # HTTPS
|
|
|
|
53 # DNS
|
2021-02-03 18:38:41 +01:00
|
|
|
8448 # Matrix
|
2023-04-03 00:50:47 +02:00
|
|
|
1883 # MQTT
|
2019-11-11 03:29:00 +01:00
|
|
|
];
|
2020-02-21 12:25:43 +01:00
|
|
|
allowedUDPPorts = [
|
2022-06-06 19:03:18 +02:00
|
|
|
wireguard_port # Wireguard
|
2020-11-30 02:03:58 +01:00
|
|
|
53 # DNS
|
2020-02-21 12:25:43 +01:00
|
|
|
];
|
|
|
|
extraCommands = ''
|
2023-06-08 18:30:16 +02:00
|
|
|
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o ${
|
|
|
|
config.systemd.network.networks."24-home".name
|
|
|
|
} -j MASQUERADE
|
2020-06-09 21:53:20 +02:00
|
|
|
'';
|
2019-11-06 23:04:16 +01:00
|
|
|
};
|
2019-11-11 14:30:45 +01:00
|
|
|
|
2022-12-20 15:04:11 +01:00
|
|
|
# Wireguard setup
|
|
|
|
systemd.network.netdevs."wg0" = {
|
|
|
|
netdevConfig = {
|
|
|
|
Kind = "wireguard";
|
|
|
|
Name = "wg0";
|
|
|
|
};
|
|
|
|
wireguardConfig = {
|
|
|
|
ListenPort = wireguard_port;
|
|
|
|
PrivateKeyFile = config.age.secrets.wireguard.path;
|
|
|
|
};
|
|
|
|
wireguardPeers = [
|
|
|
|
# panacea
|
|
|
|
{
|
|
|
|
wireguardPeerConfig = {
|
|
|
|
PublicKey = "XMkTztU2Y8hw6Fu/2o4Gszij+EmNacvFMXuZyHS1n38=";
|
|
|
|
AllowedIPs = [ "10.8.0.2/32" ];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
# caravanserai
|
|
|
|
{
|
|
|
|
wireguardPeerConfig = {
|
|
|
|
PublicKey = "eeKfAgMisM3K4ZOErev05RJ9LS2NLqL4x9jyi4XhM1Q=";
|
|
|
|
AllowedIPs = [ "10.8.0.3/32" ];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2020-02-21 12:25:43 +01:00
|
|
|
};
|
|
|
|
|
2022-12-20 15:04:11 +01:00
|
|
|
systemd.network.networks."wg0" = {
|
|
|
|
matchConfig.Name = "wg0";
|
|
|
|
networkConfig = {
|
|
|
|
Address = "10.8.0.1/24";
|
|
|
|
IPForward = true;
|
|
|
|
IPMasquerade = "ipv4";
|
2020-02-21 12:25:43 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-11-30 02:03:58 +01:00
|
|
|
# DNS server with ad-block
|
|
|
|
services.dnsmasq = {
|
|
|
|
enable = true;
|
2023-06-08 18:30:16 +02:00
|
|
|
settings = {
|
|
|
|
domain-needed = true;
|
|
|
|
bogus-priv = true;
|
|
|
|
no-resolv = true;
|
2020-11-30 02:03:58 +01:00
|
|
|
|
2023-06-08 18:30:16 +02:00
|
|
|
listen-address = [ "127.0.0.1" "192.168.13.2" "10.8.0.1" ];
|
|
|
|
bind-interfaces = true;
|
2023-07-27 01:14:36 +02:00
|
|
|
server = [ "127.0.0.1#43" ];
|
2020-11-30 02:03:58 +01:00
|
|
|
|
2023-06-08 18:30:16 +02:00
|
|
|
cache-size = 10000;
|
|
|
|
local-ttl = 300;
|
2020-11-30 02:03:58 +01:00
|
|
|
|
2023-08-16 03:21:25 +02:00
|
|
|
conf-file = "${pkgs.dnsmasq}/share/dnsmasq/trust-anchors.conf";
|
2023-12-12 14:56:24 +01:00
|
|
|
dnssec = false;
|
2020-12-01 11:03:01 +01:00
|
|
|
|
2023-06-08 18:30:16 +02:00
|
|
|
address = "/coolneng.duckdns.org/192.168.13.2";
|
|
|
|
};
|
2020-11-30 02:03:58 +01:00
|
|
|
};
|
|
|
|
|
2023-07-27 01:14:36 +02:00
|
|
|
# Encrypted DNS
|
|
|
|
services.dnscrypt-proxy2 = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
ipv6_servers = false;
|
|
|
|
require_dnssec = true;
|
|
|
|
listen_addresses = [ "127.0.0.1:43" ];
|
|
|
|
sources.public-resolvers = {
|
|
|
|
urls = [
|
|
|
|
"https://download.dnscrypt.info/resolvers-list/v3/public-resolvers.md"
|
|
|
|
];
|
|
|
|
cache_file = "/var/lib/dnscrypt-proxy2/public-resolvers.md";
|
|
|
|
minisign_key =
|
|
|
|
"RWQf6LRCGA9i53mlYecO4IzT51TGPpvWucNSCh1CBM0QTaLn73Y7GFO3";
|
|
|
|
};
|
2023-12-12 14:56:24 +01:00
|
|
|
blocked_names.blocked_names_file =
|
|
|
|
"/var/lib/dnscrypt-proxy/blocklist.txt";
|
2023-07-27 01:14:36 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-11-06 23:04:16 +01:00
|
|
|
}
|