1 # /etc files related to networking, such as /etc/services.
2 { config, lib, pkgs, ... }:
5 cfg = config.networking.resolvconf;
7 resolvconfOptions = cfg.extraOptions
8 ++ lib.optional cfg.dnsSingleRequest "single-request"
9 ++ lib.optional cfg.dnsExtensionMechanism "edns0"
10 ++ lib.optional cfg.useLocalResolver "trust-ad";
14 # This is the default, but we must set it here to prevent
15 # a collision with an apparently unrelated environment
16 # variable with the same name exported by dhcpcd.
17 interface_order='lo lo[0-9]*'
18 '' + lib.optionalString config.services.nscd.enable ''
19 # Invalidate the nscd cache whenever resolv.conf is
21 libc_restart='/run/current-system/systemd/bin/systemctl try-restart --no-block nscd.service 2> /dev/null'
22 '' + lib.optionalString (lib.length resolvconfOptions > 0) ''
23 # Options as described in resolv.conf(5)
24 resolv_conf_options='${lib.concatStringsSep " " resolvconfOptions}'
25 '' + lib.optionalString cfg.useLocalResolver ''
26 # This hosts runs a full-blown DNS resolver.
27 name_servers='127.0.0.1${lib.optionalString config.networking.enableIPv6 " ::1"}'
34 (lib.mkRenamedOptionModule [ "networking" "dnsSingleRequest" ] [ "networking" "resolvconf" "dnsSingleRequest" ])
35 (lib.mkRenamedOptionModule [ "networking" "dnsExtensionMechanism" ] [ "networking" "resolvconf" "dnsExtensionMechanism" ])
36 (lib.mkRenamedOptionModule [ "networking" "extraResolvconfConf" ] [ "networking" "resolvconf" "extraConfig" ])
37 (lib.mkRenamedOptionModule [ "networking" "resolvconfOptions" ] [ "networking" "resolvconf" "extraOptions" ])
38 (lib.mkRemovedOptionModule [ "networking" "resolvconf" "useHostResolvConf" ] "This option was never used for anything anyways")
43 networking.resolvconf = {
45 enable = lib.mkOption {
46 type = lib.types.bool;
47 default = !(config.environment.etc ? "resolv.conf");
48 defaultText = lib.literalExpression ''!(config.environment.etc ? "resolv.conf")'';
50 Whether DNS configuration is managed by resolvconf.
54 package = lib.mkOption {
55 type = lib.types.package;
56 default = pkgs.openresolv;
57 defaultText = lib.literalExpression "pkgs.openresolv";
59 The package that provides the system-wide resolvconf command. Defaults to `openresolv`
60 if this module is enabled. Otherwise, can be used by other modules (for example {option}`services.resolved`) to
61 provide a compatibility layer.
63 This option generally shouldn't be set by the user.
67 dnsSingleRequest = lib.mkOption {
68 type = lib.types.bool;
71 Recent versions of glibc will issue both ipv4 (A) and ipv6 (AAAA)
72 address queries at the same time, from the same port. Sometimes upstream
73 routers will systemically drop the ipv4 queries. The symptom of this problem is
74 that 'getent hosts example.com' only returns ipv6 (or perhaps only ipv4) addresses. The
75 workaround for this is to specify the option 'single-request' in
76 /etc/resolv.conf. This option enables that.
80 dnsExtensionMechanism = lib.mkOption {
81 type = lib.types.bool;
84 Enable the `edns0` option in {file}`resolv.conf`. With
85 that option set, `glibc` supports use of the extension mechanisms for
86 DNS (EDNS) specified in RFC 2671. The most popular user of that feature is DNSSEC,
87 which does not work without it.
91 extraConfig = lib.mkOption {
92 type = lib.types.lines;
96 Extra configuration to append to {file}`resolvconf.conf`.
100 extraOptions = lib.mkOption {
101 type = lib.types.listOf lib.types.str;
103 example = [ "ndots:1" "rotate" ];
105 Set the options in {file}`/etc/resolv.conf`.
109 useLocalResolver = lib.mkOption {
110 type = lib.types.bool;
113 Use local DNS server for resolving.
121 config = lib.mkMerge [
123 environment.etc."resolvconf.conf".text =
125 # Force-stop any attempts to use resolvconf
127 echo "resolvconf is disabled on this system but was used anyway:" >&2
134 (lib.mkIf cfg.enable {
135 networking.resolvconf.package = pkgs.openresolv;
137 environment.systemPackages = [ cfg.package ];
139 systemd.services.resolvconf = {
140 description = "resolvconf update";
142 before = [ "network-pre.target" ];
143 wants = [ "network-pre.target" ];
144 wantedBy = [ "multi-user.target" ];
145 restartTriggers = [ config.environment.etc."resolvconf.conf".source ];
149 ExecStart = "${cfg.package}/bin/resolvconf -u";
150 RemainAfterExit = true;