2019-07-15 19:18:49 +02:00
|
|
|
# /etc files related to networking, such as /etc/services.
|
|
|
|
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.networking.resolvconf;
|
|
|
|
|
|
|
|
resolvconfOptions = cfg.extraOptions
|
|
|
|
++ optional cfg.dnsSingleRequest "single-request"
|
2024-03-17 08:52:00 +01:00
|
|
|
++ optional cfg.dnsExtensionMechanism "edns0"
|
|
|
|
++ optional cfg.useLocalResolver "trust-ad";
|
2019-07-15 19:18:49 +02:00
|
|
|
|
|
|
|
configText =
|
|
|
|
''
|
|
|
|
# This is the default, but we must set it here to prevent
|
|
|
|
# a collision with an apparently unrelated environment
|
|
|
|
# variable with the same name exported by dhcpcd.
|
|
|
|
interface_order='lo lo[0-9]*'
|
|
|
|
'' + optionalString config.services.nscd.enable ''
|
|
|
|
# Invalidate the nscd cache whenever resolv.conf is
|
|
|
|
# regenerated.
|
2020-05-21 10:29:22 +02:00
|
|
|
libc_restart='/run/current-system/systemd/bin/systemctl try-restart --no-block nscd.service 2> /dev/null'
|
2019-07-15 19:18:49 +02:00
|
|
|
'' + optionalString (length resolvconfOptions > 0) ''
|
|
|
|
# Options as described in resolv.conf(5)
|
|
|
|
resolv_conf_options='${concatStringsSep " " resolvconfOptions}'
|
|
|
|
'' + optionalString cfg.useLocalResolver ''
|
|
|
|
# This hosts runs a full-blown DNS resolver.
|
2024-04-08 17:44:33 +02:00
|
|
|
name_servers='127.0.0.1${optionalString config.networking.enableIPv6 " ::1"}'
|
2019-07-15 19:18:49 +02:00
|
|
|
'' + cfg.extraConfig;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2019-12-10 02:51:19 +01:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "networking" "dnsSingleRequest" ] [ "networking" "resolvconf" "dnsSingleRequest" ])
|
|
|
|
(mkRenamedOptionModule [ "networking" "dnsExtensionMechanism" ] [ "networking" "resolvconf" "dnsExtensionMechanism" ])
|
|
|
|
(mkRenamedOptionModule [ "networking" "extraResolvconfConf" ] [ "networking" "resolvconf" "extraConfig" ])
|
|
|
|
(mkRenamedOptionModule [ "networking" "resolvconfOptions" ] [ "networking" "resolvconf" "extraOptions" ])
|
2020-02-05 00:28:32 +01:00
|
|
|
(mkRemovedOptionModule [ "networking" "resolvconf" "useHostResolvConf" ] "This option was never used for anything anyways")
|
2019-12-10 02:51:19 +01:00
|
|
|
];
|
2019-07-15 19:18:49 +02:00
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
networking.resolvconf = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
2022-01-20 19:21:56 +01:00
|
|
|
default = !(config.environment.etc ? "resolv.conf");
|
|
|
|
defaultText = literalExpression ''!(config.environment.etc ? "resolv.conf")'';
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2022-03-29 21:14:13 +02:00
|
|
|
Whether DNS configuration is managed by resolvconf.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.openresolv;
|
|
|
|
defaultText = literalExpression "pkgs.openresolv";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2022-03-29 21:14:13 +02:00
|
|
|
The package that provides the system-wide resolvconf command. Defaults to `openresolv`
|
|
|
|
if this module is enabled. Otherwise, can be used by other modules (for example {option}`services.resolved`) to
|
|
|
|
provide a compatibility layer.
|
|
|
|
|
|
|
|
This option generally shouldn't be set by the user.
|
2019-07-15 19:18:49 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dnsSingleRequest = lib.mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-07-15 19:18:49 +02:00
|
|
|
Recent versions of glibc will issue both ipv4 (A) and ipv6 (AAAA)
|
|
|
|
address queries at the same time, from the same port. Sometimes upstream
|
|
|
|
routers will systemically drop the ipv4 queries. The symptom of this problem is
|
|
|
|
that 'getent hosts example.com' only returns ipv6 (or perhaps only ipv4) addresses. The
|
|
|
|
workaround for this is to specify the option 'single-request' in
|
|
|
|
/etc/resolv.conf. This option enables that.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dnsExtensionMechanism = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-07-15 19:18:49 +02:00
|
|
|
Enable the `edns0` option in {file}`resolv.conf`. With
|
|
|
|
that option set, `glibc` supports use of the extension mechanisms for
|
|
|
|
DNS (EDNS) specified in RFC 2671. The most popular user of that feature is DNSSEC,
|
|
|
|
which does not work without it.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = "libc=NO";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-07-15 19:18:49 +02:00
|
|
|
Extra configuration to append to {file}`resolvconf.conf`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "ndots:1" "rotate" ];
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-07-15 19:18:49 +02:00
|
|
|
Set the options in {file}`/etc/resolv.conf`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
useLocalResolver = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-07-15 19:18:49 +02:00
|
|
|
Use local DNS server for resolving.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [
|
|
|
|
{
|
|
|
|
environment.etc."resolvconf.conf".text =
|
|
|
|
if !cfg.enable then
|
|
|
|
# Force-stop any attempts to use resolvconf
|
|
|
|
''
|
|
|
|
echo "resolvconf is disabled on this system but was used anyway:" >&2
|
|
|
|
echo "$0 $*" >&2
|
|
|
|
exit 1
|
|
|
|
''
|
|
|
|
else configText;
|
|
|
|
}
|
|
|
|
|
|
|
|
(mkIf cfg.enable {
|
2022-03-29 21:14:13 +02:00
|
|
|
networking.resolvconf.package = pkgs.openresolv;
|
2019-07-15 19:18:49 +02:00
|
|
|
|
2023-03-18 01:50:45 +01:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
2019-07-15 19:18:49 +02:00
|
|
|
systemd.services.resolvconf = {
|
|
|
|
description = "resolvconf update";
|
|
|
|
|
|
|
|
before = [ "network-pre.target" ];
|
|
|
|
wants = [ "network-pre.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
restartTriggers = [ config.environment.etc."resolvconf.conf".source ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
2022-03-29 21:14:13 +02:00
|
|
|
ExecStart = "${cfg.package}/bin/resolvconf -u";
|
2019-07-15 19:18:49 +02:00
|
|
|
RemainAfterExit = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|