···
11
+
cfg = config.services.bcg;
12
+
configFile = (pkgs.formats.yaml {}).generate "bcg.conf.yaml" (
13
+
filterAttrsRecursive (n: v: v != null) {
14
+
inherit (cfg) device name mqtt;
15
+
retain_node_messages = cfg.retainNodeMessages;
16
+
qos_node_messages = cfg.qosNodeMessages;
17
+
base_topic_prefix = cfg.baseTopicPrefix;
18
+
automatic_remove_kit_from_names = cfg.automaticRemoveKitFromNames;
19
+
automatic_rename_kit_nodes = cfg.automaticRenameKitNodes;
20
+
automatic_rename_generic_nodes = cfg.automaticRenameGenericNodes;
21
+
automatic_rename_nodes = cfg.automaticRenameNodes;
28
+
enable = mkEnableOption (mdDoc "BigClown gateway");
29
+
package = mkOption {
30
+
default = pkgs.python3Packages.bcg;
31
+
defaultText = literalExpression "pkgs.python3Packages.bcg";
32
+
description = mdDoc "Which bcg derivation to use.";
33
+
type = types.package;
35
+
environmentFiles = mkOption {
36
+
type = types.listOf types.path;
38
+
example = [ "/run/keys/bcg.env" ];
39
+
description = mdDoc ''
40
+
File to load as environment file. Environment variables from this file
41
+
will be interpolated into the config file using envsubst with this
42
+
syntax: `$ENVIRONMENT` or `''${VARIABLE}`.
43
+
This is useful to avoid putting secrets into the nix store.
46
+
verbose = mkOption {
47
+
type = types.enum ["CRITICAL" "ERROR" "WARNING" "INFO" "DEBUG"];
48
+
default = "WARNING";
49
+
description = mdDoc "Verbosity level.";
53
+
description = mdDoc "Device name to configure gateway to use.";
56
+
type = with types; nullOr str;
58
+
description = mdDoc ''
59
+
Name for the device.
61
+
Supported variables:
63
+
* `{id}` The ID of the connected usb-dongle or core-module
65
+
`null` can be used for automatic detection from gateway firmware.
71
+
default = "127.0.0.1";
72
+
description = mdDoc "Host where MQTT server is running.";
77
+
description = mdDoc "Port of MQTT server.";
79
+
username = mkOption {
80
+
type = with types; nullOr str;
82
+
description = mdDoc "MQTT server access username.";
84
+
password = mkOption {
85
+
type = with types; nullOr str;
87
+
description = mdDoc "MQTT server access password.";
90
+
type = with types; nullOr str;
92
+
description = mdDoc "Certificate Authority file for MQTT server access.";
94
+
certfile = mkOption {
95
+
type = with types; nullOr str;
97
+
description = mdDoc "Certificate file for MQTT server access.";
99
+
keyfile = mkOption {
100
+
type = with types; nullOr str;
102
+
description = mdDoc "Key file for MQTT server access.";
105
+
retainNodeMessages = mkOption {
108
+
description = mdDoc "Specify that node messages should be retaied in MQTT broker.";
110
+
qosNodeMessages = mkOption {
113
+
description = mdDoc "Set the guarantee of MQTT message delivery.";
115
+
baseTopicPrefix = mkOption {
118
+
description = mdDoc "Topic prefix added to all MQTT messages.";
120
+
automaticRemoveKitFromNames = mkOption {
123
+
description = mdDoc "Automatically remove kits.";
125
+
automaticRenameKitNodes = mkOption {
128
+
description = mdDoc "Automatically rename kit's nodes.";
130
+
automaticRenameGenericNodes = mkOption {
133
+
description = mdDoc "Automatically rename generic nodes.";
135
+
automaticRenameNodes = mkOption {
138
+
description = mdDoc "Automatically rename all nodes.";
140
+
rename = mkOption {
141
+
type = with types; attrsOf str;
143
+
description = mdDoc "Rename nodes to different name.";
148
+
config = mkIf cfg.enable {
149
+
environment.systemPackages = with pkgs; [
150
+
python3Packages.bcg
151
+
python3Packages.bch
154
+
systemd.services.bcg = let
155
+
envConfig = cfg.environmentFiles != [];
156
+
finalConfig = if envConfig
157
+
then "$RUNTIME_DIRECTORY/bcg.config.yaml"
160
+
description = "BigClown Gateway";
161
+
wantedBy = [ "multi-user.target" ];
162
+
wants = mkIf config.services.mosquitto.enable [ "mosquitto.service" ];
163
+
after = [ "network-online.target" ];
166
+
${pkgs.envsubst}/bin/envsubst -i "${configFile}" -o "${finalConfig}"
169
+
EnvironmentFile = cfg.environmentFiles;
170
+
ExecStart="${cfg.package}/bin/bcg -c ${finalConfig} -v ${cfg.verbose}";
171
+
RuntimeDirectory = "bcg";