nix-config/config/services/netbird.nix

125 lines
3.2 KiB
Nix
Raw Permalink Normal View History

2024-04-24 01:00:57 +02:00
{
2024-12-20 20:40:27 +01:00
config,
lib,
globals,
...
}:
{
wireguard.services = {
client.via = "nucnix";
firewallRuleForNode.nucnix-nginx.allowedTCPPorts = [
2024-11-03 21:32:46 +01:00
80 # dashboard
3000 # management
8012 # signal
33080 # relay
2024-07-26 22:12:48 +02:00
];
2024-03-21 20:39:59 +01:00
};
2024-11-25 16:44:35 +01:00
networking.nftables.chains.forward.from-netbird = {
after = [ "conntrack" ];
rules = [
2025-01-03 00:31:36 +01:00
"iifname nb-main oifname { lan-home, lan-services } accept"
2024-11-25 16:44:35 +01:00
];
};
2024-03-21 20:39:59 +01:00
2024-04-24 01:00:57 +02:00
age.secrets.coturnPassword = {
generator.script = "alnum";
2024-07-20 19:44:14 +02:00
owner = "turnserver";
2024-04-24 01:00:57 +02:00
};
age.secrets.coturnSecret = {
generator.script = "alnum";
2024-04-24 15:50:56 +02:00
owner = "turnserver";
2024-04-24 01:00:57 +02:00
};
2024-11-16 11:21:01 +01:00
age.secrets.relaySecret = {
generator.script = "alnum";
owner = "turnserver";
};
2024-04-24 01:00:57 +02:00
age.secrets.dataEnc = {
2024-07-26 22:12:48 +02:00
generator.script =
{ pkgs, ... }:
''
${lib.getExe pkgs.openssl} rand -base64 32
'';
2024-04-24 01:00:57 +02:00
group = "netbird";
};
2024-11-25 16:44:35 +01:00
networking.firewall.allowedUDPPorts = [
3478
]; # STUN/TURN server
2024-04-24 01:00:57 +02:00
services.netbird = {
2024-11-21 18:10:33 +01:00
clients.main = {
port = 51820;
environment = {
2024-12-20 20:40:27 +01:00
NB_MANAGEMENT_URL = "https://${globals.services.netbird.domain}";
NB_ADMIN_URL = "https://${globals.services.netbird.domain}";
2024-11-21 18:10:33 +01:00
NB_HOSTNAME = "home";
};
};
2024-11-25 16:44:35 +01:00
2024-04-24 01:00:57 +02:00
server = {
enable = true;
2024-12-20 20:40:27 +01:00
inherit (globals.services.netbird) domain;
2024-04-24 01:00:57 +02:00
dashboard = {
2024-05-25 21:12:15 +02:00
enableNginx = true;
2024-04-24 01:00:57 +02:00
settings = {
2024-12-20 20:40:27 +01:00
AUTH_AUTHORITY = "https://${globals.services.kanidm.domain}/oauth2/openid/netbird";
2024-11-18 13:44:06 +01:00
# Fix Kanidm not supporting fragmented URIs
AUTH_REDIRECT_URI = "/peers";
AUTH_SILENT_REDIRECT_URI = "/add-peers";
2024-04-24 01:00:57 +02:00
};
};
2024-11-21 18:10:33 +01:00
relay = {
authSecretFile = config.age.secrets.relaySecret.path;
2024-12-20 20:40:27 +01:00
settings.NB_EXPOSED_ADDRESS = "rels://${globals.services.netbird.domain}:443";
2024-11-21 18:10:33 +01:00
};
2024-11-16 11:21:01 +01:00
2024-04-24 01:00:57 +02:00
coturn = {
enable = true;
passwordFile = config.age.secrets.coturnPassword.path;
};
management = {
port = 3000;
2024-12-17 21:54:26 +01:00
# DNS server should do the lookup this is not used
dnsDomain = "internal.invalid";
2024-04-24 01:00:57 +02:00
singleAccountModeDomain = "netbird.patrick";
2024-12-20 20:40:27 +01:00
oidcConfigEndpoint = "https://${globals.services.kanidm.domain}/oauth2/openid/netbird/.well-known/openid-configuration";
2024-04-24 01:00:57 +02:00
settings = {
TURNConfig = {
Secret._secret = config.age.secrets.coturnSecret.path;
};
2024-12-20 20:40:27 +01:00
Signal.URI = "${globals.services.netbird.domain}:443";
2024-05-26 16:26:36 +02:00
HttpConfig = {
# This is not possible
# failed validating JWT token sent from peer y1ParZkbzVMQGeU/KMycYl75v90i2O6EwgO1YQZnSFs= with error rpc error: code = Internal desc = unable to fetch account with claims, err: user ID is empty
#AuthUserIDClaim = "preferred_username";
AuthAudience = "netbird";
};
2024-04-24 01:00:57 +02:00
DataStoreEncryptionKey._secret = config.age.secrets.dataEnc.path;
};
};
2024-03-21 20:39:59 +01:00
};
};
2024-07-20 19:44:14 +02:00
systemd.services.netbird-management.serviceConfig = {
Restart = "always";
RestartSec = 60;
};
2024-03-24 21:06:11 +01:00
environment.persistence."/persist".directories = [
{
directory = "/var/lib/netbird-mgmt";
mode = "440";
user = "netbird";
}
2024-11-21 18:10:33 +01:00
{
directory = "/var/lib/netbird-main";
mode = "440";
user = "netbird-main";
}
2024-03-24 21:06:11 +01:00
];
2024-03-21 20:39:59 +01:00
}