networking.extraHosts vs networking.hosts

What is the difference between the following two options exactly?

  1. networking.extraHosts
    • used in the official manual and wiki to configure the /etc/hosts file → seems to be prefered
  2. networking.hosts
    • is more declarative since it does not define verbatim strings to append → cleaner

For example, let’s say I want to hardcode the name resolution of a server (the host where this configuration is applied) with a public IP. Why isn’t the second options used for this in the manual/wiki?

In the manual networking.extraHosts is just an example of how a multiline string is used in nix, the wiki is unofficial and is mostly done by people adding stuff that resolved their problems and not really what’s recommended.

The only real difference other than the syntax is that networking.hosts entries have a higher priority than the ones in networking.extraHosts.

2 Likes