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/networking: add hostname to /etc/hosts by default #36261

Closed
wants to merge 3 commits into from

Conversation

kragniz
Copy link
Member

@kragniz kragniz commented Mar 3, 2018

Motivation for this change

I'm testing some kubernetes related stuff, and it's assumed in a bunch of places that the hostname is resolvable. I could add this with networking.extraHosts, but I think it should be the default. See #1248 for some past discussion.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@kragniz
Copy link
Member Author

kragniz commented Mar 3, 2018

/cc @peti

@@ -213,6 +213,10 @@ in
otherHosts = allToString ( removeAttrs cfg.hosts [ "127.0.0.1" "::1" ]);
in
''
127.0.0.1 ${cfg.hostName}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be possible to disable this behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any ideas for the disable config option name?

@kragniz
Copy link
Member Author

kragniz commented Mar 3, 2018

I added a new option, networking.hostnameInHosts, which defaults to true

@kragniz
Copy link
Member Author

kragniz commented Mar 3, 2018

I'm not especially fond of that option name, though

@oxij
Copy link
Member

oxij commented Mar 4, 2018

You shouldn't use "127.0.0.1" for that, see #1248 (comment). Other than that, I 👍 this. Should have been the default ages ago.

@kragniz
Copy link
Member Author

kragniz commented Mar 4, 2018

Good spot, I've changed it to point at 127.0.1.1 now

@Mic92
Copy link
Member

Mic92 commented Mar 4, 2018

So kubernetes does not use nscd?

@@ -213,6 +221,12 @@ in
otherHosts = allToString ( removeAttrs cfg.hosts [ "127.0.0.1" "::1" ]);
in
''
${optionalString cfg.hostnameInHosts ''
127.0.1.1 ${cfg.hostName}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oxij
Copy link
Member

oxij commented Jun 11, 2018

@kragniz ping!

@oxij
Copy link
Member

oxij commented Jun 11, 2018

@danbst why would you want to set it to empty string, btw?

@danbst
Copy link
Contributor

danbst commented Jun 19, 2018

@oxij See https://github.com/NixOS/nixpkgs/blob/release-18.03/nixos/modules/tasks/network-interfaces.nix#L374-L375

        The name of the machine.  Leave it empty if you want to obtain
        it from a DHCP server (if using DHCP).

So technically someone may have used hostName = ""; to enabled DHCP based hostname. Personally, I don't do this.

@AndreaOrru
Copy link

What's the status of this? It breaks i.e. RabbitMQ by default.

@oxij
Copy link
Member

oxij commented Sep 3, 2018 via email

@kragniz
Copy link
Member Author

kragniz commented Sep 5, 2018

I'll update this by the end of the week

@oxij
Copy link
Member

oxij commented Sep 23, 2018

See #47241.

oxij added a commit to oxij/nixpkgs that referenced this pull request Oct 2, 2018
We use `127.0.1.1` instead of `127.0.0.1` because some applications will fail if
`127.0.0.1` resolves to something other than `localhost`.

Debian does the same.

See NixOS#1248 and NixOS#36261.
@c0bw3b
Copy link
Contributor

c0bw3b commented Oct 27, 2018

Closing: superseded by #47241

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

8 participants