at 24.11-pre 5.3 kB view raw
1# /etc files related to networking, such as /etc/services. 2 3{ config, lib, pkgs, ... }: 4 5with lib; 6 7let 8 9 cfg = config.networking.resolvconf; 10 11 resolvconfOptions = cfg.extraOptions 12 ++ optional cfg.dnsSingleRequest "single-request" 13 ++ optional cfg.dnsExtensionMechanism "edns0" 14 ++ optional cfg.useLocalResolver "trust-ad"; 15 16 configText = 17 '' 18 # This is the default, but we must set it here to prevent 19 # a collision with an apparently unrelated environment 20 # variable with the same name exported by dhcpcd. 21 interface_order='lo lo[0-9]*' 22 '' + optionalString config.services.nscd.enable '' 23 # Invalidate the nscd cache whenever resolv.conf is 24 # regenerated. 25 libc_restart='/run/current-system/systemd/bin/systemctl try-restart --no-block nscd.service 2> /dev/null' 26 '' + optionalString (length resolvconfOptions > 0) '' 27 # Options as described in resolv.conf(5) 28 resolv_conf_options='${concatStringsSep " " resolvconfOptions}' 29 '' + optionalString cfg.useLocalResolver '' 30 # This hosts runs a full-blown DNS resolver. 31 name_servers='127.0.0.1${optionalString config.networking.enableIPv6 " ::1"}' 32 '' + cfg.extraConfig; 33 34in 35 36{ 37 imports = [ 38 (mkRenamedOptionModule [ "networking" "dnsSingleRequest" ] [ "networking" "resolvconf" "dnsSingleRequest" ]) 39 (mkRenamedOptionModule [ "networking" "dnsExtensionMechanism" ] [ "networking" "resolvconf" "dnsExtensionMechanism" ]) 40 (mkRenamedOptionModule [ "networking" "extraResolvconfConf" ] [ "networking" "resolvconf" "extraConfig" ]) 41 (mkRenamedOptionModule [ "networking" "resolvconfOptions" ] [ "networking" "resolvconf" "extraOptions" ]) 42 (mkRemovedOptionModule [ "networking" "resolvconf" "useHostResolvConf" ] "This option was never used for anything anyways") 43 ]; 44 45 options = { 46 47 networking.resolvconf = { 48 49 enable = mkOption { 50 type = types.bool; 51 default = !(config.environment.etc ? "resolv.conf"); 52 defaultText = literalExpression ''!(config.environment.etc ? "resolv.conf")''; 53 description = '' 54 Whether DNS configuration is managed by resolvconf. 55 ''; 56 }; 57 58 package = mkOption { 59 type = types.package; 60 default = pkgs.openresolv; 61 defaultText = literalExpression "pkgs.openresolv"; 62 description = '' 63 The package that provides the system-wide resolvconf command. Defaults to `openresolv` 64 if this module is enabled. Otherwise, can be used by other modules (for example {option}`services.resolved`) to 65 provide a compatibility layer. 66 67 This option generally shouldn't be set by the user. 68 ''; 69 }; 70 71 dnsSingleRequest = lib.mkOption { 72 type = types.bool; 73 default = false; 74 description = '' 75 Recent versions of glibc will issue both ipv4 (A) and ipv6 (AAAA) 76 address queries at the same time, from the same port. Sometimes upstream 77 routers will systemically drop the ipv4 queries. The symptom of this problem is 78 that 'getent hosts example.com' only returns ipv6 (or perhaps only ipv4) addresses. The 79 workaround for this is to specify the option 'single-request' in 80 /etc/resolv.conf. This option enables that. 81 ''; 82 }; 83 84 dnsExtensionMechanism = mkOption { 85 type = types.bool; 86 default = true; 87 description = '' 88 Enable the `edns0` option in {file}`resolv.conf`. With 89 that option set, `glibc` supports use of the extension mechanisms for 90 DNS (EDNS) specified in RFC 2671. The most popular user of that feature is DNSSEC, 91 which does not work without it. 92 ''; 93 }; 94 95 extraConfig = mkOption { 96 type = types.lines; 97 default = ""; 98 example = "libc=NO"; 99 description = '' 100 Extra configuration to append to {file}`resolvconf.conf`. 101 ''; 102 }; 103 104 extraOptions = mkOption { 105 type = types.listOf types.str; 106 default = []; 107 example = [ "ndots:1" "rotate" ]; 108 description = '' 109 Set the options in {file}`/etc/resolv.conf`. 110 ''; 111 }; 112 113 useLocalResolver = mkOption { 114 type = types.bool; 115 default = false; 116 description = '' 117 Use local DNS server for resolving. 118 ''; 119 }; 120 121 }; 122 123 }; 124 125 config = mkMerge [ 126 { 127 environment.etc."resolvconf.conf".text = 128 if !cfg.enable then 129 # Force-stop any attempts to use resolvconf 130 '' 131 echo "resolvconf is disabled on this system but was used anyway:" >&2 132 echo "$0 $*" >&2 133 exit 1 134 '' 135 else configText; 136 } 137 138 (mkIf cfg.enable { 139 networking.resolvconf.package = pkgs.openresolv; 140 141 environment.systemPackages = [ cfg.package ]; 142 143 systemd.services.resolvconf = { 144 description = "resolvconf update"; 145 146 before = [ "network-pre.target" ]; 147 wants = [ "network-pre.target" ]; 148 wantedBy = [ "multi-user.target" ]; 149 restartTriggers = [ config.environment.etc."resolvconf.conf".source ]; 150 151 serviceConfig = { 152 Type = "oneshot"; 153 ExecStart = "${cfg.package}/bin/resolvconf -u"; 154 RemainAfterExit = true; 155 }; 156 }; 157 158 }) 159 ]; 160 161}