Add LibreNMS service

This commit is contained in:
pazpi 2026-01-19 12:35:13 +01:00
parent f20c086d6f
commit c0f26a47f2
10 changed files with 151 additions and 0 deletions

View file

@ -1,6 +1,7 @@
{
imports = [
./grafana.nix
./librenms.nix
./loki.nix
./prometheus.nix
./uptime-kuma.nix

View file

@ -0,0 +1,89 @@
{
lib,
config,
pkgs,
...
}:
let
cfg = config.my.monitoring.librenms;
in
{
options.my.monitoring.librenms = {
enable = lib.mkEnableOption "Enable LibreNMS module";
hostname = lib.mkOption {
default = "librenms.home";
type = lib.types.str;
description = ''
The hostname for LibreNMS
'';
};
settings = lib.mkOption {
type = lib.types.submodule {
freeformType = (pkgs.formats.json { }).type;
};
default = { };
description = ''
LibreNMS configuration settings (maps to config.php)
'';
};
proxy = {
enable = lib.mkEnableOption "Set the proxy entry for this service";
domain = lib.mkOption {
default = "example.com";
type = lib.types.str;
description = ''
The domain where Caddy is reachable
'';
};
subdomain = lib.mkOption {
default = "librenms";
type = lib.types.str;
description = ''
The subdomain where LibreNMS is reachable
'';
};
host = lib.mkOption {
default = "localhost";
type = lib.types.str;
description = ''
Host name where the service is running
'';
};
};
};
config = lib.mkMerge [
(lib.mkIf cfg.enable {
services.librenms = {
enable = true;
hostname = cfg.hostname;
database = {
createLocally = true;
socket = "/run/mysqld/mysqld.sock";
};
settings = cfg.settings;
};
networking.firewall.allowedTCPPorts = [ 80 ];
})
(lib.mkIf cfg.proxy.enable {
services.caddy = with cfg.proxy; {
virtualHosts."${subdomain}.${domain}".extraConfig = ''
reverse_proxy http://${host}:80
import cloudflare_${domain}
'';
};
})
];
}

View file

@ -9,6 +9,8 @@ in
config = lib.mkIf cfg.enable {
age.secrets.snmpd-config.file = ../../secrets/snmpd-config.age;
# Enable SSH
services.openssh = {
enable = true;
@ -30,6 +32,13 @@ in
};
};
# SNMP
services.snmpd = {
enable = true;
openFirewall = true;
configFile = config.age.secrets.snmpd-config.path;
};
networking.nameservers = [ "192.168.1.2" ];
};