Unverified Commit f8db473d authored by Martin Weinelt's avatar Martin Weinelt Committed by GitHub
Browse files

nixos/statsd: drop (#496358)

parents edec7d26 934111c3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -80,6 +80,8 @@

- `sing-box` has been updated to 1.13.0, which has removed some deprecated options.  See [upstream documentation](https://sing-box.sagernet.org/configuration/) for details and migration options.

- `services.statsd` has been removed because the packages it relies on do not exist anymore in nixpkgs.

- `services.tandoor-recipes` now uses a sub-directory for media files by default starting with `26.05`. Existing setups should move media files out of the data directory and adjust `services.tandoor-recipes.extraConfig.MEDIA_ROOT` accordingly. See [Migrating media files for pre 26.05 installations](#module-services-tandoor-recipes-migrating-media).

- `rustic` was upgraded to `0.11.x`, which contains breaking [changes to command-line parameters and configuration file](https://rustic.cli.rs/docs/breaking_changes.html#0110).
+0 −1
Original line number Diff line number Diff line
@@ -1057,7 +1057,6 @@
  ./services/monitoring/scrutiny.nix
  ./services/monitoring/smartd.nix
  ./services/monitoring/snmpd.nix
  ./services/monitoring/statsd.nix
  ./services/monitoring/sysstat.nix
  ./services/monitoring/teamviewer.nix
  ./services/monitoring/telegraf.nix
+3 −0
Original line number Diff line number Diff line
@@ -319,6 +319,9 @@ in
      the program being unmaintained. The options `programs.msmtp.*` can be
      used instead.
    '')
    (mkRemovedOptionModule [ "services" "statsd" ] ''
      The statsd module was removed because the packages it uses have been removed from nixpkgs.
    '')
    (mkRemovedOptionModule [ "services" "sourcehut" ] ''
      The sourcehut packages and the corresponding module have been removed due to being broken and unmaintained.
    '')
+0 −154
Original line number Diff line number Diff line
{
  config,
  lib,
  pkgs,
  ...
}:
let

  cfg = config.services.statsd;

  isBuiltinBackend =
    name:
    builtins.elem name [
      "graphite"
      "console"
      "repeater"
    ];

  backendsToPackages =
    let
      mkMap = list: name: if isBuiltinBackend name then list else list ++ [ pkgs.nodePackages.${name} ];
    in
    lib.foldl mkMap [ ];

  configFile = pkgs.writeText "statsd.conf" ''
    {
      address: "${cfg.listenAddress}",
      port: "${toString cfg.port}",
      mgmt_address: "${cfg.mgmt_address}",
      mgmt_port: "${toString cfg.mgmt_port}",
      backends: [${
        lib.concatMapStringsSep "," (
          name: if (isBuiltinBackend name) then ''"./backends/${name}"'' else ''"${name}"''
        ) cfg.backends
      }],
      ${lib.optionalString (cfg.graphiteHost != null) ''graphiteHost: "${cfg.graphiteHost}",''}
      ${lib.optionalString (cfg.graphitePort != null) ''graphitePort: "${toString cfg.graphitePort}",''}
      console: {
        prettyprint: false
      },
      log: {
        backend: "stdout"
      },
      automaticConfigReload: false${lib.optionalString (cfg.extraConfig != null) ","}
      ${cfg.extraConfig}
    }
  '';

  deps = pkgs.buildEnv {
    name = "statsd-runtime-deps";
    pathsToLink = [ "/lib" ];
    ignoreCollisions = true;

    paths = backendsToPackages cfg.backends;
  };

in

{

  ###### interface

  options.services.statsd = {

    enable = lib.mkEnableOption "statsd";

    listenAddress = lib.mkOption {
      description = "Address that statsd listens on over UDP";
      default = "127.0.0.1";
      type = lib.types.str;
    };

    port = lib.mkOption {
      description = "Port that stats listens for messages on over UDP";
      default = 8125;
      type = lib.types.port;
    };

    mgmt_address = lib.mkOption {
      description = "Address to run management TCP interface on";
      default = "127.0.0.1";
      type = lib.types.str;
    };

    mgmt_port = lib.mkOption {
      description = "Port to run the management TCP interface on";
      default = 8126;
      type = lib.types.port;
    };

    backends = lib.mkOption {
      description = "List of backends statsd will use for data persistence";
      default = [ ];
      example = [
        "graphite"
        "console"
        "repeater"
        "statsd-librato-backend"
        "statsd-influxdb-backend"
      ];
      type = lib.types.listOf lib.types.str;
    };

    graphiteHost = lib.mkOption {
      description = "Hostname or IP of Graphite server";
      default = null;
      type = lib.types.nullOr lib.types.str;
    };

    graphitePort = lib.mkOption {
      description = "Port of Graphite server (i.e. carbon-cache).";
      default = null;
      type = lib.types.nullOr lib.types.port;
    };

    extraConfig = lib.mkOption {
      description = "Extra configuration options for statsd";
      default = "";
      type = lib.types.nullOr lib.types.str;
    };

  };

  ###### implementation

  config = lib.mkIf cfg.enable {

    assertions = map (backend: {
      assertion = !isBuiltinBackend backend -> lib.hasAttrByPath [ backend ] pkgs.nodePackages;
      message = "Only builtin backends (graphite, console, repeater) or backends enumerated in `pkgs.nodePackages` are allowed!";
    }) cfg.backends;

    users.users.statsd = {
      uid = config.ids.uids.statsd;
      description = "Statsd daemon user";
    };

    systemd.services.statsd = {
      description = "Statsd Server";
      wantedBy = [ "multi-user.target" ];
      environment = {
        NODE_PATH = "${deps}/lib/node_modules";
      };
      serviceConfig = {
        ExecStart = "${pkgs.statsd}/bin/statsd ${configFile}";
        User = "statsd";
      };
    };

    environment.systemPackages = [ pkgs.statsd ];

  };

}