adguardhome.nix 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. { config, lib, ... }:
  2. with lib;
  3. let
  4. cfg = config.roles.server.adguardhome;
  5. in {
  6. options.roles.server.adguardhome = {
  7. enable = mkOption {
  8. default = false;
  9. type = types.bool;
  10. };
  11. domain = mkOption {
  12. default = config.roles.server.domain;
  13. type = types.str;
  14. };
  15. };
  16. config = mkIf cfg.enable {
  17. roles.server.nginx.enable = mkForce true;
  18. systemd.services.adguardhome.serviceConfig.SupplementaryGroups = [ "acme" ];
  19. networking.firewall = {
  20. allowedTCPPorts = [ 853 ];
  21. allowedUDPPorts = [ 53 ];
  22. };
  23. services = {
  24. adguardhome.enable = true;
  25. nginx = {
  26. upstreams.adguardhome.servers = { "127.0.0.1:${toString config.services.adguardhome.port}" = {}; };
  27. virtualHosts."dns.${cfg.domain}" = {
  28. forceSSL = true;
  29. useACMEHost = cfg.domain;
  30. locations = {
  31. "/".proxyPass = "http://adguardhome";
  32. "/dns-query".proxyPass = "https://127.0.0.1:7443";
  33. };
  34. };
  35. };
  36. };
  37. };
  38. }