nixos: add option for bind to not resolve local queries (#29503)

When the user specifies the networking.nameservers setting in the
configuration file, it must take precedence over automatically
derived settings.

The culprit was services.bind that made the resolver set to
127.0.0.1 and ignore the nameserver setting.

This patch adds a flag to services.bind to override the nameserver
to localhost. It defaults to true. Setting this to false prevents the
service.bind and dnsmasq.resolveLocalQueries settings from
overriding the users' settings.

Also, when the user specifies a domain to search, it must be set in
the resolver configuration, even if the user does not specify any
nameservers.

(cherry picked from commit 670b4e29adc16e0a29aa5b4c126703dcca56aeb6)

This commit was accidentally merged to 17.09 but was intended for
master. This is the cherry-pick to master.

authored by gwitmond and committed by Franz Pletz bd52618c 38c14d71

+14 -3
+3 -1
nixos/modules/config/networking.nix
··· 9 9 cfg = config.networking; 10 10 dnsmasqResolve = config.services.dnsmasq.enable && 11 11 config.services.dnsmasq.resolveLocalQueries; 12 - hasLocalResolver = config.services.bind.enable || dnsmasqResolve; 12 + bindResolve = config.services.bind.enable && 13 + config.services.bind.resolveLocalQueries; 14 + hasLocalResolver = bindResolve || dnsmasqResolve; 13 15 14 16 resolvconfOptions = cfg.resolvconfOptions 15 17 ++ optional cfg.dnsSingleRequest "single-request"
+9
nixos/modules/services/networking/bind.nix
··· 151 151 "; 152 152 }; 153 153 154 + resolveLocalQueries = mkOption { 155 + type = types.bool; 156 + default = true; 157 + description = '' 158 + Whether bind should resolve local queries (i.e. add 127.0.0.1 to 159 + /etc/resolv.conf, overriding networking.nameserver). 160 + ''; 161 + }; 162 + 154 163 }; 155 164 156 165 };
+1 -1
nixos/modules/services/networking/dnsmasq.nix
··· 42 42 default = true; 43 43 description = '' 44 44 Whether dnsmasq should resolve local queries (i.e. add 127.0.0.1 to 45 - /etc/resolv.conf). 45 + /etc/resolv.conf overriding networking.nameservers). 46 46 ''; 47 47 }; 48 48
+1 -1
nixos/modules/tasks/network-interfaces-scripted.nix
··· 105 105 '' 106 106 # Set the static DNS configuration, if given. 107 107 ${pkgs.openresolv}/sbin/resolvconf -m 1 -a static <<EOF 108 - ${optionalString (cfg.nameservers != [] && cfg.domain != null) '' 108 + ${optionalString (cfg.domain != null) '' 109 109 domain ${cfg.domain} 110 110 ''} 111 111 ${optionalString (cfg.search != []) ("search " + concatStringsSep " " cfg.search)}