- extraServices.maintenance.enable + notify.url https://ping.az-gruppe.com (Q7) - Selbstanmeldung (Q3) in allen 16 Router-Modulen, 18 Einträge: traefik-routing.nix bündelt prtg/home-assistant/azdesk - Bewusst unregistriert (Policy): r.l (Traefik-Dashboard), loki-push - error-pages-Verkabelung der Router bleibt Ticket 05 (AZ-NIX-9m4)
166 lines
5.6 KiB
Nix
166 lines
5.6 KiB
Nix
{
|
|
config,
|
|
pkgs,
|
|
...
|
|
}: let
|
|
serviceName = "netbox";
|
|
servicePort = config.m3ta.ports.get serviceName;
|
|
staticPort = config.m3ta.ports.get "netbox-static";
|
|
hostName = "nb.l.az-gruppe.com";
|
|
staticRoot = "${config.services.netbox.dataDir}/static";
|
|
# nixpkgs >= 25.11: Plugin-Pakete liegen im passthru-Set netbox.plugins
|
|
# (python3Packages.netbox-* sind Throw-Stubs); pluginName = NetBox-Modulname
|
|
#
|
|
# nixpkgs-unstable liefert netbox-qrcode 0.0.21 und netbox-floorplan-plugin
|
|
# 0.9.2 — beide deklarieren max. NetBox 4.6.x und laden unter NetBox 4.7
|
|
# nicht ("requires NetBox maximum version 4.6.99"). Bis die Versionen im
|
|
# Modul-Set nachziehen, werden sie hier auf die ersten 4.7-kompatiblen
|
|
# Releases gehoben (qrcode 1.0.0 / floorplan 0.10.0, s. COMPATIBILITY.md
|
|
# der jeweiligen Repos).
|
|
netboxPlugins = with pkgs.unstable.netbox.plugins; [
|
|
netbox-dns
|
|
(netbox-qrcode.overridePythonAttrs (old: rec {
|
|
version = "1.0.0";
|
|
src = pkgs.fetchFromGitHub {
|
|
owner = "netbox-community";
|
|
repo = "netbox-qrcode";
|
|
tag = "v${version}";
|
|
hash = "sha256-4BtK1//TfcNiFgw2U+S6SH58Nb/kAmFk+a/GAhQ/+SU=";
|
|
};
|
|
# setup.py deklariert ab 1.0.0 zusaetzlich 'packaging'
|
|
dependencies =
|
|
(old.dependencies or [])
|
|
++ [
|
|
pkgs.unstable.netbox.python.pkgs.packaging
|
|
];
|
|
}))
|
|
netbox-routing
|
|
netbox-topology-views
|
|
(netbox-floorplan-plugin.overridePythonAttrs (old: rec {
|
|
version = "0.10.0";
|
|
src = pkgs.fetchFromGitHub {
|
|
owner = "netbox-community";
|
|
repo = "netbox-floorplan-plugin";
|
|
tag = "v${version}";
|
|
hash = "sha256-YVQ3sBh9FYiYiikReYruzSGdKMYrqx0tMWKcCAIrrOk=";
|
|
};
|
|
}))
|
|
];
|
|
in {
|
|
services.netbox = {
|
|
enable = true;
|
|
package = pkgs.unstable.netbox_4_7;
|
|
listenAddress = "127.0.0.1";
|
|
port = servicePort;
|
|
secretKeyFile = config.age.secrets.netbox-secret-key.path;
|
|
apiTokenPeppersFile = config.age.secrets.netbox-api-token-pepper.path;
|
|
|
|
settings = {
|
|
ALLOWED_HOSTS = [hostName "localhost" "127.0.0.1"];
|
|
SECURE_SSL_REDIRECT = true;
|
|
SESSION_COOKIE_SECURE = true;
|
|
CSRF_COOKIE_SECURE = true;
|
|
# NetBox aktiviert Plugins erst über PLUGINS in configuration.py —
|
|
# der NixOS-NetBox-Modul trägt sie NICHT automatisch ein.
|
|
PLUGINS = map (p: p.pluginName) netboxPlugins;
|
|
};
|
|
# installiert die Pakete in NetBox' Python-Environment (extraBuildInputs)
|
|
plugins = _: netboxPlugins;
|
|
extraConfig = ''
|
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
|
'';
|
|
};
|
|
|
|
# Der Upgrade-Guard im NetBox-Modul (preStart) vergleicht /var/lib/netbox/version
|
|
# nur mit dem BASISPAKET (services.netbox.package). Reine Config-/Plugin-
|
|
# Änderungen bei gleicher NetBox-Version überspringen damit migrate +
|
|
# collectstatic → Plugin-Tabellen fehlen ("database migration missing").
|
|
# Deshalb Migrationen/Statics hier VOR jedem netbox.service-Start ausführen
|
|
# (idempotent, entspricht dem offiziellen NetBox-Upgrade-Pfad):
|
|
systemd.services.netbox = {
|
|
wants = ["netbox-migrate.service"];
|
|
after = ["netbox-migrate.service"];
|
|
};
|
|
|
|
systemd.services.netbox-migrate = {
|
|
description = "NetBox: DB-Migrationen & Statics (v. a. Plugins)";
|
|
wants = ["network-online.target"];
|
|
after = ["network-online.target" "postgresql.service" "redis-netbox.service"];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
User = "netbox";
|
|
Group = "netbox";
|
|
StateDirectory = "netbox";
|
|
TimeoutStartSec = "10min";
|
|
};
|
|
script = ''
|
|
/run/current-system/sw/bin/netbox-manage migrate --no-input
|
|
/run/current-system/sw/bin/netbox-manage collectstatic --no-input
|
|
'';
|
|
};
|
|
|
|
# NetBox >= 4.7 hat den 'housekeeping'-Management-Befehl entfernt
|
|
# (netbox-community/netbox#21565): Housekeeping laeuft seit NetBox 4.4
|
|
# automatisch als interner System-Job im RQ-Worker. Der Timer aus dem
|
|
# stabilen NixOS-Modul ruft den Befehl trotzdem taeglich auf und die Unit
|
|
# failed mit "Unknown command: 'housekeeping'" → beide Units maskieren.
|
|
# Kann entfallen, sobald der Modul das selbst korrekt behandelt.
|
|
systemd.services.netbox-housekeeping.enable = false;
|
|
systemd.timers.netbox-housekeeping.enable = false;
|
|
|
|
services.nginx = {
|
|
enable = true;
|
|
virtualHosts.netbox-static = {
|
|
listen = [
|
|
{
|
|
addr = "127.0.0.1";
|
|
port = staticPort;
|
|
}
|
|
];
|
|
locations."/static/" = {
|
|
alias = "${staticRoot}/";
|
|
extraConfig = ''
|
|
expires 1h;
|
|
access_log off;
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
users.users.nginx.extraGroups = ["netbox"];
|
|
|
|
# Traefik-Routing: zwei Backends (App + Static), ein Host
|
|
services.traefik.dynamicConfigOptions.http = {
|
|
services = {
|
|
${serviceName}.loadBalancer.servers = [
|
|
{url = "http://127.0.0.1:${toString servicePort}/";}
|
|
];
|
|
"${serviceName}-static".loadBalancer.servers = [
|
|
{url = "http://127.0.0.1:${toString staticPort}/";}
|
|
];
|
|
};
|
|
|
|
routers = {
|
|
${serviceName} = {
|
|
rule = "Host(`${hostName}`) && !PathPrefix(`/static`)";
|
|
tls.certResolver = "ionos";
|
|
service = serviceName;
|
|
entrypoints = "websecure";
|
|
};
|
|
"${serviceName}-static" = {
|
|
rule = "Host(`${hostName}`) && PathPrefix(`/static`)";
|
|
tls.certResolver = "ionos";
|
|
service = "${serviceName}-static";
|
|
entrypoints = "websecure";
|
|
};
|
|
};
|
|
};
|
|
|
|
# Wartungsmodus: Selbstanmeldung des Dienstes (Q3). App- und Static-Router
|
|
# teilen sich den Host — ein Registry-Eintrag deckt beide ab.
|
|
m3ta.maintenance.services.netbox = {
|
|
domains = [hostName];
|
|
desc = "NetBox (IPAM/DCIM)";
|
|
};
|
|
}
|