2024-04-24 01:00:57 +02:00
{
2024-12-20 20:40:27 +01:00
config ,
lib ,
globals ,
. . .
} :
{
wireguard . services = {
client . via = " n u c n i x " ;
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 = [ " c o n n t r a c k " ] ;
rules = [
2025-01-03 00:31:36 +01:00
" i i f n a m e n b - m a i n o i f n a m e { l a n - h o m e , l a n - s e r v i c e s } a c c e p t "
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 = " a l n u m " ;
2024-07-20 19:44:14 +02:00
owner = " t u r n s e r v e r " ;
2024-04-24 01:00:57 +02:00
} ;
age . secrets . coturnSecret = {
generator . script = " a l n u m " ;
2024-04-24 15:50:56 +02:00
owner = " t u r n s e r v e r " ;
2024-04-24 01:00:57 +02:00
} ;
2024-11-16 11:21:01 +01:00
age . secrets . relaySecret = {
generator . script = " a l n u m " ;
owner = " t u r n s e r v e r " ;
} ;
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 = " n e t b i r d " ;
} ;
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 = " h t t p s : / / ${ globals . services . netbird . domain } " ;
NB_ADMIN_URL = " h t t p s : / / ${ globals . services . netbird . domain } " ;
2024-11-21 18:10:33 +01:00
NB_HOSTNAME = " h o m e " ;
} ;
} ;
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 = " h t t p s : / / ${ globals . services . kanidm . domain } / o a u t h 2 / o p e n i d / n e t b i r d " ;
2024-11-18 13:44:06 +01:00
# Fix Kanidm not supporting fragmented URIs
AUTH_REDIRECT_URI = " / p e e r s " ;
AUTH_SILENT_REDIRECT_URI = " / a d d - p e e r s " ;
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 = " r e l s : / / ${ globals . services . netbird . domain } : 4 4 3 " ;
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 = " i n t e r n a l . i n v a l i d " ;
2024-04-24 01:00:57 +02:00
singleAccountModeDomain = " n e t b i r d . p a t r i c k " ;
2024-12-20 20:40:27 +01:00
oidcConfigEndpoint = " h t t p s : / / ${ globals . services . kanidm . domain } / o a u t h 2 / o p e n i d / n e t b i r d / . w e l l - k n o w n / o p e n i d - c o n f i g u r a t i o n " ;
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 } : 4 4 3 " ;
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 = " n e t b i r d " ;
} ;
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 = " a l w a y s " ;
RestartSec = 60 ;
} ;
2024-03-24 21:06:11 +01:00
environment . persistence . " / p e r s i s t " . directories = [
{
directory = " / v a r / l i b / n e t b i r d - m g m t " ;
mode = " 4 4 0 " ;
user = " n e t b i r d " ;
}
2024-11-21 18:10:33 +01:00
{
directory = " / v a r / l i b / n e t b i r d - m a i n " ;
mode = " 4 4 0 " ;
user = " n e t b i r d - m a i n " ;
}
2024-03-24 21:06:11 +01:00
] ;
2024-03-21 20:39:59 +01:00
}