From f9ec52dedceb3904b49c27d49076a881c43ba4cf Mon Sep 17 00:00:00 2001 From: Valentin Shirokov Date: Tue, 4 Jul 2017 01:58:48 +0300 Subject: 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(-) (limited to 'nixos/modules/config/networking.nix') diff --git a/nixos/modules/config/networking.nix b/nixos/modules/config/networking.nix index d503f5a8b20e..ea9e8b712c68 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} ''; -- cgit 1.4.1 From 5f2826fbed5ee26fb905f3950c2d7c5631933ba3 Mon Sep 17 00:00:00 2001 From: Valentin Shirokov Date: Sat, 8 Jul 2017 21:13:16 +0300 Subject: Added networking.hosts and networking.fqdn options --- nixos/modules/config/networking.nix | 47 ++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 11 deletions(-) (limited to 'nixos/modules/config/networking.nix') diff --git a/nixos/modules/config/networking.nix b/nixos/modules/config/networking.nix index ea9e8b712c68..c0b0c8494c84 100644 --- a/nixos/modules/config/networking.nix +++ b/nixos/modules/config/networking.nix @@ -20,24 +20,35 @@ in options = { - networking.extraLocalHosts = lib.mkOption { - type = types.listOf types.str; - default = []; - example = [ "localhost.localdomain" "workinprogress.example.com" ]; + networking.fqdn = lib.mkOption { + type = types.nullOr types.str; + default = null; + example = "foo.example.com"; description = '' - Additional entries to be appended to 127.0.0.1 entry in /etc/hosts. + Full qualified domain name, if any. ''; }; + networking.hosts = lib.mkOption { + type = types.attrsOf ( types.listOf types.str ); + default = {}; + example = '' + { + "localhost" = [ "foo.bar" ]; + "192.168.0.2" = [ "fileserver.local" "nameserver.local" ]; + }; + ''; + description = '' + Locally defined maps of IP addresses to hostnames' + ''; + }; 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. + Additional verbatim entries to be appended to /etc/hosts. ''; }; @@ -199,12 +210,26 @@ in "rpc".source = pkgs.glibc.out + "/etc/rpc"; # /etc/hosts: Hostname-to-IP mappings. - "hosts".text = let foo = concatStringsSep " " cfg.extraLocalHosts; in + "hosts".text = + let oneToString = set : ip : ip + " " + concatStringsSep " " ( getAttr ip set ); + allToString = set : concatStringsSep "\n" ( map ( oneToString set ) ( builtins.attrNames set )); + userLocalHosts = + if builtins.hasAttr "127.0.0.1" cfg.hosts + then concatStringsSep " " ( filter (x : x != "localhost" ) ( getAttr "127.0.0.1" cfg.hosts)) + else ""; + userLocalHosts6 = + if builtins.hasAttr "::1" cfg.hosts + then concatStringsSep " " ( filter (x : x != "localhost" ) ( getAttr "::1" cfg.hosts)) + else ""; + otherHosts = allToString ( removeAttrs cfg.hosts [ "127.0.0.1" "::1" ]); + maybeFQDN = if cfg.fqdn == null then "" else cfq.fqdn; + in '' - 127.0.0.1 localhost ${foo} + 127.0.0.1 ${maybeFQDN} ${userLocalHosts} localhost ${optionalString cfg.enableIPv6 '' - ::1 localhost ${foo} + ::1 ${maybeFQDN} ${userLocalHosts6} localhost ''} + ${otherHosts} ${cfg.extraHosts} ''; -- cgit 1.4.1 From ca54c3f1aaea5b2a32c9add3e1b619066a46e29a Mon Sep 17 00:00:00 2001 From: Valentin Shirokov Date: Sat, 8 Jul 2017 22:30:02 +0300 Subject: Typo fix --- nixos/modules/config/networking.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nixos/modules/config/networking.nix') diff --git a/nixos/modules/config/networking.nix b/nixos/modules/config/networking.nix index c0b0c8494c84..7065368f7153 100644 --- a/nixos/modules/config/networking.nix +++ b/nixos/modules/config/networking.nix @@ -25,7 +25,7 @@ in default = null; example = "foo.example.com"; description = '' - Full qualified domain name, if any. + Fully qualified domain name, if any. ''; }; -- cgit 1.4.1 From 396db6493d63352394d0f94cf8d939de637517d7 Mon Sep 17 00:00:00 2001 From: Valentin Shirokov Date: Sat, 8 Jul 2017 23:04:47 +0300 Subject: Style adjustments Also dangerous typo fix --- nixos/modules/config/networking.nix | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'nixos/modules/config/networking.nix') diff --git a/nixos/modules/config/networking.nix b/nixos/modules/config/networking.nix index 7065368f7153..d0e5b35e42e8 100644 --- a/nixos/modules/config/networking.nix +++ b/nixos/modules/config/networking.nix @@ -213,16 +213,14 @@ in "hosts".text = let oneToString = set : ip : ip + " " + concatStringsSep " " ( getAttr ip set ); allToString = set : concatStringsSep "\n" ( map ( oneToString set ) ( builtins.attrNames set )); - userLocalHosts = - if builtins.hasAttr "127.0.0.1" cfg.hosts - then concatStringsSep " " ( filter (x : x != "localhost" ) ( getAttr "127.0.0.1" cfg.hosts)) - else ""; - userLocalHosts6 = - if builtins.hasAttr "::1" cfg.hosts - then concatStringsSep " " ( filter (x : x != "localhost" ) ( getAttr "::1" cfg.hosts)) - else ""; + userLocalHosts = optionalString + ( builtins.hasAttr "127.0.0.1" cfg.hosts ) + ( concatStringsSep " " ( filter (x : x != "localhost" ) ( getAttr "127.0.0.1" cfg.hosts))); + userLocalHosts6 = optionalString + ( builtins.hasAttr "::1" cfg.hosts ) + ( concatStringsSep " " ( filter (x : x != "localhost" ) ( getAttr "::1" cfg.hosts))); otherHosts = allToString ( removeAttrs cfg.hosts [ "127.0.0.1" "::1" ]); - maybeFQDN = if cfg.fqdn == null then "" else cfq.fqdn; + maybeFQDN = optionalString ( cfg.fqdn != null ) cfg.fqdn; in '' 127.0.0.1 ${maybeFQDN} ${userLocalHosts} localhost -- cgit 1.4.1 From 2f9799399255bdacc028092b904f6ea0afc7a09a Mon Sep 17 00:00:00 2001 From: Valentin Shirokov Date: Sun, 9 Jul 2017 00:28:05 +0300 Subject: Documentation fixes --- nixos/modules/config/networking.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nixos/modules/config/networking.nix') diff --git a/nixos/modules/config/networking.nix b/nixos/modules/config/networking.nix index d0e5b35e42e8..760f8353fb30 100644 --- a/nixos/modules/config/networking.nix +++ b/nixos/modules/config/networking.nix @@ -34,12 +34,12 @@ in default = {}; example = '' { - "localhost" = [ "foo.bar" ]; + "127.0.0.1" = [ "foo.bar.baz" ]; "192.168.0.2" = [ "fileserver.local" "nameserver.local" ]; }; ''; description = '' - Locally defined maps of IP addresses to hostnames' + Locally defined maps of hostnames to IP addresses. ''; }; -- cgit 1.4.1 From 163393865fd4828842f956d603c1c83fe6ab08b2 Mon Sep 17 00:00:00 2001 From: Valentin Shirokov Date: Sun, 9 Jul 2017 08:56:36 +0300 Subject: Style optimizations --- nixos/modules/config/networking.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'nixos/modules/config/networking.nix') diff --git a/nixos/modules/config/networking.nix b/nixos/modules/config/networking.nix index 760f8353fb30..6035facb594e 100644 --- a/nixos/modules/config/networking.nix +++ b/nixos/modules/config/networking.nix @@ -212,13 +212,13 @@ in # /etc/hosts: Hostname-to-IP mappings. "hosts".text = let oneToString = set : ip : ip + " " + concatStringsSep " " ( getAttr ip set ); - allToString = set : concatStringsSep "\n" ( map ( oneToString set ) ( builtins.attrNames set )); + allToString = set : concatMapStringsSep "\n" ( oneToString set ) ( attrNames set ); userLocalHosts = optionalString ( builtins.hasAttr "127.0.0.1" cfg.hosts ) - ( concatStringsSep " " ( filter (x : x != "localhost" ) ( getAttr "127.0.0.1" cfg.hosts))); + ( concatStringsSep " " ( remove "localhost" cfg.hosts."127.0.0.1" )); userLocalHosts6 = optionalString ( builtins.hasAttr "::1" cfg.hosts ) - ( concatStringsSep " " ( filter (x : x != "localhost" ) ( getAttr "::1" cfg.hosts))); + ( concatStringsSep " " ( remove "localhost" cfg.hosts."::1" )); otherHosts = allToString ( removeAttrs cfg.hosts [ "127.0.0.1" "::1" ]); maybeFQDN = optionalString ( cfg.fqdn != null ) cfg.fqdn; in -- cgit 1.4.1 From d29fc731b3d97959331322d2ff787e665e7d6342 Mon Sep 17 00:00:00 2001 From: Valentin Shirokov Date: Sun, 9 Jul 2017 23:12:57 +0300 Subject: Example of networking.hosts is now literalExample --- nixos/modules/config/networking.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nixos/modules/config/networking.nix') diff --git a/nixos/modules/config/networking.nix b/nixos/modules/config/networking.nix index 6035facb594e..3a643943d3d4 100644 --- a/nixos/modules/config/networking.nix +++ b/nixos/modules/config/networking.nix @@ -32,7 +32,7 @@ in networking.hosts = lib.mkOption { type = types.attrsOf ( types.listOf types.str ); default = {}; - example = '' + example = literalExample '' { "127.0.0.1" = [ "foo.bar.baz" ]; "192.168.0.2" = [ "fileserver.local" "nameserver.local" ]; -- cgit 1.4.1 From 635ecd802fd1928db0b33b396744b620c7b82ffe Mon Sep 17 00:00:00 2001 From: Valentin Shirokov Date: Fri, 28 Jul 2017 00:15:17 +0300 Subject: Deprecation warning for networking.extraHosts --- nixos/modules/config/networking.nix | 3 +++ 1 file changed, 3 insertions(+) (limited to 'nixos/modules/config/networking.nix') diff --git a/nixos/modules/config/networking.nix b/nixos/modules/config/networking.nix index 3a643943d3d4..055e45e4a51a 100644 --- a/nixos/modules/config/networking.nix +++ b/nixos/modules/config/networking.nix @@ -199,6 +199,9 @@ in config = { + warnings = optional (cfg.extraHosts != "") + "networking.extraHosts is deprecated, please use networking.hosts instead"; + environment.etc = { # /etc/services: TCP/UDP port assignments. "services".source = pkgs.iana-etc + "/etc/services"; -- cgit 1.4.1