nixos/services.prometheus.pushgateway: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-30 00:47:01 +02:00
parent ea4bd53274
commit 3b6ddc5927

View File

@ -1,7 +1,4 @@
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.prometheus.pushgateway;
@ -10,23 +7,23 @@ let
++ opt "web.telemetry-path" cfg.web.telemetry-path
++ opt "web.external-url" cfg.web.external-url
++ opt "web.route-prefix" cfg.web.route-prefix
++ optional cfg.persistMetrics ''--persistence.file="/var/lib/${cfg.stateDir}/metrics"''
++ lib.optional cfg.persistMetrics ''--persistence.file="/var/lib/${cfg.stateDir}/metrics"''
++ opt "persistence.interval" cfg.persistence.interval
++ opt "log.level" cfg.log.level
++ opt "log.format" cfg.log.format
++ cfg.extraFlags;
opt = k : v : optional (v != null) ''--${k}="${v}"'';
opt = k : v : lib.optional (v != null) ''--${k}="${v}"'';
in {
options = {
services.prometheus.pushgateway = {
enable = mkEnableOption "Prometheus Pushgateway";
enable = lib.mkEnableOption "Prometheus Pushgateway";
package = mkPackageOption pkgs "prometheus-pushgateway" { };
package = lib.mkPackageOption pkgs "prometheus-pushgateway" { };
web.listen-address = mkOption {
type = types.nullOr types.str;
web.listen-address = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
Address to listen on for the web interface, API and telemetry.
@ -35,8 +32,8 @@ in {
'';
};
web.telemetry-path = mkOption {
type = types.nullOr types.str;
web.telemetry-path = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
Path under which to expose metrics.
@ -45,16 +42,16 @@ in {
'';
};
web.external-url = mkOption {
type = types.nullOr types.str;
web.external-url = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
The URL under which Pushgateway is externally reachable.
'';
};
web.route-prefix = mkOption {
type = types.nullOr types.str;
web.route-prefix = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
Prefix for the internal routes of web endpoints.
@ -64,8 +61,8 @@ in {
'';
};
persistence.interval = mkOption {
type = types.nullOr types.str;
persistence.interval = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "10m";
description = ''
@ -75,8 +72,8 @@ in {
'';
};
log.level = mkOption {
type = types.nullOr (types.enum ["debug" "info" "warn" "error" "fatal"]);
log.level = lib.mkOption {
type = lib.types.nullOr (lib.types.enum ["debug" "info" "warn" "error" "fatal"]);
default = null;
description = ''
Only log messages with the given severity or above.
@ -85,8 +82,8 @@ in {
'';
};
log.format = mkOption {
type = types.nullOr types.str;
log.format = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "logger:syslog?appname=bob&local=7";
description = ''
@ -96,16 +93,16 @@ in {
'';
};
extraFlags = mkOption {
type = types.listOf types.str;
extraFlags = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [];
description = ''
Extra commandline options when launching the Pushgateway.
'';
};
persistMetrics = mkOption {
type = types.bool;
persistMetrics = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether to persist metrics to a file.
@ -118,8 +115,8 @@ in {
'';
};
stateDir = mkOption {
type = types.str;
stateDir = lib.mkOption {
type = lib.types.str;
default = "pushgateway";
description = ''
Directory below `/var/lib` to store metrics.
@ -133,10 +130,10 @@ in {
};
};
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = !hasPrefix "/" cfg.stateDir;
assertion = !lib.hasPrefix "/" cfg.stateDir;
message =
"The option services.prometheus.pushgateway.stateDir" +
" shouldn't be an absolute directory." +
@ -148,8 +145,8 @@ in {
after = [ "network.target" ];
serviceConfig = {
ExecStart = "${cfg.package}/bin/pushgateway" +
optionalString (length cmdlineArgs != 0) (" \\\n " +
concatStringsSep " \\\n " cmdlineArgs);
lib.optionalString (lib.length cmdlineArgs != 0) (" \\\n " +
lib.concatStringsSep " \\\n " cmdlineArgs);
CapabilityBoundingSet = [ "" ];
DeviceAllow = [ "" ];