2024-05-21 01:51:15 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}:
|
2024-05-21 01:23:10 +00:00
|
|
|
with lib; let
|
2024-05-21 01:51:15 +00:00
|
|
|
name = "grafana";
|
2024-05-21 02:02:37 +00:00
|
|
|
cfg = config.services.skynet."${name}";
|
2024-05-21 01:51:15 +00:00
|
|
|
port = 4444;
|
2024-05-21 01:23:10 +00:00
|
|
|
in {
|
|
|
|
imports = [
|
|
|
|
./acme.nix
|
|
|
|
./dns.nix
|
|
|
|
];
|
|
|
|
|
2024-05-21 01:51:15 +00:00
|
|
|
options.services.skynet."${name}" = {
|
2024-05-21 01:23:10 +00:00
|
|
|
enable = mkEnableOption "Grafana Server";
|
|
|
|
|
|
|
|
host = {
|
|
|
|
ip = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
};
|
2024-05-21 05:16:35 +00:00
|
|
|
|
|
|
|
datasource = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
url = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
};
|
2024-05-21 01:23:10 +00:00
|
|
|
};
|
|
|
|
|
2024-05-21 01:51:15 +00:00
|
|
|
config = mkIf cfg.enable {
|
2024-05-30 12:25:52 +00:00
|
|
|
services.skynet.dns.records = [
|
2024-05-21 01:23:10 +00:00
|
|
|
{
|
|
|
|
record = "${name}";
|
|
|
|
r_type = "CNAME";
|
|
|
|
value = cfg.host.name;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-05-30 12:34:59 +00:00
|
|
|
services.skynet.acme.domains = [
|
2024-05-21 01:23:10 +00:00
|
|
|
"${name}.skynet.ie"
|
|
|
|
];
|
2024-05-21 01:51:15 +00:00
|
|
|
|
2024-05-23 03:07:19 +00:00
|
|
|
age.secrets.grafana_pw = {
|
|
|
|
file = ../secrets/grafana/pw.age;
|
|
|
|
owner = "grafana";
|
|
|
|
group = "grafana";
|
|
|
|
};
|
2024-05-23 01:39:36 +00:00
|
|
|
|
2024-05-21 01:51:15 +00:00
|
|
|
services.grafana = {
|
|
|
|
enable = true;
|
2024-05-21 02:02:37 +00:00
|
|
|
domain = "${name}.skynet.ie";
|
2024-05-21 02:40:58 +00:00
|
|
|
port = port;
|
2024-05-21 05:16:35 +00:00
|
|
|
|
2024-05-23 01:39:36 +00:00
|
|
|
settings.security.admin_password = "$__file{${config.age.secrets.grafana_pw.path}}";
|
|
|
|
|
2024-05-21 05:16:35 +00:00
|
|
|
provision = {
|
|
|
|
enable = true;
|
|
|
|
datasources.settings.datasources = [
|
|
|
|
{
|
2024-05-23 03:34:19 +00:00
|
|
|
name = "Prometheus";
|
2024-05-23 03:20:44 +00:00
|
|
|
type = "prometheus";
|
2024-05-23 03:34:19 +00:00
|
|
|
url = "http://localhost:${toString config.services.skynet.prometheus.server.port}";
|
2024-05-21 05:16:35 +00:00
|
|
|
isDefault = true;
|
2024-05-23 03:20:44 +00:00
|
|
|
editable = true;
|
2024-05-21 05:16:35 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2024-05-21 01:51:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.nginx.virtualHosts = {
|
|
|
|
"${name}.skynet.ie" = {
|
|
|
|
forceSSL = true;
|
|
|
|
useACMEHost = "skynet";
|
|
|
|
locations."/" = {
|
2024-05-21 02:40:58 +00:00
|
|
|
proxyPass = "http://localhost:${toString port}";
|
2024-05-21 01:51:15 +00:00
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-05-21 01:23:10 +00:00
|
|
|
};
|
|
|
|
}
|