How to add search domains to /etc/resolv.conf?

On Debian I used to just edit the NetworkManager configuration to add “Additional search domains” in the “IPv4 Settings” tab of my wired connection in the NetworkManager applet, but on NixOS that settings seems to have no effect. And when I re-connect the domains I added are gone.

I tried using the networking.resolvconf.useHostResolvConf setting but it appears to do nothing in the file its defined in.

I also looked at NetworkManager settings and I found both networking.networkmanager.appendNameservers and networking.networkmanager.insertNameservers but nothing related to search domains.
I also tried setting networking.networkmanager.dns to several of the suggested values like dnsmasqbut it has no effect whatsoever.

I just want to add:

search my.own.domain

To resolv.conf so I don’t have to append it to hosts whenever I SSH. How can I do this?

1 Like

Did you try setting networking.search?

networking.search = [ "mydomain.com" ];
2 Likes

No, I did not, and it works! When I was searching for this I simply typed resolv into the options site:
https://nixos.org/nixos/options.html#resolv
And I focused on the networking.resolvconf section where I expected the setting to be, and missed that networking.search was just below it. Truth be told it would make more sense for it to be under networking.resolvconf, but okay. Thank you!

3 Likes