1 { config, pkgs, lib, ... }:
4 cfg = config.services.vmagent;
5 settingsFormat = pkgs.formats.json { };
7 options.services.vmagent = {
8 enable = mkEnableOption (lib.mdDoc "vmagent");
13 description = lib.mdDoc ''
14 User account under which vmagent runs.
21 description = lib.mdDoc ''
22 Group under which vmagent runs.
27 default = pkgs.vmagent;
28 defaultText = lib.literalMD "pkgs.vmagent";
30 description = lib.mdDoc ''
31 vmagent package to use.
37 default = "/var/lib/vmagent";
38 description = lib.mdDoc ''
39 The directory where vmagent stores its data files.
43 remoteWriteUrl = mkOption {
44 default = "http://localhost:8428/api/v1/write";
46 description = lib.mdDoc ''
47 The storage endpoint such as VictoriaMetrics
51 prometheusConfig = mkOption {
52 type = lib.types.submodule { freeformType = settingsFormat.type; };
53 description = lib.mdDoc ''
54 Config for prometheus style metrics
58 openFirewall = mkOption {
61 description = lib.mdDoc ''
62 Whether to open the firewall for the default ports.
67 config = mkIf cfg.enable {
68 users.groups = mkIf (cfg.group == "vmagent") { vmagent = { }; };
70 users.users = mkIf (cfg.user == "vmagent") {
73 description = "vmagent daemon user";
79 networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ 8429 ];
81 systemd.services.vmagent = let
82 prometheusConfig = settingsFormat.generate "prometheusConfig.yaml" cfg.prometheusConfig;
84 wantedBy = [ "multi-user.target" ];
85 after = [ "network.target" ];
86 description = "vmagent system service";
91 Restart = "on-failure";
92 WorkingDirectory = cfg.dataDir;
93 ExecStart = "${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig}";
97 systemd.tmpfiles.rules =
98 [ "d '${cfg.dataDir}' 0755 ${cfg.user} ${cfg.group} -" ];