Files
nixos/modules/services/meshcore/default.nix
JakeHillion 9e4157fb21
commit-validation / validate-single-commit (pull_request) Successful in 24s
buildbot/nix-eval Build done. (767 warnings)
buildbot/nix-build Build done.
buildbot/nix-effects Build done.
meshcore: log a MeshCore companion node to the journal
A Heltec V4 running the MeshCore USB companion firmware is plugged into
stinger. Nothing reads it, so what it hears is lost, and there is no
record of where a portable node has been.

Add a service that owns the node's serial port through the meshcore
library. It writes every direct and channel message and every advert to
the journal, with the sender, channel, SNR and path as structured
fields, and asks the portable node for telemetry every 5 minutes,
logging the decoded readings, location included, or the missing reply.
The portable node's public key is an agent-tier secret, so the public
repo doesn't tie it to its owner. The unit starts with the device and
stops when it is unplugged.

Test plan:
- Checked the script parses and its imports resolve against stinger's
  Python environment
- After deploy: messages and adverts appear in the journal, and a
  telemetry entry with the portable node's location every 5 minutes
- CI
2026-12-02 18:14:09 +00:00

42 lines
1.4 KiB
Nix

{ config, pkgs, lib, ... }:
let
cfg = config.custom.services.meshcore;
script = pkgs.writers.writePython3 "meshcore-journal"
{
libraries = with pkgs.python3Packages; [ meshcore systemd-python ];
}
(builtins.readFile ./meshcore_journal.py);
in
{
options.custom.services.meshcore = {
enable = lib.mkEnableOption "MeshCore companion node logging";
};
config = lib.mkIf cfg.enable {
age.secrets."meshcore/telemetry-target".rekeyFile = ./telemetry-target.agent.age;
# The Heltec V4 uses the ESP32-S3's built-in USB serial, whose IDs every
# ESP32-S3 shares, so match this board by the MAC it reports as its serial.
services.udev.extraRules = ''
SUBSYSTEM=="tty", ATTRS{idVendor}=="303a", ATTRS{idProduct}=="1001", ATTRS{serial}=="D4:05:92:55:19:D8", SYMLINK+="meshcore"
'';
systemd.services.meshcore = {
description = "Log MeshCore traffic to the journal";
wantedBy = [ "dev-meshcore.device" ];
bindsTo = [ "dev-meshcore.device" ];
after = [ "dev-meshcore.device" ];
serviceConfig = {
ExecStart = "${script} --port /dev/meshcore --telemetry-target-file %d/telemetry-target --telemetry-interval 300";
DynamicUser = true;
SupplementaryGroups = [ "dialout" ];
LoadCredential = "telemetry-target:${config.age.secrets."meshcore/telemetry-target".path}";
Restart = "always";
RestartSec = 10;
};
};
};
}