nixpkgs/nixos/modules
Michael Weiss 234d95a6fc
nixos/networking: Add the FQDN and hostname to /etc/hosts
This fixes the output of "hostname --fqdn" (previously the domain name
was not appended). Additionally it's now possible to use the FQDN.

This works by unconditionally adding two entries to /etc/hosts:
127.0.0.1 localhost
::1 localhost

These are the first two entries and therefore gethostbyaddr() will
always resolve "127.0.0.1" and "::1" back to "localhost" [0].
This works because nscd (or rather the nss-files module) returns the
first matching row from /etc/hosts (and ignores the rest).

The FQDN and hostname entries are appended later to /etc/hosts, e.g.:
127.0.0.2 nixos-unstable.test.tld nixos-unstable
::1 nixos-unstable.test.tld nixos-unstable
Note: We use 127.0.0.2 here to follow nss-myhostname (systemd) as close
as possible. This has the advantage that 127.0.0.2 can be resolved back
to the FQDN but also the drawback that applications that only listen to
127.0.0.1 (and not additionally ::1) cannot be reached via the FQDN.
If you would like this to work you can use the following configuration:
```nix
networking.hosts."127.0.0.1" = [
  "${config.networking.hostName}.${config.networking.domain}"
  config.networking.hostName
];
```

Therefore gethostbyname() resolves "nixos-unstable" to the FQDN
(canonical name): "nixos-unstable.test.tld".

Advantages over the previous behaviour:
- The FQDN will now also be resolved correctly (the entry was missing).
- E.g. the command "hostname --fqdn" will now work as expected.
Drawbacks:
- Overrides entries form the DNS (an issue if e.g. $FQDN should resolve
  to the public IP address instead of 127.0.0.1)
  - Note: This was already partly an issue as there's an entry for
    $HOSTNAME (without the domain part) that resolves to
    127.0.1.1 (!= 127.0.0.1).
- Unknown (could potentially cause other unexpected issues, but special
  care was taken).

[0]: Some applications do apparently depend on this behaviour (see
c578924) and this is typically the expected behaviour.

Co-authored-by: Florian Klink <flokli@flokli.de>
2020-05-25 14:06:25 +02:00
..
config nixos/networking: Add the FQDN and hostname to /etc/hosts 2020-05-25 14:06:25 +02:00
hardware Merge pull request #73530 from eadwu/nvidia/systemd-pm 2020-05-12 13:54:45 +02:00
i18n/input-method Revert "ibus: fix dconf db installation" 2020-04-24 18:22:59 -04:00
installer Merge pull request #85996 from misuzu/nixos-install-low-memory 2020-05-08 18:40:24 +03:00
misc Update link in /etc/os-release (#85723) 2020-04-22 00:16:22 +02:00
profiles Merge pull request #74378 from ttuegel/lxc-container 2020-04-25 16:25:15 +02:00
programs Merge pull request #86643 from asbachb/zsh-bash-autocomplete 2020-05-19 11:57:25 +02:00
security Merge pull request #87016 from flokli/nsswitch-cleanup 2020-05-14 14:55:43 +02:00
services Merge pull request #75435 from Elyhaka/fprintd 2020-05-25 12:22:48 +02:00
system nixos/binfmt: move systemd-binfmt.service to binfmt module 2020-05-18 11:18:44 +02:00
tasks nixos/scripted-networking: use udev to configure link MACAddress and MTUBytes 2020-05-22 10:58:00 +02:00
testing nixos/service-runner.nix: Allow quotes in commands + test 2020-02-28 14:26:29 +01:00
virtualisation nixos/cri-o: default to upstream pause 2020-05-25 12:27:49 +02:00
module-list.nix Merge pull request #82753 from Kloenk/feature/engelsystem 2020-05-24 16:31:23 +02:00
rename.nix rkt: remove 2020-05-16 09:23:07 +10:00