nixpkgs/nixos/modules/services/monitoring/vmagent.nix
stuebinm 6afb255d97 nixos: remove all uses of lib.mdDoc
these changes were generated with nixq 0.0.2, by running

  nixq ">> lib.mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> Inherit >> mdDoc[remove]" --batchmode nixos/**.nix

two mentions of the mdDoc function remain in nixos/, both of which
are inside of comments.

Since lib.mdDoc is already defined as just id, this commit is a no-op as
far as Nix (and the built manual) is concerned.
2024-04-13 10:07:35 -07:00

104 lines
2.7 KiB
Nix

{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.vmagent;
settingsFormat = pkgs.formats.json { };
in {
options.services.vmagent = {
enable = mkEnableOption "vmagent";
user = mkOption {
default = "vmagent";
type = types.str;
description = ''
User account under which vmagent runs.
'';
};
group = mkOption {
type = types.str;
default = "vmagent";
description = ''
Group under which vmagent runs.
'';
};
package = mkPackageOption pkgs "vmagent" { };
dataDir = mkOption {
type = types.str;
default = "/var/lib/vmagent";
description = ''
The directory where vmagent stores its data files.
'';
};
remoteWriteUrl = mkOption {
default = "http://localhost:8428/api/v1/write";
type = types.str;
description = ''
The storage endpoint such as VictoriaMetrics
'';
};
prometheusConfig = mkOption {
type = lib.types.submodule { freeformType = settingsFormat.type; };
description = ''
Config for prometheus style metrics
'';
};
openFirewall = mkOption {
type = types.bool;
default = false;
description = ''
Whether to open the firewall for the default ports.
'';
};
extraArgs = mkOption {
type = types.listOf types.str;
default = [];
description = ''
Extra args to pass to `vmagent`. See the docs:
<https://docs.victoriametrics.com/vmagent.html#advanced-usage>
or {command}`vmagent -help` for more information.
'';
};
};
config = mkIf cfg.enable {
users.groups = mkIf (cfg.group == "vmagent") { vmagent = { }; };
users.users = mkIf (cfg.user == "vmagent") {
vmagent = {
group = cfg.group;
description = "vmagent daemon user";
home = cfg.dataDir;
isSystemUser = true;
};
};
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ 8429 ];
systemd.services.vmagent = let
prometheusConfig = settingsFormat.generate "prometheusConfig.yaml" cfg.prometheusConfig;
in {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
description = "vmagent system service";
serviceConfig = {
User = cfg.user;
Group = cfg.group;
Type = "simple";
Restart = "on-failure";
WorkingDirectory = cfg.dataDir;
ExecStart = "${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig} ${escapeShellArgs cfg.extraArgs}";
};
};
systemd.tmpfiles.rules =
[ "d '${cfg.dataDir}' 0755 ${cfg.user} ${cfg.group} -" ];
};
}