Publish a service with Avahi on NixOS

Revision history
Tags: nixos dns

Usually I would create a new .service file and fill in the service details there. But for now I was just able to figure out how to broadcast the hostname and IP address of the server the NixOS way.

I should later find out how to publish a HTTP web service listening on a specific port. This post will in that case be updated. Until then – this will suffice!


Open up the main NixOS configuration file at /etc/nixos/configuration.nix and enable the avahi service:

# Publish this server and its address on the network
services.avahi = {
  enable = true;
  publish = {
    enable = true;
    addresses = true;
    workstation = true;

Rebuild NixOS

# nixos-rebuild switch --fast

Now, on my other machine, I can see the server broadcasting itself

# systemctl start avahi-daemon.service
$ avahi-browse -park | grep nix


Debug mDNS traffic using tcpdump

# tcpdump -ni wlp3s0 port 5353


If you have any comments or feedback, please send me an e-mail. (stig at stigok dotcom).

Did you find any typos, incorrect information, or have something to add? Then please propose a change to this post.