nixos/vmagent: remove global with lib;

This commit is contained in:
Leona Maroni 2024-04-21 22:45:26 +02:00
parent cc1c4a2832
commit 5f27e501a1
No known key found for this signature in database
GPG Key ID: D5B08ADFC75E3605

View File

@ -1,63 +1,63 @@
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.vmagent;
settingsFormat = pkgs.formats.json { };
in {
options.services.vmagent = {
enable = mkEnableOption "vmagent";
enable = lib.mkEnableOption "vmagent";
user = mkOption {
user = lib.mkOption {
default = "vmagent";
type = types.str;
type = lib.types.str;
description = ''
User account under which vmagent runs.
'';
};
group = mkOption {
type = types.str;
group = lib.mkOption {
type = lib.types.str;
default = "vmagent";
description = ''
Group under which vmagent runs.
'';
};
package = mkPackageOption pkgs "vmagent" { };
package = lib.mkPackageOption pkgs "vmagent" { };
dataDir = mkOption {
type = types.str;
dataDir = lib.mkOption {
type = lib.types.str;
default = "/var/lib/vmagent";
description = ''
The directory where vmagent stores its data files.
'';
};
remoteWriteUrl = mkOption {
remoteWriteUrl = lib.mkOption {
default = "http://localhost:8428/api/v1/write";
type = types.str;
type = lib.types.str;
description = ''
The storage endpoint such as VictoriaMetrics
'';
};
prometheusConfig = mkOption {
prometheusConfig = lib.mkOption {
type = lib.types.submodule { freeformType = settingsFormat.type; };
description = ''
Config for prometheus style metrics
'';
};
openFirewall = mkOption {
type = types.bool;
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether to open the firewall for the default ports.
'';
};
extraArgs = mkOption {
type = types.listOf types.str;
extraArgs = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [];
description = ''
Extra args to pass to `vmagent`. See the docs:
@ -67,10 +67,10 @@ in {
};
};
config = mkIf cfg.enable {
users.groups = mkIf (cfg.group == "vmagent") { vmagent = { }; };
config = lib.mkIf cfg.enable {
users.groups = lib.mkIf (cfg.group == "vmagent") { vmagent = { }; };
users.users = mkIf (cfg.user == "vmagent") {
users.users = lib.mkIf (cfg.user == "vmagent") {
vmagent = {
group = cfg.group;
description = "vmagent daemon user";
@ -79,7 +79,7 @@ in {
};
};
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ 8429 ];
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ 8429 ];
systemd.services.vmagent = let
prometheusConfig = settingsFormat.generate "prometheusConfig.yaml" cfg.prometheusConfig;
@ -93,7 +93,7 @@ in {
Type = "simple";
Restart = "on-failure";
WorkingDirectory = cfg.dataDir;
ExecStart = "${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig} ${escapeShellArgs cfg.extraArgs}";
ExecStart = "${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig} ${lib.escapeShellArgs cfg.extraArgs}";
};
};