···
cfg = config.services.adguardhome;
7
+
settingsFormat = pkgs.formats.yaml { };
args = concatStringsSep " " ([
···
"--config /var/lib/AdGuardHome/AdGuardHome.yaml"
15
-
configFile = pkgs.writeTextFile {
16
-
name = "AdGuardHome.yaml";
17
-
text = builtins.toJSON cfg.settings;
18
-
checkPhase = "${pkgs.adguardhome}/bin/adguardhome -c $out --check-config";
20
-
defaultBindPort = 3000;
26
-
let cfgPath = [ "services" "adguardhome" ];
29
-
(mkRenamedOptionModuleWith { sinceRelease = 2211; from = cfgPath ++ [ "host" ]; to = cfgPath ++ [ "settings" "bind_host" ]; })
30
-
(mkRenamedOptionModuleWith { sinceRelease = 2211; from = cfgPath ++ [ "port" ]; to = cfgPath ++ [ "settings" "bind_port" ]; })
16
+
settings = if (cfg.settings != null) then
17
+
cfg.settings // (if cfg.settings.schema_version < 23 then {
18
+
bind_host = cfg.host;
19
+
bind_port = cfg.port;
21
+
http.address = "${cfg.host}:${toString cfg.port}";
27
+
(settingsFormat.generate "AdGuardHome.yaml" settings).overrideAttrs (_: {
28
+
checkPhase = "${cfg.package}/bin/adguardhome -c $out --check-config";
options.services.adguardhome = with types; {
enable = mkEnableOption "AdGuard Home network-wide ad blocker";
34
+
package = mkOption {
36
+
default = pkgs.adguardhome;
37
+
defaultText = literalExpression "pkgs.adguardhome";
39
+
The package that runs adguardhome.
openFirewall = mkOption {
···
46
-
default = cfg.settings.dhcp.enabled or false;
47
-
defaultText = literalExpression ''config.services.adguardhome.settings.dhcp.enabled or false'';
53
+
default = settings.dhcp.enabled or false;
54
+
defaultText = literalExpression "config.services.adguardhome.settings.dhcp.enabled or false";
Allows AdGuard Home to open raw sockets (`CAP_NET_RAW`), which is
···
76
+
default = "0.0.0.0";
79
+
Host address to bind HTTP server to.
87
+
Port to serve HTTP pages on.
type = nullOr (submodule {
71
-
freeformType = (pkgs.formats.yaml { }).type;
94
+
freeformType = settingsFormat.type;
schema_version = mkOption {
74
-
default = pkgs.adguardhome.schema_version;
75
-
defaultText = literalExpression "pkgs.adguardhome.schema_version";
97
+
default = cfg.package.schema_version;
98
+
defaultText = literalExpression "cfg.package.schema_version";
Schema version for the configuration.
79
-
Defaults to the `schema_version` supplied by `pkgs.adguardhome`.
82
-
bind_host = mkOption {
83
-
default = "0.0.0.0";
86
-
Host address to bind HTTP server to.
89
-
bind_port = mkOption {
90
-
default = defaultBindPort;
93
-
Port to serve HTTP pages on.
102
+
Defaults to the `schema_version` supplied by `cfg.package`.
···
Set this to `null` (default) for a non-declarative configuration without any
110
-
Declarative configurations are supplied with a default `schema_version`, `bind_host`, and `bind_port`.
119
+
Declarative configurations are supplied with a default `schema_version`, and `http.address`.
···
config = mkIf cfg.enable {
127
-
assertion = cfg.settings != null -> cfg.mutableSettings
128
-
|| (hasAttrByPath [ "dns" "bind_host" ] cfg.settings)
129
-
|| (hasAttrByPath [ "dns" "bind_hosts" ] cfg.settings);
131
-
"AdGuard setting dns.bind_host or dns.bind_hosts needs to be configured for a minimal working configuration";
136
+
assertion = cfg.settings != null
137
+
-> !(hasAttrByPath [ "bind_host" ] cfg.settings);
138
+
message = "AdGuard option `settings.bind_host' has been superseded by `services.adguardhome.host'";
141
+
assertion = cfg.settings != null
142
+
-> !(hasAttrByPath [ "bind_port" ] cfg.settings);
143
+
message = "AdGuard option `settings.bind_host' has been superseded by `services.adguardhome.port'";
134
-
assertion = cfg.settings != null -> cfg.mutableSettings
135
-
|| hasAttrByPath [ "dns" "bootstrap_dns" ] cfg.settings;
137
-
"AdGuard setting dns.bootstrap_dns needs to be configured for a minimal working configuration";
146
+
assertion = settings != null -> cfg.mutableSettings
147
+
|| hasAttrByPath [ "dns" "bootstrap_dns" ] settings;
148
+
message = "AdGuard setting dns.bootstrap_dns needs to be configured for a minimal working configuration";
151
+
assertion = settings != null -> cfg.mutableSettings
152
+
|| hasAttrByPath [ "dns" "bootstrap_dns" ] settings
153
+
&& isList settings.dns.bootstrap_dns;
154
+
message = "AdGuard setting dns.bootstrap_dns needs to be a list";
···
150
-
preStart = optionalString (cfg.settings != null) ''
167
+
preStart = optionalString (settings != null) ''
if [ -e "$STATE_DIRECTORY/AdGuardHome.yaml" ] \
&& [ "${toString cfg.mutableSettings}" = "1" ]; then
# Writing directly to AdGuardHome.yaml results in empty file
···
164
-
ExecStart = "${pkgs.adguardhome}/bin/adguardhome ${args}";
165
-
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ] ++ optionals cfg.allowDHCP [ "CAP_NET_RAW" ];
181
+
ExecStart = "${cfg.package}/bin/adguardhome ${args}";
182
+
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ]
183
+
++ optionals cfg.allowDHCP [ "CAP_NET_RAW" ];
RuntimeDirectory = "AdGuardHome";
···
173
-
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.settings.bind_port or defaultBindPort ];
191
+
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];