2019-07-15 17:18:49 +00:00
|
|
|
# /etc files related to networking, such as /etc/services.
|
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.networking.resolvconf;
|
|
|
|
|
|
|
|
resolvconfOptions =
|
|
|
|
cfg.extraOptions
|
2024-08-27 18:42:49 +00:00
|
|
|
++ lib.optional cfg.dnsSingleRequest "single-request"
|
|
|
|
++ lib.optional cfg.dnsExtensionMechanism "edns0"
|
|
|
|
++ lib.optional cfg.useLocalResolver "trust-ad";
|
2019-07-15 17:18:49 +00: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]*'
|
2024-08-27 18:42:49 +00:00
|
|
|
''
|
|
|
|
+ lib.optionalString config.services.nscd.enable ''
|
2019-07-15 17:18:49 +00:00
|
|
|
# Invalidate the nscd cache whenever resolv.conf is
|
|
|
|
# regenerated.
|
2020-05-21 08:29:22 +00:00
|
|
|
libc_restart='/run/current-system/systemd/bin/systemctl try-restart --no-block nscd.service 2> /dev/null'
|
2024-08-27 18:42:49 +00:00
|
|
|
''
|
|
|
|
+ lib.optionalString (lib.length resolvconfOptions > 0) ''
|
2019-07-15 17:18:49 +00:00
|
|
|
# Options as described in resolv.conf(5)
|
2024-08-27 18:42:49 +00:00
|
|
|
resolv_conf_options='${lib.concatStringsSep " " resolvconfOptions}'
|
|
|
|
''
|
|
|
|
+ lib.optionalString cfg.useLocalResolver ''
|
2019-07-15 17:18:49 +00:00
|
|
|
# This hosts runs a full-blown DNS resolver.
|
2024-08-27 18:42:49 +00:00
|
|
|
name_servers='127.0.0.1${lib.optionalString config.networking.enableIPv6 " ::1"}'
|
2019-07-15 17:18:49 +00:00
|
|
|
''
|
|
|
|
+ cfg.extraConfig;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
2024-08-27 18:42:49 +00:00
|
|
|
(lib.mkRenamedOptionModule
|
|
|
|
[ "networking" "dnsSingleRequest" ]
|
|
|
|
[ "networking" "resolvconf" "dnsSingleRequest" ]
|
|
|
|
)
|
|
|
|
(lib.mkRenamedOptionModule
|
|
|
|
[ "networking" "dnsExtensionMechanism" ]
|
|
|
|
[ "networking" "resolvconf" "dnsExtensionMechanism" ]
|
|
|
|
)
|
|
|
|
(lib.mkRenamedOptionModule
|
|
|
|
[ "networking" "extraResolvconfConf" ]
|
|
|
|
[ "networking" "resolvconf" "extraConfig" ]
|
|
|
|
)
|
|
|
|
(lib.mkRenamedOptionModule
|
|
|
|
[ "networking" "resolvconfOptions" ]
|
|
|
|
[ "networking" "resolvconf" "extraOptions" ]
|
|
|
|
)
|
2024-09-04 16:21:09 +00:00
|
|
|
(lib.mkRemovedOptionModule [
|
|
|
|
"networking"
|
|
|
|
"resolvconf"
|
|
|
|
"useHostResolvConf"
|
|
|
|
] "This option was never used for anything anyways")
|
2019-12-10 01:51:19 +00:00
|
|
|
];
|
2019-07-15 17:18:49 +00:00
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
networking.resolvconf = {
|
|
|
|
|
2024-08-27 18:42:49 +00:00
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2022-01-20 18:21:56 +00:00
|
|
|
default = !(config.environment.etc ? "resolv.conf");
|
2024-08-27 18:42:49 +00:00
|
|
|
defaultText = lib.literalExpression ''!(config.environment.etc ? "resolv.conf")'';
|
2019-07-15 17:18:49 +00:00
|
|
|
description = ''
|
2022-03-29 19:14:13 +00:00
|
|
|
Whether DNS configuration is managed by resolvconf.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-27 18:42:49 +00:00
|
|
|
package = lib.mkOption {
|
|
|
|
type = lib.types.package;
|
2022-03-29 19:14:13 +00:00
|
|
|
default = pkgs.openresolv;
|
2024-08-27 18:42:49 +00:00
|
|
|
defaultText = lib.literalExpression "pkgs.openresolv";
|
2022-03-29 19:14:13 +00:00
|
|
|
description = ''
|
|
|
|
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 17:18:49 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dnsSingleRequest = lib.mkOption {
|
2024-08-27 18:42:49 +00:00
|
|
|
type = lib.types.bool;
|
2019-07-15 17:18:49 +00:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-27 18:42:49 +00:00
|
|
|
dnsExtensionMechanism = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2019-07-15 17:18:49 +00:00
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-27 18:42:49 +00:00
|
|
|
extraConfig = lib.mkOption {
|
|
|
|
type = lib.types.lines;
|
2019-07-15 17:18:49 +00:00
|
|
|
default = "";
|
|
|
|
example = "libc=NO";
|
|
|
|
description = ''
|
|
|
|
Extra configuration to append to {file}`resolvconf.conf`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-27 18:42:49 +00:00
|
|
|
extraOptions = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2019-07-15 17:18:49 +00:00
|
|
|
default = [ ];
|
|
|
|
example = [
|
|
|
|
"ndots:1"
|
|
|
|
"rotate"
|
|
|
|
];
|
|
|
|
description = ''
|
|
|
|
Set the options in {file}`/etc/resolv.conf`.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-27 18:42:49 +00:00
|
|
|
useLocalResolver = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2019-07-15 17:18:49 +00:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Use local DNS server for resolving.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-10-16 02:00:40 +00:00
|
|
|
subscriberFiles = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.path;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Files written by resolvconf updates
|
|
|
|
'';
|
|
|
|
internal = true;
|
|
|
|
};
|
|
|
|
|
2019-07-15 17:18:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2024-08-27 18:42:49 +00:00
|
|
|
config = lib.mkMerge [
|
2019-07-15 17:18:49 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-08-27 18:42:49 +00:00
|
|
|
(lib.mkIf cfg.enable {
|
2023-12-24 22:40:36 +00:00
|
|
|
users.groups.resolvconf = { };
|
|
|
|
|
2024-10-16 02:00:40 +00:00
|
|
|
networking.resolvconf.subscriberFiles = [ "/etc/resolv.conf" ];
|
|
|
|
|
2022-03-29 19:14:13 +00:00
|
|
|
networking.resolvconf.package = pkgs.openresolv;
|
2019-07-15 17:18:49 +00:00
|
|
|
|
2023-03-18 00:50:45 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
2019-07-15 17:18:49 +00: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 ];
|
2024-10-13 16:08:05 +00:00
|
|
|
serviceConfig.Type = "oneshot";
|
2023-12-24 22:40:36 +00:00
|
|
|
serviceConfig.RemainAfterExit = true;
|
2019-07-15 17:18:49 +00:00
|
|
|
|
2023-12-24 22:40:36 +00:00
|
|
|
script = ''
|
|
|
|
${lib.getExe cfg.package} -u
|
2024-10-25 15:56:51 +00:00
|
|
|
chgrp resolvconf ${lib.escapeShellArgs cfg.subscriberFiles}
|
|
|
|
chmod g=u ${lib.escapeShellArgs cfg.subscriberFiles}
|
|
|
|
${lib.getExe' pkgs.acl "setfacl"} -R \
|
|
|
|
-m group:resolvconf:rwx \
|
|
|
|
-m default:group:resolvconf:rwx \
|
|
|
|
/run/resolvconf
|
2023-12-24 22:40:36 +00:00
|
|
|
'';
|
2019-07-15 17:18:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|