Files
nixos/hosts/common/optional/selfhosted/monitoring/prometheus/default.nix
T
aloslider c92b90e406 Small modules config restructure
Changed variables names in every module
2026-10-31 19:48:50 +03:00

48 lines
1.4 KiB
Nix

{ config, lib, ... }:
with lib;
let
rootCfg = config.selfhosted;
common = rootCfg.common;
moduleCfg = rootCfg.monitoring;
cfg = moduleCfg.prometheus;
hostDataPath = "${common.dataDir}/prometheus";
in
{
imports = [ ./config.nix ];
options.selfhosted.monitoring.prometheus = {
name = mkOption {
type = types.str;
};
};
config = mkIf moduleCfg.enable {
virtualisation.oci-containers.containers."${cfg.name}" = {
image = "docker.io/prom/prometheus:v3.15.0";
volumes = [
"${hostDataPath}/data:/prometheus"
"${hostDataPath}/monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro"
];
log-driver = "journald";
extraOptions = [
"--network=${common.network.name}"
];
};
systemd.services."${common.backend}-${cfg.name}" = {
serviceConfig = {
Restart = lib.mkOverride 90 "always";
};
wantedBy = [ "${common.backend}-${moduleCfg.targetName}.target" ];
partOf = [ "${common.backend}-${moduleCfg.targetName}.target" ];
after = [ "${common.backend}-${moduleCfg.nodeExporter.name}.service" ];
preStart = ''
mkdir -p ${hostDataPath}/data ${hostDataPath}/monitoring
cp -f ${config.sops.templates."prometheus.yml".path} ${hostDataPath}/monitoring/prometheus.yml
chmod 644 ${hostDataPath}/monitoring/prometheus.yml
chown -R 65534:65534 ${hostDataPath}
'';
};
};
}