nixpkgs/nixos/modules/config
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
..
fonts treewide: add types to boolean / enable options or make use of mkEnableOption 2020-04-27 09:32:01 +02:00
gtk gtk-icon-cache: get native gtk3 for icon cache 2020-03-06 00:45:48 -05:00
krb5 treewide: remove redundant quotes 2019-08-26 21:40:19 +00:00
xdg nixos: add freedesktop/gnome/myself maintainers 2020-04-01 20:53:09 -04:00
appstream.nix nixos: add AppStream module 2018-12-04 20:26:25 +00:00
console.nix nixos/console: set colors using kernel parameters 2019-12-20 00:27:35 +01:00
debug-info.nix
gnu.nix treewide: isArm -> isAarch32 2018-04-25 15:28:55 -04:00
i18n.nix treewide: use attrs instead of list for types.loaOf options 2020-01-06 10:39:18 -05:00
iproute2.nix alternative for iproute module (#41801) 2018-09-01 20:28:23 +02:00
ldap.nix nixos/ldap: move nss database configuration into ldap module 2020-05-11 16:14:50 +02:00
locale.nix timezone.nix -> locale.nix 2019-08-12 11:56:40 -04:00
malloc.nix treewide: remove redundant rec 2019-08-28 11:07:32 +00:00
networking.nix nixos/networking: Add the FQDN and hostname to /etc/hosts 2020-05-25 14:06:25 +02:00
no-x-libs.nix pinentry: build with multiple outputs in single drv 2019-10-16 20:30:52 -04:00
nsswitch.nix nixos/nsswitch: improve error message 2020-05-11 16:14:51 +02:00
power-management.nix nixos/power-management: always run systemctl of the currently running systemd 2020-05-21 10:28:29 +02:00
pulseaudio.nix nixos/pulseaudio: Enable udev rules 2020-02-07 15:54:35 -06:00
qt5.nix nixos/qt5: support adwaita-dark theme 2020-04-05 08:38:08 +03:00
resolvconf.nix nixos/resolvconf: always run systemctl of the currently running systemd 2020-05-21 10:29:22 +02:00
shells-environment.nix nixos: default environment.homeBinInPath to false 2019-11-26 12:44:12 +01:00
swap.nix swap: depend on rngd if enabled and randomEncryption is configured to 2020-02-08 12:26:09 +01:00
sysctl.nix nixos/sysctl: reduce prio of "kernel.kptr_restrict" to mkDefault 2019-09-26 10:09:31 +01:00
system-environment.nix nixos/system-environment: prepend wrapperDir to PATH (#70430) 2019-10-15 13:17:38 +02:00
system-path.nix nixos: add /share/hunspell to environment.pathsToLink 2020-02-17 03:35:06 +01:00
terminfo.nix nixos/terminfo: use profileRelativeSessionVariables 2019-09-18 11:13:42 -04:00
unix-odbc-drivers.nix Fix documentation typo 2019-10-09 19:43:12 +09:00
update-users-groups.pl nixos/users: Increase maximum system uid/gid from 499 to 999 2019-10-14 01:59:19 +02:00
users-groups.nix nixos/treewide: Move rename.nix imports to their respective modules 2019-12-10 02:51:19 +01:00
vte.nix nixos: add freedesktop/gnome/myself maintainers 2020-04-01 20:53:09 -04:00
zram.nix nixos/zram: make zstd the default (#87917) 2020-05-21 21:30:03 +03:00