Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NixOS /etc/hosts improvements #27804

Closed
wants to merge 2 commits into from

Conversation

aszlig
Copy link
Member

@aszlig aszlig commented Jul 31, 2017

The goal is to improve networking.hosts so that we have more control over whether to set the canonical hostname or aliases of it.

This was originally discussed in #27105 starting with this comment.

We really don't need to make exceptions for localhost in the generation
of the host entries if we feed the entries for localhost back into the
module system via the networking.hosts option itself.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
The order of the hosts does matter here, so instead of passing a list,
we can now also use an attribute set of "canonical" and "aliases"
options to specify what we exactly want.

I'm coercing the old form of specifying host entries (a plain list) to
the new form, although this is probably a bad idea, because we have no
real control over the canonical name and while it might be convenient to
just say 'networking.hosts."1.2.3.4" = [ "host1" "host2" ]' it doesn't
really merge well if "1.2.3.4" is already defined somewhere else.

So I'm not really sure whether we want to remove the list variant or use
a custom merging function to merge values into aliases if there's
another definition with a canonical hostname and use the first item if
there's no such definition.

Using such a merging function would probably confuse the hell out of our
users, so we might want to drop it soon.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
@edolstra
Copy link
Member

What are the use cases for this?

Worried that we're over-engineering /etc/hosts.

@aszlig
Copy link
Member Author

aszlig commented Jul 31, 2017

@edolstra: The main point here is to improve on mergability of the options defined in networking.hosts, because right now if you want to distinguish between the canonical host name and aliases, you have to use mkBefore to force a particular canonical hostname.

So let's say you have the following definition:

{
  networking.hosts."1.2.3.4" = [ "foo" "bar" ];
}

This leads to the canonical hostname foo and the alias bar. Now let's say you want to set the canonical host name to xyz and still keep aliases defined somewhere else, you could do something like this:

{ lib, ... }: {
  networking.hosts."1.2.3.4" = lib.mkBefore [ "xyz" ];
}

Now we have 1.2.3.4 xyz foo bar, but we'd need to use mkOrder 400 if we want to have another canonical hostname. If we want to replace the canonical name it gets even worse and we can only mkForce the whole definition.

@aszlig
Copy link
Member Author

aszlig commented Jul 31, 2017

@volth: What exactly are you referring to?

Edit: Ah, didn't see your comment on the referenced PR. That's the reason why I've added coercedTo to the type, so that it's possible to still use the list form instead. Right now the coercion here is rather simplistic and always uses the first element of the list as the canonical hostname.

So if there is some interest in this PR, the idea would be to merge the list form into aliases if a canonical name is already defined.

@mmahut
Copy link
Member

mmahut commented Aug 1, 2019

Any update on this pull request?

@aszlig
Copy link
Member Author

aszlig commented Aug 2, 2019

@mmahut: Hm, I guess I won't pursue this further, hence closing.

@aszlig aszlig closed this Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants