A fast way for modifying /etc/hosts using "networking.extraHosts"

Hello,

In case I need to modify my /etc/hosts I use the main configuration.nix file but the problem with this file it will rebuild the whole system again and that might take too much time depending on your configuration… Is there a fast way to just modify /etc/hosts directly using nix or any other way ?

1 Like

In theory, you could use dnsmasq in such a way that it reads a hosts
file from a writable place, which you could then apply by only reloading
dnsmasq.

Keyword is addn-hosts.

1 Like

If you set environment.etc.hosts.mode = "0644";, you can modify the file as root. Note that changes made in this way will be discarded when switching configurations. I used this to make vagrant’s hostmanager work though, and it worked pretty smoothly.

10 Likes