Unverified Commit 5f27e501 authored by Leona Maroni's avatar Leona Maroni
Browse files

nixos/vmagent: remove global `with lib;`

parent cc1c4a28
Loading
Loading
Loading
Loading
+21 −21
Original line number Diff line number Diff line
{ 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}";
      };
    };