networkmanager: Add option for appending DNS settings

If the option is enabled, the DNS servers from networking.nameservers
will be inserted in /etc/resolv.conf after the DNS servers that
NetworkManager receieves by DHCP, or that is configured manually
in the connection settings.
This commit is contained in:
Rickard Nilsson 2013-08-20 13:36:01 +02:00
parent 71a21704dc
commit 1ff7584a30

View File

@ -46,8 +46,8 @@ let
overrideNameserversScript = writeScript "02overridedns" '' overrideNameserversScript = writeScript "02overridedns" ''
#!/bin/sh #!/bin/sh
${pkgs.gnused}/bin/sed -i '/nameserver /d' /etc/resolv.conf ${optionalString cfg.overrideNameservers "${gnused}/bin/sed -i '/nameserver /d' /etc/resolv.conf"}
${pkgs.lib.concatStringsSep ";" (map (s: "echo 'nameserver ${s}' >> /etc/resolv.conf") config.networking.nameservers)} ${concatStringsSep ";" (map (s: "echo 'nameserver ${s}' >> /etc/resolv.conf") config.networking.nameservers)}
''; '';
in { in {
@ -84,7 +84,18 @@ in {
description = '' description = ''
If enabled, any nameservers received by DHCP or configured in If enabled, any nameservers received by DHCP or configured in
NetworkManager will be replaced by the nameservers configured NetworkManager will be replaced by the nameservers configured
in the <literal>networking.nameservers</literal> option. in the <literal>networking.nameservers</literal> option. This
option overrides the <literal>appendNameservers</literal> option
if both are enabled.
'';
};
appendNameservers = mkOption {
default = false;
description = ''
If enabled, the name servers configured in the
<literal>networking.nameservers</literal> option will be appended
to the ones configured in NetworkManager or received by DHCP.
''; '';
}; };
@ -117,7 +128,7 @@ in {
{ source = "${networkmanager_openconnect}/etc/NetworkManager/VPN/nm-openconnect-service.name"; { source = "${networkmanager_openconnect}/etc/NetworkManager/VPN/nm-openconnect-service.name";
target = "NetworkManager/VPN/nm-openconnect-service.name"; target = "NetworkManager/VPN/nm-openconnect-service.name";
} }
] ++ pkgs.lib.optional cfg.overrideNameservers ] ++ pkgs.lib.optional (cfg.overrideNameservers || cfg.appendNameservers)
{ source = overrideNameserversScript; { source = overrideNameserversScript;
target = "NetworkManager/dispatcher.d/02overridedns"; target = "NetworkManager/dispatcher.d/02overridedns";
}; };