mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-02-01 17:53:14 +00:00
nixos/services.mqtt2influxdb: remove with lib;
This commit is contained in:
parent
36eaab4720
commit
5352447f1c
@ -4,12 +4,9 @@
|
|||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.mqtt2influxdb;
|
cfg = config.services.mqtt2influxdb;
|
||||||
filterNull = filterAttrsRecursive (n: v: v != null);
|
filterNull = lib.filterAttrsRecursive (n: v: v != null);
|
||||||
configFile = (pkgs.formats.yaml {}).generate "mqtt2influxdb.config.yaml" (
|
configFile = (pkgs.formats.yaml {}).generate "mqtt2influxdb.config.yaml" (
|
||||||
filterNull {
|
filterNull {
|
||||||
inherit (cfg) mqtt influxdb;
|
inherit (cfg) mqtt influxdb;
|
||||||
@ -17,26 +14,26 @@ let
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
pointType = types.submodule {
|
pointType = lib.types.submodule {
|
||||||
options = {
|
options = {
|
||||||
measurement = mkOption {
|
measurement = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
description = "Name of the measurement";
|
description = "Name of the measurement";
|
||||||
};
|
};
|
||||||
topic = mkOption {
|
topic = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
description = "MQTT topic to subscribe to.";
|
description = "MQTT topic to subscribe to.";
|
||||||
};
|
};
|
||||||
fields = mkOption {
|
fields = lib.mkOption {
|
||||||
type = types.submodule {
|
type = lib.types.submodule {
|
||||||
options = {
|
options = {
|
||||||
value = mkOption {
|
value = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "$.payload";
|
default = "$.payload";
|
||||||
description = "Value to be picked up";
|
description = "Value to be picked up";
|
||||||
};
|
};
|
||||||
type = mkOption {
|
type = lib.mkOption {
|
||||||
type = with types; nullOr str;
|
type = with lib.types; nullOr str;
|
||||||
default = null;
|
default = null;
|
||||||
description = "Type to be picked up";
|
description = "Type to be picked up";
|
||||||
};
|
};
|
||||||
@ -44,8 +41,8 @@ let
|
|||||||
};
|
};
|
||||||
description = "Field selector.";
|
description = "Field selector.";
|
||||||
};
|
};
|
||||||
tags = mkOption {
|
tags = lib.mkOption {
|
||||||
type = with types; attrsOf str;
|
type = with lib.types; attrsOf str;
|
||||||
default = {};
|
default = {};
|
||||||
description = "Tags applied";
|
description = "Tags applied";
|
||||||
};
|
};
|
||||||
@ -124,10 +121,10 @@ let
|
|||||||
in {
|
in {
|
||||||
options = {
|
options = {
|
||||||
services.mqtt2influxdb = {
|
services.mqtt2influxdb = {
|
||||||
enable = mkEnableOption "BigClown MQTT to InfluxDB bridge";
|
enable = lib.mkEnableOption "BigClown MQTT to InfluxDB bridge";
|
||||||
package = mkPackageOption pkgs ["python3Packages" "mqtt2influxdb"] {};
|
package = lib.mkPackageOption pkgs ["python3Packages" "mqtt2influxdb"] {};
|
||||||
environmentFiles = mkOption {
|
environmentFiles = lib.mkOption {
|
||||||
type = types.listOf types.path;
|
type = lib.types.listOf lib.types.path;
|
||||||
default = [];
|
default = [];
|
||||||
example = [ "/run/keys/mqtt2influxdb.env" ];
|
example = [ "/run/keys/mqtt2influxdb.env" ];
|
||||||
description = ''
|
description = ''
|
||||||
@ -138,23 +135,23 @@ in {
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
mqtt = {
|
mqtt = {
|
||||||
host = mkOption {
|
host = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "127.0.0.1";
|
default = "127.0.0.1";
|
||||||
description = "Host where MQTT server is running.";
|
description = "Host where MQTT server is running.";
|
||||||
};
|
};
|
||||||
port = mkOption {
|
port = lib.mkOption {
|
||||||
type = types.port;
|
type = lib.types.port;
|
||||||
default = 1883;
|
default = 1883;
|
||||||
description = "MQTT server port.";
|
description = "MQTT server port.";
|
||||||
};
|
};
|
||||||
username = mkOption {
|
username = lib.mkOption {
|
||||||
type = with types; nullOr str;
|
type = with lib.types; nullOr str;
|
||||||
default = null;
|
default = null;
|
||||||
description = "Username used to connect to the MQTT server.";
|
description = "Username used to connect to the MQTT server.";
|
||||||
};
|
};
|
||||||
password = mkOption {
|
password = lib.mkOption {
|
||||||
type = with types; nullOr str;
|
type = with lib.types; nullOr str;
|
||||||
default = null;
|
default = null;
|
||||||
description = ''
|
description = ''
|
||||||
MQTT password.
|
MQTT password.
|
||||||
@ -164,44 +161,44 @@ in {
|
|||||||
the store.
|
the store.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
cafile = mkOption {
|
cafile = lib.mkOption {
|
||||||
type = with types; nullOr path;
|
type = with lib.types; nullOr path;
|
||||||
default = null;
|
default = null;
|
||||||
description = "Certification Authority file for MQTT";
|
description = "Certification Authority file for MQTT";
|
||||||
};
|
};
|
||||||
certfile = mkOption {
|
certfile = lib.mkOption {
|
||||||
type = with types; nullOr path;
|
type = with lib.types; nullOr path;
|
||||||
default = null;
|
default = null;
|
||||||
description = "Certificate file for MQTT";
|
description = "Certificate file for MQTT";
|
||||||
};
|
};
|
||||||
keyfile = mkOption {
|
keyfile = lib.mkOption {
|
||||||
type = with types; nullOr path;
|
type = with lib.types; nullOr path;
|
||||||
default = null;
|
default = null;
|
||||||
description = "Key file for MQTT";
|
description = "Key file for MQTT";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
influxdb = {
|
influxdb = {
|
||||||
host = mkOption {
|
host = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "127.0.0.1";
|
default = "127.0.0.1";
|
||||||
description = "Host where InfluxDB server is running.";
|
description = "Host where InfluxDB server is running.";
|
||||||
};
|
};
|
||||||
port = mkOption {
|
port = lib.mkOption {
|
||||||
type = types.port;
|
type = lib.types.port;
|
||||||
default = 8086;
|
default = 8086;
|
||||||
description = "InfluxDB server port";
|
description = "InfluxDB server port";
|
||||||
};
|
};
|
||||||
database = mkOption {
|
database = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
description = "Name of the InfluxDB database.";
|
description = "Name of the InfluxDB database.";
|
||||||
};
|
};
|
||||||
username = mkOption {
|
username = lib.mkOption {
|
||||||
type = with types; nullOr str;
|
type = with lib.types; nullOr str;
|
||||||
default = null;
|
default = null;
|
||||||
description = "Username for InfluxDB login.";
|
description = "Username for InfluxDB login.";
|
||||||
};
|
};
|
||||||
password = mkOption {
|
password = lib.mkOption {
|
||||||
type = with types; nullOr str;
|
type = with lib.types; nullOr str;
|
||||||
default = null;
|
default = null;
|
||||||
description = ''
|
description = ''
|
||||||
Password for InfluxDB login.
|
Password for InfluxDB login.
|
||||||
@ -211,26 +208,26 @@ in {
|
|||||||
the store.
|
the store.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
ssl = mkOption {
|
ssl = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = "Use SSL to connect to the InfluxDB server.";
|
description = "Use SSL to connect to the InfluxDB server.";
|
||||||
};
|
};
|
||||||
verify_ssl = mkOption {
|
verify_ssl = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
description = "Verify SSL certificate when connecting to the InfluxDB server.";
|
description = "Verify SSL certificate when connecting to the InfluxDB server.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
points = mkOption {
|
points = lib.mkOption {
|
||||||
type = types.listOf pointType;
|
type = lib.types.listOf pointType;
|
||||||
default = defaultPoints;
|
default = defaultPoints;
|
||||||
description = "Points to bridge from MQTT to InfluxDB.";
|
description = "Points to bridge from MQTT to InfluxDB.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
systemd.services.bigclown-mqtt2influxdb = let
|
systemd.services.bigclown-mqtt2influxdb = let
|
||||||
envConfig = cfg.environmentFiles != [];
|
envConfig = cfg.environmentFiles != [];
|
||||||
finalConfig = if envConfig
|
finalConfig = if envConfig
|
||||||
@ -239,7 +236,7 @@ in {
|
|||||||
in {
|
in {
|
||||||
description = "BigClown MQTT to InfluxDB bridge";
|
description = "BigClown MQTT to InfluxDB bridge";
|
||||||
wantedBy = ["multi-user.target"];
|
wantedBy = ["multi-user.target"];
|
||||||
wants = mkIf config.services.mosquitto.enable ["mosquitto.service"];
|
wants = lib.mkIf config.services.mosquitto.enable ["mosquitto.service"];
|
||||||
preStart = ''
|
preStart = ''
|
||||||
umask 077
|
umask 077
|
||||||
${pkgs.envsubst}/bin/envsubst -i "${configFile}" -o "${finalConfig}"
|
${pkgs.envsubst}/bin/envsubst -i "${configFile}" -o "${finalConfig}"
|
||||||
|
Loading…
Reference in New Issue
Block a user