zion/modules/networking.nix

85 lines
1.6 KiB
Nix
Raw Normal View History

2019-11-06 23:04:16 +01:00
{ config, pkgs, lib, ... }:
let password = builtins.readFile /var/lib/ddclient/token;
in
2019-11-06 23:04:16 +01:00
{
2020-01-29 00:20:52 +01:00
environment.systemPackages = with pkgs; [
wireguard
wireguard-tools
];
2020-01-28 21:57:53 +01:00
# Enable zeroconf
services.avahi = {
enable = true;
nssmdns = true;
publish = {
enable = true;
userServices = true;
};
};
2019-11-06 23:04:16 +01:00
# Dynamic DNS configuration
services.ddclient = {
enable = true;
quiet = true;
2019-11-10 17:47:46 +01:00
protocol = "duckdns";
domains = [ "coolneng.duckdns.org" ];
inherit password;
2019-11-06 23:04:16 +01:00
};
# Firewall configuration
networking.firewall = {
allowedTCPPorts = [
631 # Cups
6566 # SANE
80
443
];
2020-01-29 14:30:31 +01:00
allowedUDPPorts = [
51820 # Wireguard
];
2019-11-06 23:04:16 +01:00
autoLoadConntrackHelpers = true;
connectionTrackingModules = [ "sane" ];
2020-01-29 14:30:31 +01:00
extraCommands = ''
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
'';
2019-11-06 23:04:16 +01:00
};
2019-11-11 14:30:45 +01:00
2019-12-09 10:04:41 +01:00
# Disable IPv6
networking.enableIPv6 = false;
2020-01-29 14:30:31 +01:00
# Enable NAT for wireguard
networking.nat = {
enable = true;
externalInterface = "eth0";
internalInterfaces = [ "wg0" ];
};
# Wireguard setup
networking.wireguard.interfaces = {
wg0 = {
ips = [ "10.8.0.1/24" ];
listenPort = 51820;
privateKeyFile = "/home/coolneng/.wg/keys/privatekey";
peers = [
# Monolith
{
publicKey = "ka9a/VB49XMtrMw/ZJmZHThfk2Y5D/8wErLPtN+KvHE=";
allowedIPs = [ "10.8.0.2/32" ];
}
# Roamer
#{
#publicKey = "{john doe's public key}";
#allowedIPs = [ "10.8.0.3/32" ];
#}
];
};
};
2019-11-06 23:04:16 +01:00
}