2022-06-14 00:17:12 -07:00
{ config , lib , pkgs , . . . }:
with lib ;
let
cfg = config . mossnet . wg ;
in
{
options = {
mossnet . wg = {
2022-06-14 00:29:17 -07:00
enable = mkEnableOption " G a i n a c c e s s t o a l l m o s s n e t s y s t e m s t h r o u g h w i r e g u a r d " ;
2022-06-14 00:17:12 -07:00
ips = lib . mkOption {
type = with types ; listOf str ;
default = { } ;
example = literalExample ''
[ " 1 0 . 0 . 6 9 . 2 / 2 4 " ] ;
'' ;
description = ''
The IP this machine is allowed to connect to
'' ;
2022-06-14 00:29:17 -07:00
} ;
privateKeyFile = lib . mkOption {
type = types . path ;
default = { } ;
example = literalExample ''
/run/agenix/wg-curve
'' ;
description = ''
The private ssh key file to use to connect !
Remember set age . secrets . * . file and age . secrets . * . user
'' ;
2022-06-14 00:17:12 -07:00
} ;
} ;
} ;
config = mkIf cfg . enable {
networking . firewall . allowedUDPPorts = [ 60990 ] ;
networking . wireguard . interfaces = {
wg0 = {
ips = cfg . ips ;
listenPort = 60990 ; # to match firewall allowedUDPPorts (without this wg uses random port numbers)
privateKeyFile = cfg . privateKeyFile ;
peers = [
# For a client configuration, one peer entry for the server will suffice.
{
publicKey = " c 1 J 4 p 6 3 r D 3 I l s z u g M Z i k i 7 U B V 3 Y m D d q a 3 D U 4 U e j X z A I = " ;
allowedIPs = [ " 1 0 . 0 . 6 9 . 0 / 2 4 " ] ;
# Set this to the server IP and port.
endpoint = " 1 4 9 . 2 8 . 1 6 3 . 7 8 : 6 0 9 9 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
persistentKeepalive = 25 ;
}
] ;
} ;
} ;
} ;
}