Avahi for printer discovery / editing nsswitch.conf

Hi all-

I was trying to automatically detect printers within CUPS, so I could use my parents’ printer during a visit. I think I am supposed to use Avahi to add .local hostname resolution so that this works. I followed the suggestions in this tweet, and it almost worked: I was able to add the printer, but I got an error about “.local” addresses not working when I tried to print. Now that I am home, the same setup seems to work just fine with my own printer.

First question set: Is there anything else I should have to do to make printer discovery work? Can someone help me understand why this didn’t work at my parents’ house?

While I was at my parents house, I further attempted to modify the file /etc/nsswitch.conf by placing an entry in my /etc/nixos/configuration.nix file (through the environment.etc."nsswitch.conf" option), using an example I found online. However, after rebuilding my system, I found /etc/nsswitch.conf contained my specified text for the file, followed by the text that had been there before. (Since my laptop has been rebooted since I returned home from my parents’ house, I am not sure if the reboot explains why printer discovery works for me at home, while it didn’t at my parents’.)

Second question: how am I supposed to edit /etc/nsswitch.conf? What causes this “prepending” behavior when I try to supply my own file?

In general, I am looking for help understanding how Avahi is supposed to work, and in particular getting my head around what it takes to be able to easily print to available printers on any network via CUPS. Any help will be appreciated.



You might want to try running:

ping <printer>.local

to debug this further. It should resolve to the printer if it is configured correctly. Touching /etc/nsswitch.conf shouldn’t be necessary

Thanks for this tip! I am now trying all this from my workplace, and the ping command works just fine.

To print, I added the office printer through CUPS, finding it through Avahi’s exposed services, and selecting the generic “IPP Everywhere” driver. Is this procedure generally enough to feel like I’ve handled the problem of adding printers? What kind of printer features might I miss by using that driver? Are there many commonly used printers that don’t work with that driver?

Thanks for the help!


In addition to services.avahi.nssmdns, I’ve had easy luck for this kind of setup by adding the following to my /etc/nixos/configuration.nix:

  services.avahi.publish.enable = true;
  services.avahi.publish.workstation = true;

Thanks for the tip–can you explain what this does? It seems like this would advertise my own machine on the network as a workstation (whatever that might mean)?


According to the option docs, it registers a service of type _workstation._tcp. on the local domain.

_workstation._tcp. is a service that macOS machines used to all broadcast. They stopped doing that some time ago, I don’t remember exactly when, and it was never clear to me what the point was anyway.

I’m not sure myself why exactly these were needed in my case. It came to my mine I might want to try set these when I noticed that with only services.avahi.nssmdns, the network printer’s address has _tcp in it.