-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.nix
75 lines (68 loc) · 2.32 KB
/
module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{ config, pkgs, lib, ... }:
let
cfg = config.services.sflow-exporter;
in
{
options.services.sflow-exporter = {
package = lib.mkOption {
type = lib.types.package;
default = pkgs.sflow-exporter;
defaultText = lib.literalExpression "pkgs.sflow-exporter";
description = lib.mdDoc "Which sflow_exporzer derivation to use.";
};
enable = lib.mkEnableOption (lib.mdDoc "sflow_exporter");
listen = {
sflow = {
addr = lib.mkOption {
type = lib.types.str;
description = lib.mdDoc "The ip address the sflow listener shuld be listening on.";
default = "::";
};
port = lib.mkOption {
type = lib.types.port;
description = lib.mdDoc "The port the sflow listener shuld be listening on.";
default = 6343;
};
};
metrics = {
addr = lib.mkOption {
type = lib.types.str;
description = lib.mdDoc "The ip address the metrics listener shuld be listening on.";
default = "::";
};
port = lib.mkOption {
type = lib.types.port;
description = lib.mdDoc "The port the metrics listener shuld be listening on.";
default = 9144;
};
};
};
metaPath = lib.mkOption {
type = lib.types.str;
description = lib.mdDoc "The path where the meta configuration file is located.";
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
systemd.services.sflow-exporter = {
description = "sflow_exporter";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart = "${cfg.package}/bin/sflow_exporter listen";
DynamicUser = true;
User = "sflow_exporter";
Environment =
let
sflowAddr = cfg.listen.sflow.addr;
metricsAddr = cfg.listen.metrics.addr;
in
[
"SFLOW_EXPORTER_SFlOW_LISTEN_ADDR=${if (lib.hasInfix ":" sflowAddr) then "[${sflowAddr}]" else sflowAddr}:${toString cfg.listen.sflow.port}"
"SFLOW_EXPORTER_METRICS_LISTEN_ADDR=${if (lib.hasInfix ":" metricsAddr) then "[${metricsAddr}]" else metricsAddr}:${toString cfg.listen.metrics.port}"
"SFLOW_EXPORTER_META=${cfg.metaPath}"
];
};
};
};
}