{ 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} ''; }; }) ]; }