nixos/services.statsd: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-30 00:47:04 +02:00
parent 084011a1b4
commit 8b8b523eb9

View File

@ -1,7 +1,4 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.statsd;
@ -13,7 +10,7 @@ let
mkMap = list: name:
if isBuiltinBackend name then list
else list ++ [ pkgs.nodePackages.${name} ];
in foldl mkMap [];
in lib.foldl mkMap [];
configFile = pkgs.writeText "statsd.conf" ''
{
@ -22,20 +19,20 @@ let
mgmt_address: "${cfg.mgmt_address}",
mgmt_port: "${toString cfg.mgmt_port}",
backends: [${
concatMapStringsSep "," (name:
lib.concatMapStringsSep "," (name:
if (isBuiltinBackend name)
then ''"./backends/${name}"''
else ''"${name}"''
) cfg.backends}],
${optionalString (cfg.graphiteHost!=null) ''graphiteHost: "${cfg.graphiteHost}",''}
${optionalString (cfg.graphitePort!=null) ''graphitePort: "${toString cfg.graphitePort}",''}
${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${optionalString (cfg.extraConfig != null) ","}
automaticConfigReload: false${lib.optionalString (cfg.extraConfig != null) ","}
${cfg.extraConfig}
}
'';
@ -56,33 +53,33 @@ in
options.services.statsd = {
enable = mkEnableOption "statsd";
enable = lib.mkEnableOption "statsd";
listenAddress = mkOption {
listenAddress = lib.mkOption {
description = "Address that statsd listens on over UDP";
default = "127.0.0.1";
type = types.str;
type = lib.types.str;
};
port = mkOption {
port = lib.mkOption {
description = "Port that stats listens for messages on over UDP";
default = 8125;
type = types.int;
type = lib.types.int;
};
mgmt_address = mkOption {
mgmt_address = lib.mkOption {
description = "Address to run management TCP interface on";
default = "127.0.0.1";
type = types.str;
type = lib.types.str;
};
mgmt_port = mkOption {
mgmt_port = lib.mkOption {
description = "Port to run the management TCP interface on";
default = 8126;
type = types.int;
type = lib.types.int;
};
backends = mkOption {
backends = lib.mkOption {
description = "List of backends statsd will use for data persistence";
default = [];
example = [
@ -93,35 +90,35 @@ in
"stackdriver-statsd-backend"
"statsd-influxdb-backend"
];
type = types.listOf types.str;
type = lib.types.listOf lib.types.str;
};
graphiteHost = mkOption {
graphiteHost = lib.mkOption {
description = "Hostname or IP of Graphite server";
default = null;
type = types.nullOr types.str;
type = lib.types.nullOr lib.types.str;
};
graphitePort = mkOption {
graphitePort = lib.mkOption {
description = "Port of Graphite server (i.e. carbon-cache).";
default = null;
type = types.nullOr types.int;
type = lib.types.nullOr lib.types.int;
};
extraConfig = mkOption {
extraConfig = lib.mkOption {
description = "Extra configuration options for statsd";
default = "";
type = types.nullOr types.str;
type = lib.types.nullOr lib.types.str;
};
};
###### implementation
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
assertions = map (backend: {
assertion = !isBuiltinBackend backend -> hasAttrByPath [ backend ] pkgs.nodePackages;
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;