1 { config, pkgs, lib, ... }:
4 cfg = config.services.vmagent;
5 settingsFormat = pkgs.formats.json { };
8 (lib.mkRemovedOptionModule [ "services" "vmagent" "dataDir" ] "dataDir has been deprecated in favor of systemd provided CacheDirectory")
9 (lib.mkRemovedOptionModule [ "services" "vmagent" "user" ] "user has been deprecated in favor of systemd DynamicUser")
10 (lib.mkRemovedOptionModule [ "services" "vmagent" "group" ] "group has been deprecated in favor of systemd DynamicUser")
11 (lib.mkRenamedOptionModule [ "services" "vmagent" "remoteWriteUrl" ] [ "services" "vmagent" "remoteWrite" "url" ])
14 options.services.vmagent = {
15 enable = lib.mkEnableOption "vmagent";
17 package = lib.mkPackageOption pkgs "vmagent" { };
22 type = lib.types.nullOr lib.types.str;
24 Endpoint for prometheus compatible remote_write
27 basicAuthUsername = lib.mkOption {
29 type = lib.types.nullOr lib.types.str;
31 Basic Auth username used to connect to remote_write endpoint
34 basicAuthPasswordFile = lib.mkOption {
36 type = lib.types.nullOr lib.types.str;
38 File that contains the Basic Auth password used to connect to remote_write endpoint
43 prometheusConfig = lib.mkOption {
44 type = lib.types.submodule { freeformType = settingsFormat.type; };
46 Config for prometheus style metrics
50 openFirewall = lib.mkOption {
51 type = lib.types.bool;
54 Whether to open the firewall for the default ports.
58 extraArgs = lib.mkOption {
59 type = lib.types.listOf lib.types.str;
62 Extra args to pass to `vmagent`. See the docs:
63 <https://docs.victoriametrics.com/vmagent.html#advanced-usage>
64 or {command}`vmagent -help` for more information.
69 config = lib.mkIf cfg.enable {
70 networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ 8429 ];
72 systemd.services.vmagent = let
73 prometheusConfig = settingsFormat.generate "prometheusConfig.yaml" cfg.prometheusConfig;
74 startCommandLine = lib.concatStringsSep " " ([
75 "${cfg.package}/bin/vmagent"
76 "-promscrape.config=${prometheusConfig}"
78 ++ lib.optionals (cfg.remoteWrite.url != null) [
79 "-remoteWrite.url=${cfg.remoteWrite.url}"
80 "-remoteWrite.tmpDataPath=%C/vmagent/remote_write_tmp"
81 ] ++ lib.optional (cfg.remoteWrite.basicAuthUsername != null) "-remoteWrite.basicAuth.username=${cfg.remoteWrite.basicAuthUsername}"
82 ++ lib.optional (cfg.remoteWrite.basicAuthPasswordFile != null) "-remoteWrite.basicAuth.passwordFile=\${CREDENTIALS_DIRECTORY}/remote_write_basic_auth_password");
84 wantedBy = [ "multi-user.target" ];
85 after = [ "network.target" ];
86 description = "vmagent system service";
92 Restart = "on-failure";
93 CacheDirectory = "vmagent";
94 ExecStart = startCommandLine;
95 LoadCredential = lib.optional (cfg.remoteWrite.basicAuthPasswordFile != null) [
96 "remote_write_basic_auth_password:${cfg.remoteWrite.basicAuthPasswordFile}"