Skip to main content
nerves-hub-link-agent is a NervesHub client for Linux systems that are not running Nerves. It is one Rust binary that runs beside your application. It does not write firmware itself: it runs the update tool your image already has, fwup or rauc. The agent:
  • reports which firmware the device is running
  • receives updates and runs the update tool
  • can ask your application whether to install an update and whether to reboot
  • confirms a good boot so the bootloader releases its rollback
  • runs support scripts
  • answers health, geo, logging, local shell and network identity requests
The agent has been exercised end to end against a NervesHub, and both update tools install, roll back and validate on a QEMU rig with a real bootloader. It has not yet run on production hardware.Client-certificate authentication and resumable downloads are not implemented. The agent refuses to start with a client-certificate config.

Requirements

Build

This builds nerves-hub-link-agent and agent-ctl in target/release/. Update tools are cargo features. The default feature set is sandbox and fwup. A config file cannot select a tool that was not built in. Build a device binary with only the tool it has:

Connect a device with the sandbox tool

Start with the sandbox update tool. It downloads firmware, verifies its SHA-256, writes it to a file and stops. It touches no block device or bootloader, and a reboot is only a log line.
1

Create a shared secret

Create a product shared secret in NervesHub. See Shared secret authentication. You get a product key that starts with nhp_ and a product secret.
2

Write a config file

agent.toml
For your own instance, set host to its device endpoint.initial_firmware is what the sandbox reports as the running firmware before anything is installed. Without it the device has no firmware for a deployment group to compare against.
3

Run the agent

The device appears in NervesHub under the identifier you configured.Set RUST_LOG=nerves_hub_link_agent=debug to log the URL it connects to and every frame in both directions.
4

Send it an update

Upload fwup firmware to the product and target the device from a deployment group. The sandbox downloads it into work_dir, and you can watch progress in NervesHub.
The sandbox reports itself to NervesHub as fwup, and the startup log line reads update tool fwup (sandboxed). It stands in for the fwup path, so test it with fwup firmware.

Configuration

The agent reads one TOML file. It looks for the path in this order:
  1. --config <path> (or -c <path>)
  2. The NERVES_HUB_AGENT_CONFIG environment variable
  3. /etc/nerves-hub-link-agent.toml
examples/agent.toml in the repository lists every option with its default.

Server

host is a host name only, with no scheme or path. The other values shown are the defaults.

Identity

The identifier comes from one of three sources:
A product shared secret registers any identifier NervesHub has not seen before. A wrong identifier creates a second device without an error. A literal identifier in a shipped image makes every device the same device. An identifier stored in the root filesystem is lost at the first update, so read it from the hardware or from a data partition.

fwup

The archive streams into fwup as it downloads. The agent reports its fwup version and NervesHub decides whether to send a delta, as it does for Nerves devices. See docs/fwup.md for what the image must provide.

RAUC

What the image must provide:
  • RAUC 1.9 or later. The agent refuses to start with an older version.
  • The RAUC service. rauc install is a D-Bus client of rauc service. The agent checks for the service at startup.
  • A system.conf that describes the slots, names a real bootloader backend, and points at a keyring. RAUC verifies bundles against that keyring. The agent has no signature settings for RAUC.
  • Verity bundles. Streaming requires them, and NervesHub refuses plain bundles.
The agent marks a boot good with rauc status mark-good booted. Identifying the running firmware. The agent reads firmware_file first. It holds key=value lines for uuid, version, product, platform and architecture, written by your image build. Pair it with a uuid in the bundle manifest’s [meta.nerveshub] section so that both sides name the same firmware. When the file is absent, the agent falls back to the bundle hash RAUC recorded for the booted slot. That hash exists only for slots RAUC installed, so a device flashed another way cannot report its firmware until its first RAUC update. See RAUC bundles. See docs/rauc.md for the slot configuration and a QEMU rig.

Update and reboot policy

policy = "apply" installs whatever arrives. policy = "ask" asks your application first. Reboot policy is separate, so an application can accept a download and still defer the reboot. The default reboot command is sudo reboot, because the agent is meant to run as an unprivileged user. That needs one sudoers rule:

Talking to your application

Your application talks to the agent over a Unix socket with newline-delimited JSON. One connection can be the controller, which answers update and reboot questions. Other connections are observers. See docs/ipc.md. agent-ctl is a small client for the same socket:

Extensions and support scripts

The agent implements five extensions. All are off by default in the agent’s config. The product and the device must also have the extension enabled in NervesHub. Turn one on with enabled = true in its table:
The local shell runs commands as the user the agent runs as, for anyone NervesHub allows to open it. Read docs/extensions.md before you enable it.
Support scripts are on by default. On this agent a script runs as a shell script, with bash as the default interpreter and a 10 second timeout. Scripts belong to the product, so a script written in Elixir for Nerves devices does not run here. See Support scripts.

Deploying to hardware

The repository’s docs/deploying.md covers cross-compiling, the service user, the systemd unit, and Buildroot packaging. docs/connecting.md covers endpoints, TLS, and what each connection failure means. If you build the image with Yocto, see meta-nerveshub.