at 21.11-pre 4.7 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 15 configText = 16 '' 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 23 # regenerated. 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' 31 '' + cfg.extraConfig; 32 33in 34 35{ 36 imports = [ 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") 42 ]; 43 44 options = { 45 46 networking.resolvconf = { 47 48 enable = mkOption { 49 type = types.bool; 50 default = false; 51 internal = true; 52 description = '' 53 DNS configuration is managed by resolvconf. 54 ''; 55 }; 56 57 dnsSingleRequest = lib.mkOption { 58 type = types.bool; 59 default = false; 60 description = '' 61 Recent versions of glibc will issue both ipv4 (A) and ipv6 (AAAA) 62 address queries at the same time, from the same port. Sometimes upstream 63 routers will systemically drop the ipv4 queries. The symptom of this problem is 64 that 'getent hosts example.com' only returns ipv6 (or perhaps only ipv4) addresses. The 65 workaround for this is to specify the option 'single-request' in 66 /etc/resolv.conf. This option enables that. 67 ''; 68 }; 69 70 dnsExtensionMechanism = mkOption { 71 type = types.bool; 72 default = true; 73 description = '' 74 Enable the <code>edns0</code> option in <filename>resolv.conf</filename>. With 75 that option set, <code>glibc</code> supports use of the extension mechanisms for 76 DNS (EDNS) specified in RFC 2671. The most popular user of that feature is DNSSEC, 77 which does not work without it. 78 ''; 79 }; 80 81 extraConfig = mkOption { 82 type = types.lines; 83 default = ""; 84 example = "libc=NO"; 85 description = '' 86 Extra configuration to append to <filename>resolvconf.conf</filename>. 87 ''; 88 }; 89 90 extraOptions = mkOption { 91 type = types.listOf types.str; 92 default = []; 93 example = [ "ndots:1" "rotate" ]; 94 description = '' 95 Set the options in <filename>/etc/resolv.conf</filename>. 96 ''; 97 }; 98 99 useLocalResolver = mkOption { 100 type = types.bool; 101 default = false; 102 description = '' 103 Use local DNS server for resolving. 104 ''; 105 }; 106 107 }; 108 109 }; 110 111 config = mkMerge [ 112 { 113 networking.resolvconf.enable = !(config.environment.etc ? "resolv.conf"); 114 115 environment.etc."resolvconf.conf".text = 116 if !cfg.enable then 117 # Force-stop any attempts to use resolvconf 118 '' 119 echo "resolvconf is disabled on this system but was used anyway:" >&2 120 echo "$0 $*" >&2 121 exit 1 122 '' 123 else configText; 124 } 125 126 (mkIf cfg.enable { 127 environment.systemPackages = [ pkgs.openresolv ]; 128 129 systemd.services.resolvconf = { 130 description = "resolvconf update"; 131 132 before = [ "network-pre.target" ]; 133 wants = [ "network-pre.target" ]; 134 wantedBy = [ "multi-user.target" ]; 135 restartTriggers = [ config.environment.etc."resolvconf.conf".source ]; 136 137 serviceConfig = { 138 Type = "oneshot"; 139 ExecStart = "${pkgs.openresolv}/bin/resolvconf -u"; 140 RemainAfterExit = true; 141 }; 142 }; 143 144 }) 145 ]; 146 147}