{ pkgs, lib, config, nodes, ... }: with lib; { services.grafana = { enable = true; settings.server = { addr = "127.0.0.1"; inherit (config.networking) domain; root_url = "%(protocol)s://%(domain)s:%(http_port)s/grafana/"; serve_from_sub_path = true; }; # provision = { # enable = true; # datasources.path = ./grafana/datasources.yaml # }; }; services.prometheus = { enable = true; webExternalUrl = "http://${config.networking.domain}/prometheus"; scrapeConfigs = mapAttrsToList (name: node: { job_name = name; static_configs = [ { targets = [ "${name}:${toString node.config.services.prometheus.exporters.node.port}" ]; } ]; }) nodes; }; services.nginx.virtualHosts.${config.networking.domain} = { locations."/grafana" = { proxyPass = "http://127.0.0.1:${toString config.services.grafana.settings.server.http_port}"; proxyWebsockets = true; }; locations."/prometheus" = { proxyPass = "http://127.0.0.1:${toString config.services.prometheus.port}"; proxyWebsockets = true; }; }; }