aboutsummaryrefslogtreecommitdiff
path: root/modules/services/nixos/selfhost/adguard.nix
blob: 73c6caffe3184d50a0f031f11e9e298af9c98d37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{
  config,
  lib,
  ...
}: let
  cfg = config.collinux.services.selfhost.adguard;
in
  lib.mkIf cfg.enable {
    services.adguardhome = {
      enable = true;
      port = cfg.port;
      mutableSettings = true;
      settings = {
        http = {
          pprof.enabled = false;
          address = "localhost:${toString cfg.port}";
        };
        users = []; # disable auth (only accessable over tailscale anyway)
        dns = {
          bind_hosts = ["127.0.0.1" cfg.bind_host];
          upstream_dns = ["https://dns.quad9.net/dns-query"];
          enable_dnssec = true;
        };
        tls.enabled = false;
        dhcp.enabled = false;
      };
    };

    # disable systemd-resolved (https://github.com/AdguardTeam/AdGuardHome/wiki/FAQ#bindinuse)
    services.resolved.extraConfig = lib.mkIf config.services.resolved.enable ''
      DNS=127.0.0.1
      DNSStubListener=no
    '';

    services.caddy = lib.mkIf (config.collinux.services.selfhost.caddy.enable
      && config.collinux.services.selfhost.magic_caddy.enable) {
      virtualHosts.${cfg.root_url}.extraConfig = ''
        ${
          if config.collinux.services.networking.tailscale.enable
          then "bind tailscale/adguard"
          else ""
        }
        reverse_proxy localhost:${toString cfg.port}
      '';
    };

    services.tailscale.extraSetFlags = lib.optional config.collinux.services.networking.tailscale.enable "--accept-dns=false"; # would create an infinite loop of dns lookups
  }