{ config, lib, pkgs, ... }: let cfg = config.grafana; in { options.grafana = { port = lib.mkOption { type = lib.types.int; }; matrixForwarderPort = lib.mkOption { type = lib.types.int; }; prometheusSqlExporterPort = lib.mkOption { type = lib.types.int; }; matrixServerUrl = lib.mkOption { type = lib.types.str; }; }; imports = [ ]; config = { age.secrets.grafana-matrix-forwarder-env.file = ; services.grafana = { enable = true; settings = { server = { http_addr = "0.0.0.0"; http_port = cfg.port; }; }; provision = { enable = true; datasources.settings.datasources = [ { name = "Prometheus Tente"; type = "prometheus"; url = "http://${config.services.prometheus.listenAddress}:${toString config.services.prometheus.port}"; } { name = "Loki Tente"; type = "loki"; access = "proxy"; url = "http://127.0.0.1:${toString config.services.loki.configuration.server.http_listen_port}"; } ]; }; }; services.grafana-matrix-forwarder = { enable = true; port = cfg.matrixForwarderPort; homeserver = cfg.matrixServerUrl; environmentFile = config.age.secrets.grafana-matrix-forwarder-env.path; }; }; }