2022-04-14 11:48:26 +00:00
{ config , pkgs , . . . }:
{
systemd . services . wireguard-wg0 . serviceConfig . Restart = " o n - f a i l u r e " ;
systemd . services . wireguard-wg0 . serviceConfig . RestartSec = " 5 s " ;
systemd . services . wireguard-wg1 . serviceConfig . Restart = " o n - f a i l u r e " ;
systemd . services . wireguard-wg1 . serviceConfig . RestartSec = " 5 s " ;
# Enable WireGuard
networking . wireguard . interfaces = {
# "wg0" is the network interface name. You can name the interface arbitrarily.
wg0 = {
# Determines the IP address and subnet of the client's end of the tunnel interface.
ips = [
" 1 0 . 0 . 0 . 1 3 / 3 2 "
" f c 0 0 : 2 0 0 : : 1 3 / 1 2 8 "
] ;
listenPort = 51820 ; # to match firewall allowedUDPPorts (without this wg uses random port numbers)
# Path to the private key file.
#
# Note: The private key can also be included inline via the privateKey option,
# but this makes the private key world-readable; thus, using privateKeyFile is
# recommended.
privateKeyFile = " / h o m e / h e n s o k o / . c o n f i g / w i r e g u a r d / h o s t i n g - d e . p r i v a t e " ;
peers = [
# For a client configuration, one peer entry for the server will suffice.
{
# Public key of the server (not a file path).
publicKey = " 0 2 / M R P d u M G x 1 a s 7 y S 4 G 7 G p L 4 + p Q j s j p y S / t D 9 i P u 8 X 0 = " ;
# Forward all the traffic via VPN.
allowedIPs = [
" 1 0 . 0 . 0 . 0 / 2 4 "
" 1 9 2 . 1 6 8 . 5 0 . 0 / 2 4 "
" 1 9 2 . 1 6 8 . 2 0 0 . 0 / 2 4 "
" 1 0 . 2 0 . 3 0 . 0 / 2 4 "
" f c 0 0 : 2 0 0 : : / 1 2 0 "
" 9 5 . 1 2 9 . 5 1 . 5 "
" 9 5 . 1 2 9 . 5 4 . 4 3 "
" 1 3 4 . 0 . 2 8 . 8 9 "
] ;
# Set this to the server IP and port.
2022-05-06 16:39:45 +00:00
endpoint = " 1 3 4 . 0 . 3 0 . 1 5 4 : 5 1 8 2 0 " ; # ToDo: route to endpoint not automatically configured https://wiki.archlinux.org/index.php/WireGuard#Loop_routing https://discourse.nixos.org/t/solved-minimal-firewall-setup-for-wireguard-client/7577
2022-04-14 11:48:26 +00:00
# Send keepalives every 25 seconds. Important to keep NAT tables alive.
persistentKeepalive = 25 ;
}
] ;
} ;
wg1 = {
# Determines the IP address and subnet of the client's end of the tunnel interface.
ips = [
" 1 0 . 7 . 0 . 2 1 "
] ;
listenPort = 51821 ; # to match firewall allowedUDPPorts (without this wg uses random port numbers)
# Path to the private key file.
#
# Note: The private key can also be included inline via the privateKey option,
# but this makes the private key world-readable; thus, using privateKeyFile is
# recommended.
privateKeyFile = " / h o m e / h e n s o k o / . c o n f i g / w i r e g u a r d / d a t a - g s s w s - d e . p r i v a t e " ;
peers = [
# For a client configuration, one peer entry for the server will suffice.
{
# Public key of the server (not a file path).
publicKey = " R w M o c d h a 7 f y x + M G T t Q p Z h Z Q G J Y 4 W U 7 9 Y g p s p Y B c l K 3 c = " ;
# Forward all the traffic via VPN.
allowedIPs = [
" 1 0 . 7 . 0 . 0 / 2 4 "
] ;
# Set this to the server IP and port.
2022-05-06 16:39:45 +00:00
endpoint = " 8 0 . 2 4 4 . 2 4 2 . 2 : 5 1 8 2 0 " ; # ToDo: route to endpoint not automatically configured https://wiki.archlinux.org/index.php/WireGuard#Loop_routing https://discourse.nixos.org/t/solved-minimal-firewall-setup-for-wireguard-client/7577
2022-04-14 11:48:26 +00:00
# Send keepalives every 25 seconds. Important to keep NAT tables alive.
persistentKeepalive = 25 ;
}
] ;
} ;
} ;
}