networkmanager: Add option for overriding DNS settings

If the option is enabled, the DNS servers from networking.nameservers
will be inserted in /etc/resolv.con and override any 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-16 00:35:57 +02:00
parent f7d11af98a
commit e36e979d38

View File

@ -44,31 +44,50 @@ let
fi fi
''; '';
overrideNameserversScript = writeScript "02overridedns" ''
#!/bin/sh
${pkgs.gnused}/bin/sed -i '/nameserver /d' /etc/resolv.conf
${pkgs.lib.concatStringsSep ";" (map (s: "echo 'nameserver ${s}' >> /etc/resolv.conf") config.networking.nameservers)}
'';
in { in {
###### interface ###### interface
options = { options = {
networking.networkmanager.enable = mkOption { networking.networkmanager = {
default = false;
merge = mergeEnableOption; enable = mkOption {
description = '' default = false;
Whether to use NetworkManager to obtain an IP address and other merge = mergeEnableOption;
configuration for all network interfaces that are not manually description = ''
configured. If enabled, a group <literal>networkmanager</literal> Whether to use NetworkManager to obtain an IP address and other
will be created. Add all users that should have permission configuration for all network interfaces that are not manually
to change network settings to this group. configured. If enabled, a group <literal>networkmanager</literal>
''; will be created. Add all users that should have permission
}; to change network settings to this group.
'';
};
packages = mkOption {
default = [ ];
description = ''
Extra packages that provide NetworkManager plugins.
'';
merge = mergeListOption;
apply = list: [ networkmanager modemmanager wpa_supplicant ] ++ list;
};
overrideNameservers = mkOption {
default = false;
description = ''
If enabled, any nameservers received by DHCP or configured in
NetworkManager will be replaced by the nameservers configured
in the <literal>networking.nameservers</literal> option.
'';
};
networking.networkmanager.packages = mkOption {
default = [ ];
description = ''
Extra packages that provide NetworkManager plugins.
'';
merge = mergeListOption;
apply = list: [ networkmanager modemmanager wpa_supplicant ] ++ list;
}; };
}; };
@ -98,7 +117,10 @@ 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
{ source = overrideNameserversScript;
target = "NetworkManager/dispatcher.d/02overridedns";
};
environment.systemPackages = cfg.packages ++ [ environment.systemPackages = cfg.packages ++ [
networkmanager_openvpn networkmanager_openvpn