diff --git a/modules/config/networking.nix b/modules/config/networking.nix index 076b9801a54b..8343912d8303 100644 --- a/modules/config/networking.nix +++ b/modules/config/networking.nix @@ -2,7 +2,9 @@ {config, pkgs, ...}: +with pkgs.lib; let + cfg = config.networking; options = { @@ -16,6 +18,13 @@ let }; + localhostWithDomain = optionalString (cfg.domain != "") + "localhost.${cfg.domain}"; + + hostnameWithDomain = optionalString + (cfg.domain != "" && cfg.hostName != "") + "${cfg.hostName}.${cfg.domain}"; + in { @@ -40,11 +49,10 @@ in { # /etc/hosts: Hostname-to-IP mappings. source = pkgs.writeText "hosts" '' - ${config.networking.extraHosts} - ${if config.networking.hostName != "" - then "127.0.0.1 ${config.networking.hostName}" - else ""} - 127.0.0.1 localhost + ${cfg.extraHosts} + ${optionalString (cfg.hostName != "") + "127.0.0.1 ${cfg.hostName} ${hostnameWithDomain}"} + 127.0.0.1 localhost ${localhostWithDomain} ''; target = "hosts"; }