2024-01-06 01:19:35 +01:00
|
|
|
# SPDX-FileCopyrightText: 2021-2023 Simon Bruder <simon@sbruder.de>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2021-02-24 20:55:21 +01:00
|
|
|
{ config, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.grafana;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
services.grafana = {
|
|
|
|
enable = true;
|
2022-12-10 15:15:43 +01:00
|
|
|
settings = {
|
|
|
|
server = {
|
|
|
|
# grafana supports sockets, but no permission management (always 660 grafana:grafana)
|
|
|
|
http_addr = "127.0.0.1";
|
|
|
|
http_port = 3002;
|
|
|
|
domain = "grafana.sbruder.de";
|
|
|
|
rootUrl = "https://%(domain)s/";
|
|
|
|
};
|
|
|
|
database = {
|
|
|
|
type = "postgres";
|
|
|
|
host = "/run/postgresql";
|
|
|
|
user = "grafana";
|
|
|
|
};
|
|
|
|
analytics = {
|
|
|
|
reporting_enabled = false;
|
|
|
|
check_for_updates = false;
|
|
|
|
check_for_plugin_updates = false;
|
|
|
|
};
|
2021-02-24 20:55:21 +01:00
|
|
|
};
|
|
|
|
provision = {
|
|
|
|
enable = true;
|
2022-12-10 15:15:43 +01:00
|
|
|
datasources.settings.datasources = [
|
2021-02-24 20:55:21 +01:00
|
|
|
{
|
|
|
|
name = "Prometheus";
|
|
|
|
type = "prometheus";
|
|
|
|
url = "http://${config.services.prometheus.listenAddress}:${toString config.services.prometheus.port}";
|
|
|
|
isDefault = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.grafana.after = [ "postgresql.service" ];
|
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
2022-12-10 15:15:43 +01:00
|
|
|
ensureDatabases = [ cfg.settings.database.name ];
|
2021-02-24 20:55:21 +01:00
|
|
|
ensureUsers = [
|
|
|
|
{
|
2022-12-10 15:15:43 +01:00
|
|
|
name = cfg.settings.database.user;
|
2023-12-02 18:54:23 +01:00
|
|
|
ensureDBOwnership = true;
|
2021-02-24 20:55:21 +01:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
services.nginx.virtualHosts."grafana.sbruder.de" = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
|
|
|
|
locations = {
|
2022-12-10 15:15:43 +01:00
|
|
|
"/".proxyPass = "http://${cfg.settings.server.http_addr}:${toString cfg.settings.server.http_port}";
|
2021-02-24 20:55:21 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|