Added networking.hosts and networking.fqdn options
This commit is contained in:
parent
f9ec52dedc
commit
5f2826fbed
@ -20,24 +20,35 @@ in
|
|||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
networking.extraLocalHosts = lib.mkOption {
|
networking.fqdn = lib.mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.nullOr types.str;
|
||||||
default = [];
|
default = null;
|
||||||
example = [ "localhost.localdomain" "workinprogress.example.com" ];
|
example = "foo.example.com";
|
||||||
description = ''
|
description = ''
|
||||||
Additional entries to be appended to 127.0.0.1 entry in <filename>/etc/hosts</filename>.
|
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 {
|
networking.extraHosts = lib.mkOption {
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
default = "";
|
default = "";
|
||||||
example = "192.168.0.1 lanlocalhost";
|
example = "192.168.0.1 lanlocalhost";
|
||||||
description = ''
|
description = ''
|
||||||
Additional entries to be appended to <filename>/etc/hosts</filename>.
|
Additional verbatim entries to be appended to <filename>/etc/hosts</filename>.
|
||||||
Note that entries for 127.0.0.1 will not always work correctly if added from here.
|
|
||||||
They should be added via <literal>networking.extraLocalHosts</literal>.
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -199,12 +210,26 @@ in
|
|||||||
"rpc".source = pkgs.glibc.out + "/etc/rpc";
|
"rpc".source = pkgs.glibc.out + "/etc/rpc";
|
||||||
|
|
||||||
# /etc/hosts: Hostname-to-IP mappings.
|
# /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 ''
|
${optionalString cfg.enableIPv6 ''
|
||||||
::1 localhost ${foo}
|
::1 ${maybeFQDN} ${userLocalHosts6} localhost
|
||||||
''}
|
''}
|
||||||
|
${otherHosts}
|
||||||
${cfg.extraHosts}
|
${cfg.extraHosts}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user