82 lines
2.1 KiB
Nix
82 lines
2.1 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}: let
|
|
inherit (lib.modules) mkIf;
|
|
inherit (lib.options) mkEnableOption;
|
|
|
|
cfg = config.modules.system.services.grafana;
|
|
domain = "info.copeberg.org";
|
|
port = 4021;
|
|
in {
|
|
options.modules.system.services.grafana.enable = mkEnableOption "Grafana, a graphing service";
|
|
|
|
config = mkIf cfg.enable {
|
|
networking.firewall.allowedTCPPorts = [config.services.grafana.settings.server.http_port];
|
|
|
|
modules.system.services.database.postgresql.enable = true;
|
|
|
|
services.grafana = {
|
|
enable = true;
|
|
package = pkgs.grafana;
|
|
|
|
settings = {
|
|
server = {
|
|
http_addr = "127.0.0.1";
|
|
http_port = port;
|
|
|
|
root_url = "https://${domain}";
|
|
domain = domain;
|
|
enforce_domain = true;
|
|
};
|
|
database = {
|
|
type = "postgres";
|
|
host = "/run/postgresql";
|
|
name = "grafana";
|
|
user = "grafana";
|
|
ssl_mode = "disable";
|
|
};
|
|
|
|
analytics = {
|
|
reporting_enabled = false;
|
|
check_for_updates = false;
|
|
};
|
|
|
|
users.allow_signup = false;
|
|
};
|
|
provision = {
|
|
enable = true;
|
|
datasources.settings = {
|
|
datasources = [
|
|
(mkIf config.modules.system.services.prometheus.enable {
|
|
name = "Prometheus";
|
|
type = "prometheus";
|
|
access = "proxy";
|
|
url = "http://127.0.0.1:${toString config.services.prometheus.port}";
|
|
isDefault = true;
|
|
})
|
|
|
|
(mkIf config.modules.system.services.database.postgresql.enable {
|
|
name = "PostgreSQL";
|
|
type = "postgres";
|
|
access = "proxy";
|
|
url = "http://127.0.0.1:${toString config.services.prometheus.exporters.postgres.port}";
|
|
})
|
|
];
|
|
};
|
|
};
|
|
};
|
|
services.nginx = {
|
|
enable = true;
|
|
virtualHosts.${domain} = {
|
|
addSSL = true;
|
|
enableACME = true;
|
|
locations."/" = {
|
|
proxyPass = "http://localhost:${toString port}";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}
|