1 # /etc files related to networking, such as /etc/services.
3 { config, lib, pkgs, ... }:
9 cfg = config.networking.resolvconf;
11 resolvconfOptions = cfg.extraOptions
12 ++ optional cfg.dnsSingleRequest "single-request"
13 ++ optional cfg.dnsExtensionMechanism "edns0";
17 # This is the default, but we must set it here to prevent
18 # a collision with an apparently unrelated environment
19 # variable with the same name exported by dhcpcd.
20 interface_order='lo lo[0-9]*'
21 '' + optionalString config.services.nscd.enable ''
22 # Invalidate the nscd cache whenever resolv.conf is
24 libc_restart='/run/current-system/systemd/bin/systemctl try-restart --no-block nscd.service 2> /dev/null'
25 '' + optionalString (length resolvconfOptions > 0) ''
26 # Options as described in resolv.conf(5)
27 resolv_conf_options='${concatStringsSep " " resolvconfOptions}'
28 '' + optionalString cfg.useLocalResolver ''
29 # This hosts runs a full-blown DNS resolver.
30 name_servers='127.0.0.1'
37 (mkRenamedOptionModule [ "networking" "dnsSingleRequest" ] [ "networking" "resolvconf" "dnsSingleRequest" ])
38 (mkRenamedOptionModule [ "networking" "dnsExtensionMechanism" ] [ "networking" "resolvconf" "dnsExtensionMechanism" ])
39 (mkRenamedOptionModule [ "networking" "extraResolvconfConf" ] [ "networking" "resolvconf" "extraConfig" ])
40 (mkRenamedOptionModule [ "networking" "resolvconfOptions" ] [ "networking" "resolvconf" "extraOptions" ])
41 (mkRemovedOptionModule [ "networking" "resolvconf" "useHostResolvConf" ] "This option was never used for anything anyways")
46 networking.resolvconf = {
50 default = !(config.environment.etc ? "resolv.conf");
51 defaultText = literalExpression ''!(config.environment.etc ? "resolv.conf")'';
52 description = lib.mdDoc ''
53 Whether DNS configuration is managed by resolvconf.
59 default = pkgs.openresolv;
60 defaultText = literalExpression "pkgs.openresolv";
61 description = lib.mdDoc ''
62 The package that provides the system-wide resolvconf command. Defaults to `openresolv`
63 if this module is enabled. Otherwise, can be used by other modules (for example {option}`services.resolved`) to
64 provide a compatibility layer.
66 This option generally shouldn't be set by the user.
70 dnsSingleRequest = lib.mkOption {
73 description = lib.mdDoc ''
74 Recent versions of glibc will issue both ipv4 (A) and ipv6 (AAAA)
75 address queries at the same time, from the same port. Sometimes upstream
76 routers will systemically drop the ipv4 queries. The symptom of this problem is
77 that 'getent hosts example.com' only returns ipv6 (or perhaps only ipv4) addresses. The
78 workaround for this is to specify the option 'single-request' in
79 /etc/resolv.conf. This option enables that.
83 dnsExtensionMechanism = mkOption {
86 description = lib.mdDoc ''
87 Enable the `edns0` option in {file}`resolv.conf`. With
88 that option set, `glibc` supports use of the extension mechanisms for
89 DNS (EDNS) specified in RFC 2671. The most popular user of that feature is DNSSEC,
90 which does not work without it.
94 extraConfig = mkOption {
98 description = lib.mdDoc ''
99 Extra configuration to append to {file}`resolvconf.conf`.
103 extraOptions = mkOption {
104 type = types.listOf types.str;
106 example = [ "ndots:1" "rotate" ];
107 description = lib.mdDoc ''
108 Set the options in {file}`/etc/resolv.conf`.
112 useLocalResolver = mkOption {
115 description = lib.mdDoc ''
116 Use local DNS server for resolving.
126 environment.etc."resolvconf.conf".text =
128 # Force-stop any attempts to use resolvconf
130 echo "resolvconf is disabled on this system but was used anyway:" >&2
136 environment.systemPackages = [ cfg.package ];
140 networking.resolvconf.package = pkgs.openresolv;
142 systemd.services.resolvconf = {
143 description = "resolvconf update";
145 before = [ "network-pre.target" ];
146 wants = [ "network-pre.target" ];
147 wantedBy = [ "multi-user.target" ];
148 restartTriggers = [ config.environment.etc."resolvconf.conf".source ];
152 ExecStart = "${cfg.package}/bin/resolvconf -u";
153 RemainAfterExit = true;