Skip to content

Mosquitto

Mosquitto is an open-source message broker that implements the MQTT protocol. In this homelab, it serves as the central communication hub for IoT devices, specifically integrating Zigbee2MQTT with Home Assistant.

PortProtocolDescription
1883TCPMain MQTT listener (Internal only)

The broker is accessible locally at mqtt://localhost:1883 or via the server IP. It is not exposed to the external network for security reasons.

Authentication is mandatory. Secrets are managed via 1Password and injected at runtime.

Secret PathKeyEnvironment Variable
op://Homelab/Mosquito/usernameusernameMQTT_USER
op://Homelab/Mosquito/passwordpasswordMQTT_PASS

Due to strict NixOS module schemas, the configuration is injected via an inclusion pattern:

  1. Secrets are fetched by mosquitto-secrets.service.
  2. A manual auth.conf is generated in /var/lib/mosquitto/config/.
  3. The main service includes this directory via services.mosquitto.includeDirs.
  • Paths: /var/lib/mosquitto (Persistence database).
  • Exclusions: passwd*, config/ (Regenerated at every startup).
Terminal window
systemctl status mosquitto
Terminal window
journalctl -u mosquitto -f
Terminal window
source /run/mosquitto/env
nix shell nixpkgs#mosquitto --command mosquitto_pub -h localhost -u "$MQTT_USER" -P "$MQTT_PASS" -t "test/status" -m "check"