···
+
cfg = config.services.bcg;
+
configFile = (pkgs.formats.yaml {}).generate "bcg.conf.yaml" (
+
filterAttrsRecursive (n: v: v != null) {
+
inherit (cfg) device name mqtt;
+
retain_node_messages = cfg.retainNodeMessages;
+
qos_node_messages = cfg.qosNodeMessages;
+
base_topic_prefix = cfg.baseTopicPrefix;
+
automatic_remove_kit_from_names = cfg.automaticRemoveKitFromNames;
+
automatic_rename_kit_nodes = cfg.automaticRenameKitNodes;
+
automatic_rename_generic_nodes = cfg.automaticRenameGenericNodes;
+
automatic_rename_nodes = cfg.automaticRenameNodes;
+
enable = mkEnableOption (mdDoc "BigClown gateway");
+
default = pkgs.python3Packages.bcg;
+
defaultText = literalExpression "pkgs.python3Packages.bcg";
+
description = mdDoc "Which bcg derivation to use.";
+
environmentFiles = mkOption {
+
type = types.listOf types.path;
+
example = [ "/run/keys/bcg.env" ];
+
File to load as environment file. Environment variables from this file
+
will be interpolated into the config file using envsubst with this
+
syntax: `$ENVIRONMENT` or `''${VARIABLE}`.
+
This is useful to avoid putting secrets into the nix store.
+
type = types.enum ["CRITICAL" "ERROR" "WARNING" "INFO" "DEBUG"];
+
description = mdDoc "Verbosity level.";
+
description = mdDoc "Device name to configure gateway to use.";
+
type = with types; nullOr str;
+
* `{id}` The ID of the connected usb-dongle or core-module
+
`null` can be used for automatic detection from gateway firmware.
+
description = mdDoc "Host where MQTT server is running.";
+
description = mdDoc "Port of MQTT server.";
+
type = with types; nullOr str;
+
description = mdDoc "MQTT server access username.";
+
type = with types; nullOr str;
+
description = mdDoc "MQTT server access password.";
+
type = with types; nullOr str;
+
description = mdDoc "Certificate Authority file for MQTT server access.";
+
type = with types; nullOr str;
+
description = mdDoc "Certificate file for MQTT server access.";
+
type = with types; nullOr str;
+
description = mdDoc "Key file for MQTT server access.";
+
retainNodeMessages = mkOption {
+
description = mdDoc "Specify that node messages should be retaied in MQTT broker.";
+
qosNodeMessages = mkOption {
+
description = mdDoc "Set the guarantee of MQTT message delivery.";
+
baseTopicPrefix = mkOption {
+
description = mdDoc "Topic prefix added to all MQTT messages.";
+
automaticRemoveKitFromNames = mkOption {
+
description = mdDoc "Automatically remove kits.";
+
automaticRenameKitNodes = mkOption {
+
description = mdDoc "Automatically rename kit's nodes.";
+
automaticRenameGenericNodes = mkOption {
+
description = mdDoc "Automatically rename generic nodes.";
+
automaticRenameNodes = mkOption {
+
description = mdDoc "Automatically rename all nodes.";
+
type = with types; attrsOf str;
+
description = mdDoc "Rename nodes to different name.";
+
config = mkIf cfg.enable {
+
environment.systemPackages = with pkgs; [
+
systemd.services.bcg = let
+
envConfig = cfg.environmentFiles != [];
+
finalConfig = if envConfig
+
then "$RUNTIME_DIRECTORY/bcg.config.yaml"
+
description = "BigClown Gateway";
+
wantedBy = [ "multi-user.target" ];
+
wants = mkIf config.services.mosquitto.enable [ "mosquitto.service" ];
+
after = [ "network-online.target" ];
+
${pkgs.envsubst}/bin/envsubst -i "${configFile}" -o "${finalConfig}"
+
EnvironmentFile = cfg.environmentFiles;
+
ExecStart="${cfg.package}/bin/bcg -c ${finalConfig} -v ${cfg.verbose}";
+
RuntimeDirectory = "bcg";