From f9ec52dedceb3904b49c27d49076a881c43ba4cf Mon Sep 17 00:00:00 2001 From: Valentin Shirokov Date: Tue, 4 Jul 2017 01:58:48 +0300 Subject: [PATCH] Added networking.extraLocalHosts option It adds its contents to '127.0.0.1' line of /etc/hosts It makes possible to point multiple domains to localhost in correct way --- nixos/modules/config/networking.nix | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/nixos/modules/config/networking.nix b/nixos/modules/config/networking.nix index d503f5a8b20..ea9e8b712c6 100644 --- a/nixos/modules/config/networking.nix +++ b/nixos/modules/config/networking.nix @@ -20,12 +20,24 @@ in options = { + networking.extraLocalHosts = lib.mkOption { + type = types.listOf types.str; + default = []; + example = [ "localhost.localdomain" "workinprogress.example.com" ]; + description = '' + Additional entries to be appended to 127.0.0.1 entry in /etc/hosts. + ''; + }; + + networking.extraHosts = lib.mkOption { type = types.lines; default = ""; example = "192.168.0.1 lanlocalhost"; description = '' Additional entries to be appended to /etc/hosts. + Note that entries for 127.0.0.1 will not always work correctly if added from here. + They should be added via networking.extraLocalHosts. ''; }; @@ -187,11 +199,11 @@ in "rpc".source = pkgs.glibc.out + "/etc/rpc"; # /etc/hosts: Hostname-to-IP mappings. - "hosts".text = + "hosts".text = let foo = concatStringsSep " " cfg.extraLocalHosts; in '' - 127.0.0.1 localhost + 127.0.0.1 localhost ${foo} ${optionalString cfg.enableIPv6 '' - ::1 localhost + ::1 localhost ${foo} ''} ${cfg.extraHosts} '';