2021-12-26 17:43:05 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.stubby;
|
2021-12-26 17:43:05 +00:00
|
|
|
settingsFormat = pkgs.formats.yaml { };
|
|
|
|
confFile = settingsFormat.generate "stubby.yml" cfg.settings;
|
|
|
|
in {
|
2022-12-02 08:20:57 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "stubby" "debugLogging" ] "Use services.stubby.logLevel = \"debug\"; instead.")
|
|
|
|
] ++ map (x:
|
2021-12-26 17:43:05 +00:00
|
|
|
(mkRemovedOptionModule [ "services" "stubby" x ]
|
|
|
|
"Stubby configuration moved to services.stubby.settings.")) [
|
|
|
|
"authenticationMode"
|
|
|
|
"fallbackProtocols"
|
|
|
|
"idleTimeout"
|
|
|
|
"listenAddresses"
|
|
|
|
"queryPaddingBlocksize"
|
|
|
|
"roundRobinUpstreams"
|
|
|
|
"subnetPrivate"
|
|
|
|
"upstreamServers"
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
options = {
|
|
|
|
services.stubby = {
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "Stubby DNS resolver";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-12-26 17:43:05 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = types.attrsOf settingsFormat.type;
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
pkgs.stubby.passthru.settingsExample // {
|
|
|
|
upstream_recursive_servers = [{
|
|
|
|
address_data = "158.64.1.29";
|
|
|
|
tls_auth_name = "kaitain.restena.lu";
|
|
|
|
tls_pubkey_pinset = [{
|
|
|
|
digest = "sha256";
|
|
|
|
value = "7ftvIkA+UeN/ktVkovd/7rPZ6mbkhVI7/8HnFJIiLa4=";
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-12-26 17:43:05 +00:00
|
|
|
Content of the Stubby configuration file. All Stubby settings may be set or queried
|
|
|
|
here. The default settings are available at
|
2022-08-12 12:06:08 +00:00
|
|
|
`pkgs.stubby.passthru.settingsExample`. See
|
|
|
|
<https://dnsprivacy.org/wiki/display/DP/Configuring+Stubby>.
|
2021-12-26 17:43:05 +00:00
|
|
|
A list of the public recursive servers can be found here:
|
2022-08-12 12:06:08 +00:00
|
|
|
<https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Test+Servers>.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-12-02 08:20:57 +00:00
|
|
|
logLevel = let
|
|
|
|
logLevels = {
|
|
|
|
emerg = 0;
|
|
|
|
alert = 1;
|
|
|
|
crit = 2;
|
|
|
|
error = 3;
|
|
|
|
warning = 4;
|
|
|
|
notice = 5;
|
|
|
|
info = 6;
|
|
|
|
debug = 7;
|
|
|
|
};
|
|
|
|
in mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr (types.enum (attrNames logLevels ++ attrValues logLevels));
|
|
|
|
apply = v: if isString v then logLevels.${v} else v;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Log verbosity (syslog keyword or level).";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-12-26 17:43:05 +00:00
|
|
|
assertions = [{
|
|
|
|
assertion =
|
|
|
|
(cfg.settings.resolution_type or "") == "GETDNS_RESOLUTION_STUB";
|
|
|
|
message = ''
|
|
|
|
services.stubby.settings.resolution_type must be set to "GETDNS_RESOLUTION_STUB".
|
|
|
|
Is services.stubby.settings unset?
|
|
|
|
'';
|
|
|
|
}];
|
|
|
|
|
|
|
|
services.stubby.settings.appdata_dir = "/var/cache/stubby";
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.stubby = {
|
|
|
|
description = "Stubby local DNS resolver";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
before = [ "nss-lookup.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "notify";
|
|
|
|
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
|
|
|
|
CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";
|
2022-12-02 08:20:57 +00:00
|
|
|
ExecStart = "${pkgs.stubby}/bin/stubby -C ${confFile} ${optionalString (cfg.logLevel != null) "-v ${toString cfg.logLevel}"}";
|
2020-04-24 23:36:52 +00:00
|
|
|
DynamicUser = true;
|
|
|
|
CacheDirectory = "stubby";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|