From 0c37f4c330a5c6e51952bedfebb0940d3038eb34 Mon Sep 17 00:00:00 2001 From: chn Date: Fri, 12 Dec 2025 20:33:42 +0800 Subject: [PATCH] modules.services.xray.client: use coredns instead of dnsmasq --- devices/nas/default.nix | 2 +- devices/pc/default.nix | 2 +- modules/services/xray/client.nix | 32 +++++++++++++++++++------------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/devices/nas/default.nix b/devices/nas/default.nix index cb44f722..39ba877b 100644 --- a/devices/nas/default.nix +++ b/devices/nas/default.nix @@ -37,7 +37,7 @@ inputs: xray.client = { xray.serverName = "xserver2.vps9.chn.moe"; - dnsmasq = { extraInterfaces = [ "enp3s0" ]; hosts."git.chn.moe" = "127.0.0.1"; }; + coredns = { extraInterfaces = [ "enp3s0" ]; hosts."git.chn.moe" = "127.0.0.1"; }; }; beesd."/".hashTableSizeMB = 10 * 128; postgresql.mountFrom = "ssd"; diff --git a/devices/pc/default.nix b/devices/pc/default.nix index 6b5dc8db..0fb2805c 100644 --- a/devices/pc/default.nix +++ b/devices/pc/default.nix @@ -59,7 +59,7 @@ inputs: }; }; sshd = {}; - xray.client.dnsmasq = + xray.client.coredns = { hosts = builtins.listToAttrs ( diff --git a/modules/services/xray/client.nix b/modules/services/xray/client.nix index 5144a2a4..cec58beb 100644 --- a/modules/services/xray/client.nix +++ b/modules/services/xray/client.nix @@ -14,7 +14,7 @@ inputs: (inputs.lib.removeSuffix ".chn.moe" submoduleInputs.config.xray.serverName); }; }; - dnsmasq = + coredns = { extraInterfaces = mkOption { type = types.listOf types.nonEmptyStr; default = []; }; hosts = mkOption { type = types.attrsOf types.nonEmptyStr; default = {}; }; @@ -27,20 +27,26 @@ inputs: { services = { - dnsmasq = + coredns = { enable = true; - settings = - { - no-poll = true; - log-queries = true; - server = [ "127.0.0.1#10853" ]; - interface = client.dnsmasq.extraInterfaces ++ [ "lo" ]; - bind-dynamic = true; - address = builtins.map (host: "/${host.name}/${host.value}") - (inputs.localLib.attrsToList client.dnsmasq.hosts); - cname = [ "git.chn.moe,nas.ts.chn.moe" ]; - }; + config = + let + hosts = inputs.pkgs.writeText "coredns.hosts" (builtins.concatStringsSep "\n" + (inputs.lib.mapAttrsToList (n: v: "${v} ${n}") client.coredns.hosts)); + in + '' + . { + log + errors + bind lo ${builtins.concatStringsSep " " client.coredns.extraInterfaces} + hosts ${hosts} { + fallthrough + } + rewrite name exact git.chn.moe nas.ts.chn.moe + forward . 127.0.0.1:10853 + } + ''; }; resolved.enable = false; };