Skip to content

Commit

Permalink
misc: clean module
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelCoding committed Dec 25, 2024
1 parent eb15d8c commit 4374f8c
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ let
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 "sflow_exporter";
package = lib.mkPackageOption pkgs "sflow-exporter" { };
listen = {
sflow = {
addr = lib.mkOption {
Expand Down Expand Up @@ -53,21 +48,20 @@ in
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];

environment =
let
addrToString = addr: port: "${if (lib.hasInfix ":" addr) then "[${addr}]" else addr}:${toString port}";
in
{
SFLOW_EXPORTER_SFlOW_LISTEN_ADDR = addrToString cfg.listen.sflow.addr cfg.listen.sflow.port;
SFLOW_EXPORTER_METRICS_LISTEN_ADDR = addrToString cfg.listen.metrics.addr cfg.listen.metrics.port;
SFLOW_EXPORTER_META = cfg.metaPath;
};

serviceConfig = {
ExecStart = "${lib.getExe cfg.package} 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}"
];
};
};
};
Expand Down

0 comments on commit 4374f8c

Please sign in to comment.