130 lines
2.8 KiB
Nix
130 lines
2.8 KiB
Nix
{
|
|
config,
|
|
pkgs,
|
|
lib,
|
|
...
|
|
}:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.my.monitoring.grafana;
|
|
|
|
in
|
|
{
|
|
options.my.monitoring.grafana = {
|
|
enable = lib.mkEnableOption "Enable grafana as a data visualization";
|
|
|
|
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
|
|
'';
|
|
};
|
|
|
|
host = lib.mkOption {
|
|
default = "localhost";
|
|
type = lib.types.str;
|
|
description = ''
|
|
Host name where Grafana is running
|
|
'';
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = lib.mkMerge [
|
|
(lib.mkIf cfg.enable {
|
|
|
|
age.secrets = {
|
|
grafana-admin-pwd = {
|
|
file = ../../secrets/grafana-admin-pwd.age;
|
|
owner = "grafana";
|
|
};
|
|
};
|
|
|
|
services = {
|
|
|
|
grafana = {
|
|
enable = true;
|
|
settings = {
|
|
analytics.reporting_enabled = false;
|
|
database = {
|
|
user = "grafana";
|
|
type = "postgres";
|
|
|
|
host = "/run/postgresql/";
|
|
name = "grafana";
|
|
};
|
|
security = {
|
|
admin_user = "pazpi";
|
|
admin_password = "$__file{${config.age.secrets.grafana-admin-pwd.path}}";
|
|
};
|
|
server = {
|
|
domain = "grafana.neon-dory.ts.net";
|
|
http_addr = "0.0.0.0";
|
|
http_port = 3000;
|
|
# root_url = "https://grafana.${cfg.proxy.domain}";
|
|
enable_gzip = true;
|
|
};
|
|
users = {
|
|
default_theme = "light";
|
|
allow_sign_up = false;
|
|
};
|
|
};
|
|
# XXX Just for future reference
|
|
# provision.dashboards.settings.providers = [
|
|
# {
|
|
# name = "example";
|
|
# options.path = ./dashboards/example.json;
|
|
# }
|
|
# ];
|
|
};
|
|
|
|
grafana-image-renderer = {
|
|
enable = true;
|
|
provisionGrafana = true;
|
|
chromium = pkgs.ungoogled-chromium;
|
|
};
|
|
|
|
postgresql = {
|
|
enable = true;
|
|
ensureDatabases = [ "grafana" ];
|
|
ensureUsers = [
|
|
{
|
|
name = "grafana";
|
|
ensureDBOwnership = true;
|
|
}
|
|
];
|
|
};
|
|
|
|
};
|
|
|
|
networking.firewall.allowedTCPPorts = [ 3000 ];
|
|
|
|
})
|
|
|
|
(lib.mkIf cfg.proxy.enable {
|
|
services.caddy = with cfg.proxy; {
|
|
virtualHosts."grafana.${domain}".extraConfig = ''
|
|
reverse_proxy http://${host}:3000
|
|
import cloudflare
|
|
'';
|
|
};
|
|
})
|
|
];
|
|
|
|
}
|
|
|
|
# {
|
|
# name = "Alertmanager";
|
|
# type = "alertmanager";
|
|
# url = "http://nuc:9093";
|
|
# jsonData.implementation = "prometheus";
|
|
# jsonData.handleGrafanaManagedAlerts = true;
|
|
# }
|