nixos/modules/services/grafana/default.nix

100 lines
2 KiB
Nix
Raw Normal View History

2023-04-07 22:40:01 +02:00
# visualize monitoring services
2024-07-28 21:08:02 +02:00
{
config,
lib,
pkgs,
...
}:
2023-04-07 22:40:01 +02:00
let
cfg = config.my.services.grafana;
2023-11-07 23:13:51 +01:00
inherit (config.networking) domain;
2023-04-07 22:40:01 +02:00
in
{
options.my.services.grafana = with lib; {
enable = mkEnableOption "Grafana for visualizing";
port = mkOption {
type = types.port;
default = 9500;
example = 3001;
description = "Internal port";
};
username = mkOption {
type = types.str;
default = "felix";
example = "admin";
description = "Admin username";
};
passwordFile = mkOption {
type = types.str;
example = "/var/lib/grafana/password.txt";
description = "Admin password stored in a file";
};
};
config = lib.mkIf cfg.enable {
services.grafana = {
enable = true;
settings = {
server = {
domain = "visualization.${domain}";
root_url = "https://visualization.${domain}/";
http_port = cfg.port;
http_addr = "127.0.0.1";
};
security = {
admin_user = cfg.username;
admin_password = "$__file{${cfg.passwordFile}}";
};
};
2023-04-16 17:27:48 +02:00
provision = {
enable = true;
dashboards.settings.providers = [
{
name = "Grafana";
options.path = pkgs.grafana-dashboards.grafana;
disableDeletion = true;
}
];
};
};
services.prometheus = {
scrapeConfigs = [
{
job_name = "grafana";
static_configs = [
{
targets = [ "127.0.0.1:${toString cfg.port}" ];
labels = {
instance = config.networking.hostName;
};
}
];
}
];
2023-04-07 22:40:01 +02:00
};
my.services.nginx.virtualHosts = [
{
subdomain = "visualization";
inherit (cfg) port;
}
];
webapps.apps.grafana = {
dashboard = {
name = "Visualization";
category = "infra";
icon = "chart-line";
2023-11-12 20:39:44 +01:00
url = "https://visualization.${domain}";
2023-04-07 22:40:01 +02:00
};
};
};
}