diff --git a/flake.nix b/flake.nix index 827b6d0..6159bc2 100755 --- a/flake.nix +++ b/flake.nix @@ -83,6 +83,7 @@ ./modules/hedgedoc.nix ./modules/padlist.nix ./modules/nextcloud.nix + ./modules/monitoring.nix ./modules/vaultwarden.nix ./modules/forgejo ./modules/kanboard.nix diff --git a/modules/monitoring.nix b/modules/monitoring.nix index d3cdb3e..ff8dc58 100644 --- a/modules/monitoring.nix +++ b/modules/monitoring.nix @@ -1,23 +1,51 @@ { config, pkgs, ... }: - let - domain = "monitoring.${config.networking.domain}"; - in { - # grafana configuration - services.grafana = { - enable = true; - port = 2342; - }; - - services.prometheus = { - enable = true; - port = 9001; +let + domain = "monitoring.${config.networking.domain}"; +in +{ + # grafana configuration + services.grafana = { + enable = true; + settings = { + server = { + inherit domain; + http_addr = "127.0.0.1"; + http_port = 2342; + }; + database = { + type = "postgres"; + user = "grafana"; + host = "/run/postgresql"; + }; + }; - # nginx reverse proxy - services.nginx.virtualHosts.${domain} = { - locations."/" = { - proxyPass = "http://localhost:${toString config.services.grafana.port}"; - proxyWebsockets = true; - }; + + }; + + services.postgresql = { + enable = true; + ensureUsers = [ + { + name = "grafana"; + ensurePermissions = { + "DATABASE grafana" = "ALL PRIVILEGES"; + }; + } + ]; + ensureDatabases = [ "grafana" ]; + }; + + services.prometheus = { + enable = true; + port = 9001; + }; + + # nginx reverse proxy + services.nginx.virtualHosts.${domain} = { + locations."/" = { + proxyPass = "http://localhost:${toString config.services.grafana.port}"; + proxyWebsockets = true; }; + }; }