From 02985e0817a19148cefd8f7cf4b865b6a3391bd2 Mon Sep 17 00:00:00 2001 From: "Gustavo \"Guz\" L. de Mello" Date: Sun, 28 Jan 2024 11:15:09 -0300 Subject: [PATCH] refactor: adguard dns rewrites --- hosts/homex/configuration.nix | 7 +++++ modules/nixos/homelab/adguard.nix | 48 ++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/hosts/homex/configuration.nix b/hosts/homex/configuration.nix index 3cce066..2fba71d 100644 --- a/hosts/homex/configuration.nix +++ b/hosts/homex/configuration.nix @@ -24,6 +24,12 @@ settings.server = { port = 3010; }; + settings.dns = { + rewrites = { + "guz.local" = "100.66.139.89"; + "*.guz.local" = "100.66.139.89"; + }; + }; }; forgejo = { @@ -51,3 +57,4 @@ } + diff --git a/modules/nixos/homelab/adguard.nix b/modules/nixos/homelab/adguard.nix index bd88307..ddaab78 100644 --- a/modules/nixos/homelab/adguard.nix +++ b/modules/nixos/homelab/adguard.nix @@ -24,6 +24,28 @@ in type = str; default = "0.0.0.0"; }; + dns.rewrites = mkOption { + type = attrsOf str; + default = { }; + }; + dns.filters = mkOption { + type = attrsOf (submodule ({ lib, ... }: { + options = { + name = mkOption { + type = nullOr str; + default = null; + }; + url = mkOption { + type = str; + }; + enabled = { + type = bool; + default = true; + }; + }; + })); + default = { }; + }; }; }; config = lib.mkIf cfg.enable { @@ -31,7 +53,7 @@ in allowedTCPPorts = [ 53 ]; allowedUDPPorts = [ 53 51820 ]; }; - services.adguardhome = { + services.adguardhome = with builtins; { enable = true; settings = { bind_port = cfg.settings.server.port; @@ -39,16 +61,20 @@ in http = { address = "${cfg.settings.server.address}:${toString cfg.settings.server.port}"; }; - dns.rewrites = [ - { - domain = "guz.local"; - answer = "100.66.139.89"; - } - { - domain = "*.guz.local"; - answer = "100.66.139.89"; - } - ]; + dns.rewrites = (builtins.attrValues (builtins.mapAttrs + (from: to: { + domain = from; + answer = to; + }) + cfg.settings.dns.rewrites)); + filters = (attrValues (mapAttrs + (id: list: { + name = if isNull list.name then id else list.name; + ID = id; + url = list.url; + enabled = list.enabled; + }) + cfg.settings.dns.filters)); }; }; };