8 cfg = config.services.bcg;
9 configFile = (pkgs.formats.yaml {}).generate "bcg.conf.yaml" (
10 lib.filterAttrsRecursive (n: v: v != null) {
11 inherit (cfg) device name mqtt;
12 retain_node_messages = cfg.retainNodeMessages;
13 qos_node_messages = cfg.qosNodeMessages;
14 base_topic_prefix = cfg.baseTopicPrefix;
15 automatic_remove_kit_from_names = cfg.automaticRemoveKitFromNames;
16 automatic_rename_kit_nodes = cfg.automaticRenameKitNodes;
17 automatic_rename_generic_nodes = cfg.automaticRenameGenericNodes;
18 automatic_rename_nodes = cfg.automaticRenameNodes;
25 enable = lib.mkEnableOption "BigClown gateway";
26 package = lib.mkPackageOption pkgs [ "python3Packages" "bcg" ] { };
27 environmentFiles = lib.mkOption {
28 type = lib.types.listOf lib.types.path;
30 example = [ "/run/keys/bcg.env" ];
32 File to load as environment file. Environment variables from this file
33 will be interpolated into the config file using envsubst with this
34 syntax: `$ENVIRONMENT` or `''${VARIABLE}`.
35 This is useful to avoid putting secrets into the nix store.
38 verbose = lib.mkOption {
39 type = lib.types.enum ["CRITICAL" "ERROR" "WARNING" "INFO" "DEBUG"];
41 description = "Verbosity level.";
43 device = lib.mkOption {
45 description = "Device name to configure gateway to use.";
48 type = with lib.types; nullOr str;
55 * `{id}` The ID of the connected usb-dongle or core-module
57 `null` can be used for automatic detection from gateway firmware.
63 default = "127.0.0.1";
64 description = "Host where MQTT server is running.";
67 type = lib.types.port;
69 description = "Port of MQTT server.";
71 username = lib.mkOption {
72 type = with lib.types; nullOr str;
74 description = "MQTT server access username.";
76 password = lib.mkOption {
77 type = with lib.types; nullOr str;
79 description = "MQTT server access password.";
81 cafile = lib.mkOption {
82 type = with lib.types; nullOr str;
84 description = "Certificate Authority file for MQTT server access.";
86 certfile = lib.mkOption {
87 type = with lib.types; nullOr str;
89 description = "Certificate file for MQTT server access.";
91 keyfile = lib.mkOption {
92 type = with lib.types; nullOr str;
94 description = "Key file for MQTT server access.";
97 retainNodeMessages = lib.mkOption {
98 type = lib.types.bool;
100 description = "Specify that node messages should be retaied in MQTT broker.";
102 qosNodeMessages = lib.mkOption {
103 type = lib.types.int;
105 description = "Set the guarantee of MQTT message delivery.";
107 baseTopicPrefix = lib.mkOption {
108 type = lib.types.str;
110 description = "Topic prefix added to all MQTT messages.";
112 automaticRemoveKitFromNames = lib.mkOption {
113 type = lib.types.bool;
115 description = "Automatically remove kits.";
117 automaticRenameKitNodes = lib.mkOption {
118 type = lib.types.bool;
120 description = "Automatically rename kit's nodes.";
122 automaticRenameGenericNodes = lib.mkOption {
123 type = lib.types.bool;
125 description = "Automatically rename generic nodes.";
127 automaticRenameNodes = lib.mkOption {
128 type = lib.types.bool;
130 description = "Automatically rename all nodes.";
132 rename = lib.mkOption {
133 type = with lib.types; attrsOf str;
135 description = "Rename nodes to different name.";
140 config = lib.mkIf cfg.enable {
141 environment.systemPackages = with pkgs; [
146 systemd.services.bcg = let
147 envConfig = cfg.environmentFiles != [];
148 finalConfig = if envConfig
149 then "\${RUNTIME_DIRECTORY}/bcg.config.yaml"
152 description = "BigClown Gateway";
153 wantedBy = [ "multi-user.target" ];
154 wants = [ "network-online.target" ] ++ lib.optional config.services.mosquitto.enable "mosquitto.service";
155 after = [ "network-online.target" ];
156 preStart = lib.mkIf envConfig ''
158 ${pkgs.envsubst}/bin/envsubst -i "${configFile}" -o "${finalConfig}"
161 EnvironmentFile = cfg.environmentFiles;
162 ExecStart = "${cfg.package}/bin/bcg -c ${finalConfig} -v ${cfg.verbose}";
163 RuntimeDirectory = "bcg";