NixOS/system/services/telemetry/grafana.nix

64 lines
1.8 KiB
Nix
Raw Normal View History

{
config,
lib,
pkgs,
...
}:
2024-08-28 20:31:11 +07:00
let
2024-08-29 11:51:08 +07:00
cfg = config.profile.services.telemetry.grafana;
2024-08-28 20:31:11 +07:00
inherit (lib) mkIf;
grafanaDomain = "grafana.tigor.web.id";
in
{
config = mkIf cfg.enable {
sops.secrets =
let
2024-08-29 11:51:08 +07:00
opts = {
sopsFile = ../../../secrets/telemetry.yaml;
owner = "grafana";
};
2024-08-28 20:31:11 +07:00
in
2024-08-29 11:51:08 +07:00
{
2024-08-28 20:31:11 +07:00
"grafana/admin_user" = opts;
"grafana/admin_password" = opts;
"grafana/admin_email" = opts;
"grafana/secret_key" = opts;
};
2024-08-29 11:51:08 +07:00
services.caddy.virtualHosts.${grafanaDomain}.extraConfig = ''
2024-08-28 20:31:11 +07:00
reverse_proxy ${config.services.grafana.settings.server.http_addr}:${toString config.services.grafana.settings.server.http_port}
'';
2024-08-29 11:51:08 +07:00
services.grafana = {
2024-08-28 20:31:11 +07:00
enable = true;
package = pkgs.grafana;
settings = {
# https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/
server = {
protocol = "http"; # served behind caddy
http_addr = "0.0.0.0";
http_port = 44518;
root_url = "https://${grafanaDomain}";
enable_gzip = true;
};
database = {
type = "sqlite3";
cache_mode = "shared";
wal = true;
query_retries = 3;
};
security = {
# Admin credentials is already available in the secrets
admin_user = "$__file{${config.sops.secrets."grafana/admin_user".path}}";
admin_password = "$__file{${config.sops.secrets."grafana/admin_password".path}}";
admin_email = "$__file{${config.sops.secrets."grafana/admin_email".path}}";
secret_key = "$__file{${config.sops.secrets."grafana/secret_key".path}}";
cookie_secure = true;
cookie_samesite = "lax";
strict_transport_security = true;
};
};
};
};
}