chore: netbird module optimized

This commit is contained in:
2026-03-09 08:21:51 +01:00
parent f5ea46001e
commit e832ba3742
5 changed files with 34 additions and 22 deletions

View File

@@ -9,7 +9,7 @@
in { in {
virtualisation.oci-containers.containers.${serviceName} = { virtualisation.oci-containers.containers.${serviceName} = {
#image = "ghcr.io/berriai/litellm:v1.78.5-stable"; #image = "ghcr.io/berriai/litellm:v1.78.5-stable";
image = "docker.litellm.ai/berriai/litellm:v1.81.12-stable"; image = "docker.litellm.ai/berriai/litellm:v1.81.14-stable.gpt-5.4_patch";
ports = ["127.0.0.1:${toString servicePort}:4000"]; ports = ["127.0.0.1:${toString servicePort}:4000"];
environmentFiles = [config.age.secrets.litellm-env.path]; environmentFiles = [config.age.secrets.litellm-env.path];
environment = { environment = {

View File

@@ -15,12 +15,18 @@
ipBase = "10.89.0"; ipBase = "10.89.0";
ipOffset = 50; ipOffset = 50;
# Derived IPs
gatewayIp = "${ipBase}.1";
dashboardIp = "${ipBase}.${toString ipOffset}";
serverIp = "${ipBase}.${toString (ipOffset + 1)}";
proxyIp = "${ipBase}.${toString (ipOffset + 2)}";
# Database configuration # Database configuration
dbName = "netbird"; dbName = "netbird";
dbUser = "netbird"; dbUser = "netbird";
dbHost = "${ipBase}.1"; dbHost = gatewayIp;
# NetBird config als Nix attribute set # NetBird config as Nix attribute set
netbirdConfig = { netbirdConfig = {
server = { server = {
listenAddress = ":80"; listenAddress = ":80";
@@ -44,7 +50,7 @@
}; };
reverseProxy = { reverseProxy = {
trustedHTTPProxies = ["${ipBase}.1/32"]; trustedHTTPProxies = ["${gatewayIp}/32"];
}; };
# Proxy Feature # Proxy Feature
@@ -65,11 +71,11 @@
}; };
}; };
# YAML generieren # Generate YAML config
yamlFormat = pkgs.formats.yaml {}; yamlFormat = pkgs.formats.yaml {};
configYamlBase = yamlFormat.generate "netbird-config-base.yaml" netbirdConfig; configYamlBase = yamlFormat.generate "netbird-config-base.yaml" netbirdConfig;
# Script das Secrets zur Runtime injiziert # Script to inject secrets at runtime
configGenScript = pkgs.writeShellScript "netbird-gen-config" '' configGenScript = pkgs.writeShellScript "netbird-gen-config" ''
set -euo pipefail set -euo pipefail
@@ -91,7 +97,7 @@ in {
age.secrets."${serviceName}-server-env".file = ../../../../secrets/${serviceName}-server-env.age; age.secrets."${serviceName}-server-env".file = ../../../../secrets/${serviceName}-server-env.age;
age.secrets."${serviceName}-proxy-env".file = ../../../../secrets/${serviceName}-proxy-env.age; age.secrets."${serviceName}-proxy-env".file = ../../../../secrets/${serviceName}-proxy-env.age;
# Systemd oneshot Service der die Config generiert # Systemd oneshot service to generate config with secrets
systemd.services."${serviceName}-config" = { systemd.services."${serviceName}-config" = {
description = "Generate NetBird config with secrets"; description = "Generate NetBird config with secrets";
wantedBy = ["multi-user.target"]; wantedBy = ["multi-user.target"];
@@ -117,9 +123,10 @@ in {
"${serviceName}-dashboard" = { "${serviceName}-dashboard" = {
image = "netbirdio/dashboard:latest"; image = "netbirdio/dashboard:latest";
autoStart = true; autoStart = true;
ports = ["127.0.0.1:${toString servicePort}:80"];
environmentFiles = [config.age.secrets."${serviceName}-dashboard-env".path]; environmentFiles = [config.age.secrets."${serviceName}-dashboard-env".path];
extraOptions = [ extraOptions = [
"--ip=${ipBase}.${toString ipOffset}" "--ip=${dashboardIp}"
"--network=web" "--network=web"
]; ];
}; };
@@ -135,7 +142,7 @@ in {
]; ];
cmd = ["--config" "/etc/netbird/config.yaml"]; cmd = ["--config" "/etc/netbird/config.yaml"];
extraOptions = [ extraOptions = [
"--ip=${ipBase}.${toString (ipOffset + 1)}" "--ip=${serverIp}"
"--network=web" "--network=web"
]; ];
}; };
@@ -149,35 +156,35 @@ in {
]; ];
environmentFiles = [config.age.secrets."${serviceName}-proxy-env".path]; environmentFiles = [config.age.secrets."${serviceName}-proxy-env".path];
cmd = [ cmd = [
"--domain=p.az-gruppe.com" "--domain=${proxyDomain}"
"--mgmt=https://${domain}:443" "--mgmt=https://${domain}:443"
"--addr=:8443" "--addr=:8443"
"--cert-dir=/certs" "--cert-dir=/certs"
"--acme-certs" "--acme-certs"
"--trusted-proxies=${ipBase}.1/32" "--trusted-proxies=${gatewayIp}/32"
]; ];
dependsOn = ["${serviceName}-server"]; dependsOn = ["${serviceName}-server"];
extraOptions = [ extraOptions = [
"--ip=${ipBase}.${toString (ipOffset + 2)}" "--ip=${proxyIp}"
"--network=web" "--network=web"
]; ];
}; };
}; };
services.traefik.dynamicConfigOptions = { services.traefik.dynamicConfigOptions = {
# HTTP Services und Routers # HTTP services and routers
http = { http = {
services = { services = {
"${serviceName}-dashboard".loadBalancer.servers = [ "${serviceName}-dashboard".loadBalancer.servers = [
{url = "http://${ipBase}.${toString ipOffset}:80/";} {url = "http://localhost:${toString servicePort}/";}
]; ];
"${serviceName}-server".loadBalancer.servers = [ "${serviceName}-server".loadBalancer.servers = [
{url = "http://${ipBase}.${toString (ipOffset + 1)}:80/";} {url = "http://${serverIp}:80/";}
]; ];
"${serviceName}-server-h2c".loadBalancer.servers = [ "${serviceName}-server-h2c".loadBalancer.servers = [
{url = "h2c://${ipBase}.${toString (ipOffset + 1)}:80";} {url = "h2c://${serverIp}:80";}
]; ];
}; };
@@ -199,7 +206,7 @@ in {
priority = 100; priority = 100;
}; };
# Dashboard (catch-all, niedrigste Priorität) # Dashboard (catch-all, lowest priority)
"${serviceName}-dashboard" = { "${serviceName}-dashboard" = {
rule = "Host(`${domain}`)"; rule = "Host(`${domain}`)";
entrypoints = "websecure"; entrypoints = "websecure";
@@ -210,10 +217,10 @@ in {
}; };
}; };
# TCP für Proxy TLS Passthrough # TCP for proxy TLS passthrough
tcp = { tcp = {
services."${serviceName}-proxy-tls".loadBalancer.servers = [ services."${serviceName}-proxy-tls".loadBalancer.servers = [
{address = "${ipBase}.${toString (ipOffset + 2)}:8443";} {address = "${proxyIp}:8443";}
]; ];
routers."${serviceName}-proxy-passthrough" = { routers."${serviceName}-proxy-passthrough" = {
@@ -225,7 +232,7 @@ in {
}; };
}; };
# ServersTransport für Proxy Protocol v2 (optional) # ServersTransport for proxy protocol v2 (optional)
serversTransports."pp-v2" = { serversTransports."pp-v2" = {
proxyProtocol.version = 2; proxyProtocol.version = 2;
}; };
@@ -233,6 +240,6 @@ in {
networking.firewall.allowedUDPPorts = [ networking.firewall.allowedUDPPorts = [
3478 # STUN 3478 # STUN
51820 # WireGuard für Proxy 51820 # WireGuard for proxy
]; ];
} }

View File

@@ -3,6 +3,7 @@
./containers ./containers
./n8n.nix ./n8n.nix
./netbird.nix
./pgadmin.nix ./pgadmin.nix
./postgres.nix ./postgres.nix
./traefik.nix ./traefik.nix

View File

@@ -1,5 +1,8 @@
{pkgs, ...}: { {pkgs, ...}: {
services.netbird.enable = true; services.netbird = {
enable = true;
package = pkgs.unstable.netbird;
};
systemd.services.netbird = { systemd.services.netbird = {
environment = { environment = {

View File

@@ -16,6 +16,7 @@
ntfy-sh = 3033; ntfy-sh = 3033;
it-tools = 3035; it-tools = 3035;
zammad-hr = 3036; zammad-hr = 3036;
netbird = 3038;
zammad-hr-elasticsearch = 3037; zammad-hr-elasticsearch = 3037;
# Docker services (3100-3199 range) # Docker services (3100-3199 range)