1
Fork 0
mirror of https://github.com/RGBCube/ncc synced 2025-07-29 19:17:45 +00:00

Use postgresql instead of sqlite for grafana

This commit is contained in:
RGBCube 2024-01-13 09:36:18 +03:00
parent f4279be9bc
commit 92e8a6630b
No known key found for this signature in database
2 changed files with 51 additions and 5 deletions

View file

@ -1,4 +1,4 @@
{ config, ulib, ... }: with ulib;
{ config, pkgs, ulib, ... }: with ulib;
let
inherit (config.networking) domain;
@ -10,18 +10,31 @@ in serverSystemConfiguration {
group = "grafana";
};
services.postgresql = {
ensureDatabases = [ "grafana" ];
initialScript = pkgs.writeText "postgresql-initial-script" ''
CREATE ROLE grafana WITH LOGIN PASSWORD NULL CREATEDB;
GRANT ALL PRIVILEGES ON DATABASE grafana TO grafana;
'';
};
services.grafana = enabled {
domain = fqdn;
port = 8999;
settings = {
database.host = "/run/postgresql";
database.type = "postgres";
database.user = "grafana";
server.http_addr = "::";
users.default_theme = "system";
};
settings.security = {
admin_email = "metrics@${domain}";
admin_password = "$__file{${config.age.secrets."cube.mail.password".path}}";
};
settings.server.http_addr = "::";
settings.users.default_theme = "system";
};
services.nginx.virtualHosts.${fqdn} = {

33
hosts/cube/postgresql.nix Normal file
View file

@ -0,0 +1,33 @@
{ config, lib, ulib, ... }: with ulib;
serverSystemConfiguration {
services.prometheus.exporters.postgres = enabled {
port = 9030;
runAsLocalSuperUser = true;
};
services.prometheus.scrapeConfigs = [{
job_name = "postgres";
static_configs = [{
labels.job = "postgres";
targets = [ "[::]:${toString config.services.prometheus.exporters.postgres.port}" ];
}];
}];
services.postgresql = enabled {
enableTCPIP = true;
authentication = lib.mkOverride 10 ''
# Type Database DBUser Authentication IdentMap
local sameuser all peer map=superuser_map
'';
identMap = ''
# Map System DBUser
superuser_map root postgres
superuser_map postgres postgres
superuser_map /^(.*)$ \1
'';
};
}