summary refs log tree commit diff
diff options
context:
space:
mode:
authorCarl Richard Theodor Schneider <dev.github@crtified.me>2022-06-07 13:35:22 +0200
committerCarl Richard Theodor Schneider <dev.github@crtified.me>2022-10-25 17:35:27 +0200
commit1526a1b04145ba66e10127c7d6f0ef1a3d30cfcd (patch)
tree46777a52d8aa7886741e79823a7d7cc4e89d37de
parent8ee9c8d3ed07609f36f9ffb1b399caf926301c28 (diff)
downloadnixpkgs-1526a1b04145ba66e10127c7d6f0ef1a3d30cfcd.tar
nixpkgs-1526a1b04145ba66e10127c7d6f0ef1a3d30cfcd.tar.gz
nixpkgs-1526a1b04145ba66e10127c7d6f0ef1a3d30cfcd.tar.bz2
nixpkgs-1526a1b04145ba66e10127c7d6f0ef1a3d30cfcd.tar.lz
nixpkgs-1526a1b04145ba66e10127c7d6f0ef1a3d30cfcd.tar.xz
nixpkgs-1526a1b04145ba66e10127c7d6f0ef1a3d30cfcd.tar.zst
nixpkgs-1526a1b04145ba66e10127c7d6f0ef1a3d30cfcd.zip
adguardhome: Add schema_version
This will add `passthru.schema_version` to be used as default value for
the adguardhome module.
It will also update the `update.sh` to keep the `schema_version` in sync
with the version by inspecting the sourcecode.

This might break existing configs, if they use deprecated values that don't
appear in newer schema_versions and schema_version wasn't set explicitly.
Explicit declarations of schema_version always have higher priority.

This also removes the `host` and `config` settings in favour of using the
appropriate `settings`.

Fixes #173938

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
-rw-r--r--nixos/doc/manual/from_md/release-notes/rl-2211.section.xml8
-rw-r--r--nixos/doc/manual/release-notes/rl-2211.section.md2
-rw-r--r--nixos/modules/services/networking/adguardhome.nix66
-rw-r--r--nixos/tests/adguardhome.nix10
-rw-r--r--pkgs/servers/adguardhome/default.nix1
-rwxr-xr-xpkgs/servers/adguardhome/update.sh6
6 files changed, 60 insertions, 33 deletions
diff --git a/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml
index 98fb0e9b8b9..87249b6c3ba 100644
--- a/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml
+++ b/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml
@@ -763,6 +763,14 @@
       </listitem>
       <listitem>
         <para>
+          The <literal>adguardhome</literal> module no longer uses
+          <literal>host</literal> and <literal>port</literal> options,
+          use <literal>settings.bind_host</literal> and
+          <literal>settings.bind_port</literal> instead.
+        </para>
+      </listitem>
+      <listitem>
+        <para>
           The default <literal>kops</literal> version is now 1.25.1 and
           support for 1.22 and older has been dropped.
         </para>
diff --git a/nixos/doc/manual/release-notes/rl-2211.section.md b/nixos/doc/manual/release-notes/rl-2211.section.md
index 688ef6c13ce..bd17f3efe35 100644
--- a/nixos/doc/manual/release-notes/rl-2211.section.md
+++ b/nixos/doc/manual/release-notes/rl-2211.section.md
@@ -242,6 +242,8 @@ Available as [services.patroni](options.html#opt-services.patroni.enable).
   Use `configure.packages` instead.
 - Neovim can not be configured with plug anymore (still works for vim).
 
+- The `adguardhome` module no longer uses `host` and `port` options, use `settings.bind_host` and `settings.bind_port` instead.
+
 - The default `kops` version is now 1.25.1 and support for 1.22 and older has been dropped.
 
 - `k3s` no longer supports docker as runtime due to upstream dropping support.
diff --git a/nixos/modules/services/networking/adguardhome.nix b/nixos/modules/services/networking/adguardhome.nix
index 13b6f6efcd6..eaeaeaeb6a7 100644
--- a/nixos/modules/services/networking/adguardhome.nix
+++ b/nixos/modules/services/networking/adguardhome.nix
@@ -12,36 +12,25 @@ let
     "--config /var/lib/AdGuardHome/AdGuardHome.yaml"
   ] ++ cfg.extraArgs);
 
-  baseConfig = {
-    bind_host = cfg.host;
-    bind_port = cfg.port;
-  };
-
   configFile = pkgs.writeTextFile {
     name = "AdGuardHome.yaml";
-    text = builtins.toJSON (recursiveUpdate cfg.settings baseConfig);
+    text = builtins.toJSON cfg.settings;
     checkPhase = "${pkgs.adguardhome}/bin/adguardhome -c $out --check-config";
   };
 
-in {
-  options.services.adguardhome = with types; {
-    enable = mkEnableOption (lib.mdDoc "AdGuard Home network-wide ad blocker");
+in
+{
 
-    host = mkOption {
-      default = "0.0.0.0";
-      type = str;
-      description = lib.mdDoc ''
-        Host address to bind HTTP server to.
-      '';
-    };
+  imports =
+    let cfgPath = [ "services" "adguardhome" ];
+    in
+    [
+      (mkRenamedOptionModuleWith { sinceRelease = 2211; from = cfgPath ++ [ "host" ]; to = cfgPath ++ [ "settings" "bind_host" ]; })
+      (mkRenamedOptionModuleWith { sinceRelease = 2211; from = cfgPath ++ [ "port" ]; to = cfgPath ++ [ "settings" "bind_port" ]; })
+    ];
 
-    port = mkOption {
-      default = 3000;
-      type = port;
-      description = lib.mdDoc ''
-        Port to serve HTTP pages on.
-      '';
-    };
+  options.services.adguardhome = with types; {
+    enable = mkEnableOption (lib.mdDoc "AdGuard Home network-wide ad blocker");
 
     openFirewall = mkOption {
       default = false;
@@ -62,8 +51,35 @@ in {
     };
 
     settings = mkOption {
-      type = (pkgs.formats.yaml { }).type;
       default = { };
+      type = submodule {
+        freeformType = (pkgs.formats.yaml { }).type;
+        options = {
+          schema_version = mkOption {
+            default = pkgs.adguardhome.schema_version;
+            defaultText = literalExpression "pkgs.adguardhome.schema_version";
+            type = int;
+            description = lib.mdDoc ''
+              Schema version for the configuration.
+              Defaults to the `schema_version` supplied by `pkgs.adguardhome`.
+            '';
+          };
+          bind_host = mkOption {
+            default = "0.0.0.0";
+            type = str;
+            description = lib.mdDoc ''
+              Host address to bind HTTP server to.
+            '';
+          };
+          bind_port = mkOption {
+            default = 3000;
+            type = port;
+            description = lib.mdDoc ''
+              Port to serve HTTP pages on.
+            '';
+          };
+        };
+      };
       description = lib.mdDoc ''
         AdGuard Home configuration. Refer to
         <https://github.com/AdguardTeam/AdGuardHome/wiki/Configuration#configuration-file>
@@ -135,6 +151,6 @@ in {
       };
     };
 
-    networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
+    networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.settings.bind_port ];
   };
 }
diff --git a/nixos/tests/adguardhome.nix b/nixos/tests/adguardhome.nix
index 1a220f99699..5be69e22e53 100644
--- a/nixos/tests/adguardhome.nix
+++ b/nixos/tests/adguardhome.nix
@@ -2,16 +2,13 @@
   name = "adguardhome";
 
   nodes = {
-    minimalConf = { ... }: {
-      services.adguardhome = { enable = true; };
-    };
-
     declarativeConf = { ... }: {
       services.adguardhome = {
         enable = true;
 
         mutableSettings = false;
         settings = {
+          schema_version = 0;
           dns = {
             bind_host = "0.0.0.0";
             bootstrap_dns = "127.0.0.1";
@@ -26,6 +23,7 @@
 
         mutableSettings = true;
         settings = {
+          schema_version = 0;
           dns = {
             bind_host = "0.0.0.0";
             bootstrap_dns = "127.0.0.1";
@@ -36,10 +34,6 @@
   };
 
   testScript = ''
-    with subtest("Minimal config test"):
-        minimalConf.wait_for_unit("adguardhome.service")
-        minimalConf.wait_for_open_port(3000)
-
     with subtest("Declarative config test, DNS will be reachable"):
         declarativeConf.wait_for_unit("adguardhome.service")
         declarativeConf.wait_for_open_port(53)
diff --git a/pkgs/servers/adguardhome/default.nix b/pkgs/servers/adguardhome/default.nix
index 77531d4b28c..2d2bafaa204 100644
--- a/pkgs/servers/adguardhome/default.nix
+++ b/pkgs/servers/adguardhome/default.nix
@@ -16,6 +16,7 @@ stdenv.mkDerivation rec {
 
   passthru = {
     updateScript = ./update.sh;
+    schema_version = 14;
     tests.adguardhome = nixosTests.adguardhome;
   };
 
diff --git a/pkgs/servers/adguardhome/update.sh b/pkgs/servers/adguardhome/update.sh
index 5f436bb126d..8a72bd5a7c9 100755
--- a/pkgs/servers/adguardhome/update.sh
+++ b/pkgs/servers/adguardhome/update.sh
@@ -13,6 +13,11 @@ version=$(jq -r '.tag_name' <<<"$latest_release")
 
 echo "got version $version"
 
+schema_version=$(curl --silent "https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/${version}/internal/home/upgrade.go" \
+    | grep -Po '(?<=const currentSchemaVersion = )[[:digit:]]+$')
+
+echo "got schema_version $schema_version"
+
 declare -A systems
 systems[linux_386]=i686-linux
 systems[linux_amd64]=x86_64-linux
@@ -37,3 +42,4 @@ done
 echo '}' >> "$bins"
 
 sed -i -r -e "s/version\s*?=\s*?.*?;/version = \"${version#v}\";/" "$dirname/default.nix"
+sed -i -r -e "s/schema_version\s*?=\s*?.*?;/schema_version = ${schema_version};/" "$dirname/default.nix"