mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-03-22 17:49:07 +01:00
Rename modules directory system to nixos
This commit is contained in:
parent
653a6f310b
commit
1c1b9221fc
48 changed files with 1 additions and 1 deletions
180
modules/nixos/web-services/grafana.nix
Normal file
180
modules/nixos/web-services/grafana.nix
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.custom.web-services.grafana;
|
||||
in
|
||||
{
|
||||
options.custom.web-services.grafana = {
|
||||
enable = lib.mkEnableOption "";
|
||||
domain = lib.mkOption {
|
||||
type = lib.types.nonEmptyStr;
|
||||
default = "";
|
||||
};
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 3000;
|
||||
};
|
||||
datasources = {
|
||||
prometheus = {
|
||||
enable = lib.mkEnableOption "" // {
|
||||
default = config.custom.web-services.victoriametrics.enable;
|
||||
};
|
||||
url = lib.mkOption {
|
||||
type = lib.types.nonEmptyStr;
|
||||
default = "https://${config.custom.web-services.victoriametrics.domain}";
|
||||
};
|
||||
};
|
||||
victoriametrics = {
|
||||
enable = lib.mkEnableOption "" // {
|
||||
default = config.custom.web-services.victoriametrics.enable;
|
||||
};
|
||||
url = lib.mkOption {
|
||||
type = lib.types.nonEmptyStr;
|
||||
default = "https://${config.custom.web-services.victoriametrics.domain}";
|
||||
};
|
||||
};
|
||||
victorialogs = {
|
||||
enable = lib.mkEnableOption "" // {
|
||||
default = config.custom.web-services.victorialogs.enable;
|
||||
};
|
||||
url = lib.mkOption {
|
||||
type = lib.types.nonEmptyStr;
|
||||
default = "https://${config.custom.web-services.victorialogs.domain}";
|
||||
};
|
||||
};
|
||||
};
|
||||
dashboards = {
|
||||
nodeExporter.enable = lib.mkEnableOption "" // {
|
||||
default = true;
|
||||
};
|
||||
victoriametrics.enable = lib.mkEnableOption "" // {
|
||||
default = config.custom.web-services.victoriametrics.enable;
|
||||
};
|
||||
victorialogs.enable = lib.mkEnableOption "" // {
|
||||
default = config.custom.web-services.victorialogs.enable;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
sops.secrets."grafana/admin-password" = {
|
||||
owner = config.users.users.grafana.name;
|
||||
restartUnits = [ "grafana.service" ];
|
||||
};
|
||||
|
||||
services.grafana = {
|
||||
enable = true;
|
||||
|
||||
settings = {
|
||||
server = {
|
||||
inherit (cfg) domain;
|
||||
http_port = cfg.port;
|
||||
enforce_domain = true;
|
||||
enable_gzip = true;
|
||||
};
|
||||
security.admin_password = "$__file{${config.sops.secrets."grafana/admin-password".path}}";
|
||||
users.default_theme = "system";
|
||||
analytics.reporting_enabled = false;
|
||||
};
|
||||
|
||||
provision = {
|
||||
enable = true;
|
||||
|
||||
dashboards.settings = {
|
||||
providers = lib.singleton {
|
||||
name = "Dashboards";
|
||||
options.path = "/etc/grafana-dashboards";
|
||||
};
|
||||
};
|
||||
|
||||
datasources.settings = {
|
||||
prune = true;
|
||||
datasources = [
|
||||
(lib.mkIf cfg.datasources.prometheus.enable {
|
||||
name = "Prometheus";
|
||||
type = "prometheus";
|
||||
inherit (cfg.datasources.prometheus) url;
|
||||
isDefault = true;
|
||||
jsonData = {
|
||||
prometheusType = "Prometheus";
|
||||
prometheusVersion = "2.50.0";
|
||||
};
|
||||
})
|
||||
(lib.mkIf cfg.datasources.victoriametrics.enable {
|
||||
name = "VictoriaMetrics";
|
||||
type = "victoriametrics-metrics-datasource";
|
||||
inherit (cfg.datasources.victoriametrics) url;
|
||||
isDefault = false;
|
||||
})
|
||||
(lib.mkIf cfg.datasources.victorialogs.enable {
|
||||
name = "VictoriaLogs";
|
||||
type = "victoriametrics-logs-datasource";
|
||||
inherit (cfg.datasources.victorialogs) url;
|
||||
isDefault = false;
|
||||
})
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
declarativePlugins =
|
||||
let
|
||||
plugins = pkgs.grafanaPlugins;
|
||||
in
|
||||
[
|
||||
(lib.optional cfg.datasources.victoriametrics.enable plugins.victoriametrics-metrics-datasource)
|
||||
(lib.optional cfg.datasources.victorialogs.enable plugins.victoriametrics-logs-datasource)
|
||||
]
|
||||
|> lib.concatLists;
|
||||
};
|
||||
|
||||
environment.etc = {
|
||||
# https://grafana.com/grafana/dashboards/1860-node-exporter-full/
|
||||
"grafana-dashboards/node-exporter-full.json" = {
|
||||
enable = cfg.dashboards.nodeExporter.enable;
|
||||
source = pkgs.fetchurl {
|
||||
name = "node-exporter-full.json";
|
||||
url = "https://grafana.com/api/dashboards/1860/revisions/41/download";
|
||||
hash = "sha256-EywgxEayjwNIGDvSmA/S56Ld49qrTSbIYFpeEXBJlTs=";
|
||||
};
|
||||
};
|
||||
# https://grafana.com/grafana/dashboards/10229-victoriametrics-single-node/
|
||||
"grafana-dashboards/victoriametrics-single-node-patched.json" = {
|
||||
enable = cfg.dashboards.victoriametrics.enable;
|
||||
source =
|
||||
pkgs.fetchurl {
|
||||
name = "victoriametrics-single-node.json";
|
||||
url = "https://grafana.com/api/dashboards/10229/revisions/41/download";
|
||||
hash = "sha256-mwtah8A2w81WZjf5bUXoTJfS1R9UX+tua2PiDrBKJCQ=";
|
||||
}
|
||||
|> (
|
||||
src:
|
||||
pkgs.runCommand "victoriametrics-single-node-patched.json" { buildInputs = [ pkgs.gnused ]; } ''
|
||||
sed 's/victoriametrics-logs-//g' ${src} > $out
|
||||
''
|
||||
);
|
||||
};
|
||||
# https://grafana.com/grafana/dashboards/22084-victorialogs-single-node/
|
||||
"grafana-dashboards/victorialogs-single-node-patched.json" = {
|
||||
enable = cfg.dashboards.victorialogs.enable;
|
||||
source =
|
||||
pkgs.fetchurl {
|
||||
name = "victorialogs-single-node.json";
|
||||
url = "https://grafana.com/api/dashboards/22084/revisions/8/download";
|
||||
hash = "sha256-/a3Rbp/6oyiLBnQtGupyFZW+fIHQfkyKRRTyfofxVTM=";
|
||||
}
|
||||
|> (
|
||||
src:
|
||||
pkgs.runCommand "victorialogs-single-node-patched.json" { buildInputs = [ pkgs.gnused ]; } ''
|
||||
sed 's/victoria-logs-//g' ${src} > $out
|
||||
''
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
custom.services.caddy.virtualHosts.${cfg.domain}.port = cfg.port;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue