Merge pull request #196837 from KoviRobi/dnsmasq-attrsets-config

nixos/dnsmasq: Use attrs instead of plain text config

Changed files
+86 -22
nixos
doc
manual
from_md
release-notes
release-notes
modules
services
networking
tests
+9
nixos/doc/manual/from_md/release-notes/rl-2305.section.xml
···
</listitem>
<listitem>
<para>
+
The <literal>dnsmasq</literal> service now takes configuration
+
via the <literal>services.dnsmasq.settings</literal> attribute
+
set. The option
+
<literal>services.dnsmasq.extraConfig</literal> will be
+
deprecated when NixOS 22.11 reaches end of life.
+
</para>
+
</listitem>
+
<listitem>
+
<para>
A new <literal>virtualisation.rosetta</literal> module was
added to allow running <literal>x86_64</literal> binaries
through
+5
nixos/doc/manual/release-notes/rl-2305.section.md
···
- `services.mastodon` gained a tootctl wrapped named `mastodon-tootctl` similar to `nextcloud-occ` which can be executed from any user and switches to the configured mastodon user with sudo and sources the environment variables.
+
- The `dnsmasq` service now takes configuration via the
+
`services.dnsmasq.settings` attribute set. The option
+
`services.dnsmasq.extraConfig` will be deprecated when NixOS 22.11 reaches
+
end of life.
+
- A new `virtualisation.rosetta` module was added to allow running `x86_64` binaries through [Rosetta](https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment) inside virtualised NixOS guests on Apple silicon. This feature works by default with the [UTM](https://docs.getutm.app/) virtualisation [package](https://search.nixos.org/packages?channel=unstable&show=utm&from=0&size=1&sort=relevance&type=packages&query=utm).
- Resilio sync secret keys can now be provided using a secrets file at runtime, preventing these secrets from ending up in the Nix store.
+69 -17
nixos/modules/services/networking/dnsmasq.nix
···
dnsmasq = pkgs.dnsmasq;
stateDir = "/var/lib/dnsmasq";
+
# True values are just put as `name` instead of `name=true`, and false values
+
# are turned to comments (false values are expected to be overrides e.g.
+
# mkForce)
+
formatKeyValue =
+
name: value:
+
if value == true
+
then name
+
else if value == false
+
then "# setting `${name}` explicitly set to false"
+
else generators.mkKeyValueDefault { } "=" name value;
+
+
settingsFormat = pkgs.formats.keyValue {
+
mkKeyValue = formatKeyValue;
+
listsAsDuplicateKeys = true;
+
};
+
+
# Because formats.generate is outputting a file, we use of conf-file. Once
+
# `extraConfig` is deprecated we can just use
+
# `dnsmasqConf = format.generate "dnsmasq.conf" cfg.settings`
dnsmasqConf = pkgs.writeText "dnsmasq.conf" ''
-
dhcp-leasefile=${stateDir}/dnsmasq.leases
-
${optionalString cfg.resolveLocalQueries ''
-
conf-file=/etc/dnsmasq-conf.conf
-
resolv-file=/etc/dnsmasq-resolv.conf
-
''}
-
${flip concatMapStrings cfg.servers (server: ''
-
server=${server}
-
'')}
+
conf-file=${settingsFormat.generate "dnsmasq.conf" cfg.settings}
${cfg.extraConfig}
'';
in
{
+
+
imports = [
+
(mkRenamedOptionModule [ "services" "dnsmasq" "servers" ] [ "services" "dnsmasq" "settings" "server" ])
+
];
###### interface
···
'';
};
-
servers = mkOption {
-
type = types.listOf types.str;
-
default = [];
-
example = [ "8.8.8.8" "8.8.4.4" ];
-
description = lib.mdDoc ''
-
The DNS servers which dnsmasq should query.
-
'';
-
};
-
alwaysKeepRunning = mkOption {
type = types.bool;
default = false;
···
'';
};
+
settings = mkOption {
+
type = types.submodule {
+
+
freeformType = settingsFormat.type;
+
+
options.server = mkOption {
+
type = types.listOf types.str;
+
default = [ ];
+
example = [ "8.8.8.8" "8.8.4.4" ];
+
description = lib.mdDoc ''
+
The DNS servers which dnsmasq should query.
+
'';
+
};
+
+
};
+
default = { };
+
description = lib.mdDoc ''
+
Configuration of dnsmasq. Lists get added one value per line (empty
+
lists and false values don't get added, though false values get
+
turned to comments). Gets merged with
+
+
{
+
dhcp-leasefile = "${stateDir}/dnsmasq.leases";
+
conf-file = optional cfg.resolveLocalQueries "/etc/dnsmasq-conf.conf";
+
resolv-file = optional cfg.resolveLocalQueries "/etc/dnsmasq-resolv.conf";
+
}
+
'';
+
example = literalExpression ''
+
{
+
domain-needed = true;
+
dhcp-range = [ "192.168.0.2,192.168.0.254" ];
+
}
+
'';
+
};
+
extraConfig = mkOption {
type = types.lines;
default = "";
description = lib.mdDoc ''
Extra configuration directives that should be added to
`dnsmasq.conf`.
+
+
This option is deprecated, please use {option}`settings` instead.
'';
};
···
###### implementation
config = mkIf cfg.enable {
+
+
warnings = lib.optional (cfg.extraConfig != "") "Text based config is deprecated, dnsmasq now supports `services.dnsmasq.settings` for an attribute-set based config";
+
+
services.dnsmasq.settings = {
+
dhcp-leasefile = mkDefault "${stateDir}/dnsmasq.leases";
+
conf-file = mkDefault (optional cfg.resolveLocalQueries "/etc/dnsmasq-conf.conf");
+
resolv-file = mkDefault (optional cfg.resolveLocalQueries "/etc/dnsmasq-resolv.conf");
+
};
networking.nameservers =
optional cfg.resolveLocalQueries "127.0.0.1";
+1 -1
nixos/tests/dnscrypt-proxy2.nix
···
};
services.dnsmasq.enable = true;
-
services.dnsmasq.servers = [ "127.0.0.1#${toString localProxyPort}" ];
+
services.dnsmasq.settings.server = [ "127.0.0.1#${toString localProxyPort}" ];
};
};
+1 -1
nixos/tests/kubernetes/dns.nix
···
extraConfiguration = { config, pkgs, lib, ... }: {
environment.systemPackages = [ pkgs.bind.host ];
services.dnsmasq.enable = true;
-
services.dnsmasq.servers = [
+
services.dnsmasq.settings.server = [
"/cluster.local/${config.services.kubernetes.addons.dns.clusterIp}#53"
];
};
+1 -3
nixos/tests/schleuder.nix
···
# Since we don't have internet here, use dnsmasq to provide MX records from /etc/hosts
services.dnsmasq = {
enable = true;
-
extraConfig = ''
-
selfmx
-
'';
+
settings.selfmx = true;
};
networking.extraHosts = ''