{ me, config, lib, ... }: let inherit (lib) mkOption mkEnableOption types; cfg = config.foundation.monitoring; ports = { victoriaDefaultPort = 8428; nodeExporterPort = 9001; cadvisorExporterPort = 9002; nginxExporterPort = 9113; nginxLogExporterPort = 9117; dockerExporterPort = 9323; }; serverConfiguration = import ./server.nix ( { hosts = cfg.server.hosts; victoriaAddress = "${me.tailscale.ip}:${toString ports.victoriaDefaultPort}"; } // ports ); clientConfiguration = import ./client.nix ( { services = cfg.services; listenAddress = me.tailscale.ip; } // ports ); in { imports = [ ../../../services/monitoring/wrapper.nix ]; options.foundation.monitoring = { server = { enable = mkEnableOption "monitoring server"; hosts = mkOption { type = with types; listOf (submodule { options = { name = mkOption { type = str; }; ip = mkOption { type = str; }; }; }); default = [ ]; }; }; client = { enable = mkEnableOption "monitoring client"; }; services = mkOption { type = with types; listOf str; default = [ ]; }; }; config = lib.mkMerge [ (lib.mkIf cfg.server.enable serverConfiguration) (lib.mkIf (cfg.client.enable || cfg.server.enable) clientConfiguration) ]; }