Skip to content

Commit 669838f

Browse files
committed
updates to make nixos module work correctly
1 parent 3e79699 commit 669838f

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

NIXOS.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ Add this to your `/etc/nixos/configuration.nix`:
6969
# };
7070
7171
# Device private key for Let'sMesh authentication
72-
# Required for auth token authentication
73-
privateKeyFile = "/path/to/your/private/key/file";
72+
# The script automatically fetches the private key from the device if it supports
73+
# ENABLE_PRIVATE_KEY_EXPORT. Only provide these if automatic fetching fails:
74+
# privateKeyFile = "/path/to/your/private/key/file";
7475
# OR
7576
# privateKey = "your_private_key_hex_string";
7677
@@ -163,7 +164,10 @@ If you're using Nix Flakes, add this to your `flake.nix`:
163164
keepalive = 120;
164165
};
165166
166-
privateKeyFile = "/path/to/your/private/key/file";
167+
# Device private key is automatically fetched from the device
168+
# Only set these if automatic fetching fails:
169+
# privateKeyFile = "/path/to/your/private/key/file";
170+
# privateKey = "your_private_key_hex_string";
167171
168172
# Optional: Owner information for Let'sMesh Analyzer
169173
# ownerPublicKey = "YOUR_64_CHAR_HEX_PUBLIC_KEY";
@@ -271,9 +275,11 @@ services.meshcore-packet-capture = {
271275
useAuthToken = true;
272276
tokenAudience = "mqtt.example.com";
273277
};
274-
privateKey = "your_private_key_hex_string";
278+
# Private key is automatically fetched from the device if it supports ENABLE_PRIVATE_KEY_EXPORT
279+
# Only provide these if automatic fetching fails:
280+
# privateKey = "your_private_key_hex_string";
275281
# OR
276-
privateKeyFile = "/path/to/private/key/file";
282+
# privateKeyFile = "/path/to/private/key/file";
277283
};
278284
```
279285

@@ -294,7 +300,8 @@ services.meshcore-packet-capture = {
294300
uploadPacketTypes = [ 0 1 2 ]; # Filter packet types, null = all
295301
rfDataTimeout = 15.0;
296302
outputFile = null; # Optional output file path
297-
privateKeyFile = "/path/to/private/key/file"; # Required for auth token auth
303+
# privateKeyFile = "/path/to/private/key/file"; # Only if auto-fetch fails
304+
# privateKey = "hex_string"; # Only if auto-fetch fails
298305
ownerPublicKey = null; # Optional: 64 hex character owner public key
299306
ownerEmail = null; # Optional: Owner email for Let'sMesh Analyzer
300307
dataDir = "/var/lib/meshcore-packet-capture";

nix/nixos-module.nix

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
options = {
88
enabled = lib.mkEnableOption "Enable MQTT broker ${toString num}";
99
server = lib.mkOption {
10-
type = lib.types.str;
10+
type = lib.types.nullOr lib.types.str;
11+
default = null;
1112
description = "MQTT broker address";
1213
};
1314
port = lib.mkOption {
@@ -100,26 +101,32 @@
100101

101102
# Build environment variables from configuration
102103
buildEnvVars = let
103-
mqttEnvVars = lib.flatten (lib.imap1 (num: broker: [
104-
"PACKETCAPTURE_MQTT${toString num}_ENABLED=${if broker.enabled then "true" else "false"}"
105-
"PACKETCAPTURE_MQTT${toString num}_SERVER=${broker.server}"
106-
"PACKETCAPTURE_MQTT${toString num}_PORT=${toString broker.port}"
107-
] ++ lib.optional (broker.username != null) "PACKETCAPTURE_MQTT${toString num}_USERNAME=${broker.username}"
108-
++ lib.optional (broker.password != null) "PACKETCAPTURE_MQTT${toString num}_PASSWORD=${broker.password}"
109-
++ ["PACKETCAPTURE_MQTT${toString num}_TRANSPORT=${broker.transport}"]
110-
++ ["PACKETCAPTURE_MQTT${toString num}_USE_TLS=${if broker.useTLS then "true" else "false"}"]
111-
++ ["PACKETCAPTURE_MQTT${toString num}_TLS_VERIFY=${if broker.tlsVerify then "true" else "false"}"]
112-
++ ["PACKETCAPTURE_MQTT${toString num}_USE_AUTH_TOKEN=${if broker.useAuthToken then "true" else "false"}"]
113-
++ lib.optional (broker.tokenAudience != null) "PACKETCAPTURE_MQTT${toString num}_TOKEN_AUDIENCE=${broker.tokenAudience}"
114-
++ lib.optional (broker.clientIdPrefix != null) "PACKETCAPTURE_MQTT${toString num}_CLIENT_ID_PREFIX=${broker.clientIdPrefix}"
115-
++ ["PACKETCAPTURE_MQTT${toString num}_QOS=${toString broker.qos}"]
116-
++ ["PACKETCAPTURE_MQTT${toString num}_RETAIN=${if broker.retain then "true" else "false"}"]
117-
++ ["PACKETCAPTURE_MQTT${toString num}_KEEPALIVE=${toString broker.keepalive}"]
118-
++ lib.optional (broker.topicStatus != null) "PACKETCAPTURE_MQTT${toString num}_TOPIC_STATUS=${broker.topicStatus}"
119-
++ lib.optional (broker.topicPackets != null) "PACKETCAPTURE_MQTT${toString num}_TOPIC_PACKETS=${broker.topicPackets}"
120-
++ lib.optional (broker.topicRaw != null) "PACKETCAPTURE_MQTT${toString num}_TOPIC_RAW=${broker.topicRaw}"
121-
++ lib.optional (broker.topicDecoded != null) "PACKETCAPTURE_MQTT${toString num}_TOPIC_DECODED=${broker.topicDecoded}"
122-
++ lib.optional (broker.topicDebug != null) "PACKETCAPTURE_MQTT${toString num}_TOPIC_DEBUG=${broker.topicDebug}") [
104+
mqttEnvVars = lib.flatten (lib.imap1 (num: broker:
105+
# Only generate env vars if broker is enabled and has a server configured
106+
if broker.enabled && broker.server != null then
107+
[
108+
"PACKETCAPTURE_MQTT${toString num}_ENABLED=true"
109+
"PACKETCAPTURE_MQTT${toString num}_SERVER=${broker.server}"
110+
"PACKETCAPTURE_MQTT${toString num}_PORT=${toString broker.port}"
111+
] ++ lib.optional (broker.username != null) "PACKETCAPTURE_MQTT${toString num}_USERNAME=${broker.username}"
112+
++ lib.optional (broker.password != null) "PACKETCAPTURE_MQTT${toString num}_PASSWORD=${broker.password}"
113+
++ ["PACKETCAPTURE_MQTT${toString num}_TRANSPORT=${broker.transport}"]
114+
++ ["PACKETCAPTURE_MQTT${toString num}_USE_TLS=${if broker.useTLS then "true" else "false"}"]
115+
++ ["PACKETCAPTURE_MQTT${toString num}_TLS_VERIFY=${if broker.tlsVerify then "true" else "false"}"]
116+
++ ["PACKETCAPTURE_MQTT${toString num}_USE_AUTH_TOKEN=${if broker.useAuthToken then "true" else "false"}"]
117+
++ lib.optional (broker.tokenAudience != null) "PACKETCAPTURE_MQTT${toString num}_TOKEN_AUDIENCE=${broker.tokenAudience}"
118+
++ lib.optional (broker.clientIdPrefix != null) "PACKETCAPTURE_MQTT${toString num}_CLIENT_ID_PREFIX=${broker.clientIdPrefix}"
119+
++ ["PACKETCAPTURE_MQTT${toString num}_QOS=${toString broker.qos}"]
120+
++ ["PACKETCAPTURE_MQTT${toString num}_RETAIN=${if broker.retain then "true" else "false"}"]
121+
++ ["PACKETCAPTURE_MQTT${toString num}_KEEPALIVE=${toString broker.keepalive}"]
122+
++ lib.optional (broker.topicStatus != null) "PACKETCAPTURE_MQTT${toString num}_TOPIC_STATUS=${broker.topicStatus}"
123+
++ lib.optional (broker.topicPackets != null) "PACKETCAPTURE_MQTT${toString num}_TOPIC_PACKETS=${broker.topicPackets}"
124+
++ lib.optional (broker.topicRaw != null) "PACKETCAPTURE_MQTT${toString num}_TOPIC_RAW=${broker.topicRaw}"
125+
++ lib.optional (broker.topicDecoded != null) "PACKETCAPTURE_MQTT${toString num}_TOPIC_DECODED=${broker.topicDecoded}"
126+
++ lib.optional (broker.topicDebug != null) "PACKETCAPTURE_MQTT${toString num}_TOPIC_DEBUG=${broker.topicDebug}"
127+
else [
128+
"PACKETCAPTURE_MQTT${toString num}_ENABLED=false"
129+
]) [
123130
cfg.mqtt1
124131
cfg.mqtt2
125132
cfg.mqtt3

0 commit comments

Comments
 (0)