62 lines
2 KiB
Nix
62 lines
2 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
let
|
|
cfg = config.birdsong.peer;
|
|
in
|
|
{
|
|
options.birdsong.peer = {
|
|
enable = mkEnableOption "WireGuard peering with the birdsong network";
|
|
interface = mkOption {
|
|
default = "birdsong";
|
|
description = "The name of the network interface to use for WireGuard.";
|
|
type = types.str;
|
|
};
|
|
openPorts = mkOption {
|
|
default = true;
|
|
description = "Whether to automatically open firewall ports.";
|
|
type = types.bool;
|
|
};
|
|
privateKeyFile = mkOption {
|
|
description = "Path to the private key for this peer, as generated by `wg genkey`.";
|
|
type = types.path;
|
|
};
|
|
listenPort = mkOption {
|
|
default = 51820;
|
|
example = 51821;
|
|
description = "Which port to expose WireGuard on. Change this if you are behind NAT, to a port not used by another peer in the same LAN.";
|
|
type = types.port;
|
|
};
|
|
persistentKeepalive = mkOption {
|
|
default = null;
|
|
example = 23;
|
|
description = "Constantly ping the hub this often, in seconds, in order to keep the WireGuard tunnel open. Set this if you are behind NAT to keep the NAT session active. To avoid syncing, this should ideally be a prime number that is not shared by another peer in the same LAN.";
|
|
type = types.nullOr types.int;
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
assertions = [{
|
|
assertion = cfg.privateKeyFile != null;
|
|
message = "birdsong.peer.privateKeyFile must be set";
|
|
}];
|
|
|
|
networking = {
|
|
firewall.allowedUDPPorts = mkIf cfg.openPorts [ cfg.listenPort ];
|
|
|
|
wireguard.interfaces.${cfg.interface} = {
|
|
listenPort = cfg.listenPort;
|
|
privateKeyFile = cfg.privateKeyFile;
|
|
peers = [
|
|
{
|
|
publicKey = "birdLVh8roeZpcVo308Ums4l/aibhAxbi7MBsglkJyA=";
|
|
allowedIPs = [ "10.127.1.0/24" "fd70:81ca:0f8f:1::/64" ];
|
|
endpoint = "birdsong.network:51820";
|
|
persistentKeepalive = cfg.persistentKeepalive;
|
|
}
|
|
];
|
|
};
|
|
};
|
|
};
|
|
}
|