diff options
Diffstat (limited to '')
| -rw-r--r-- | services/bacchus-dashboard/bacchus-dashboard.service.nix (renamed from modules/dashboard/bacchus-dashboard.service.nix) | 0 | ||||
| -rw-r--r-- | services/bacchus-dashboard/dashboard-template.nix (renamed from modules/dashboard/dashboard-template.nix) | 0 | ||||
| -rw-r--r-- | services/bacchus-dns.service.nix | 39 | ||||
| -rw-r--r-- | services/service-router.service.nix (renamed from modules/network/service-router.service.nix) | 36 |
4 files changed, 51 insertions, 24 deletions
diff --git a/modules/dashboard/bacchus-dashboard.service.nix b/services/bacchus-dashboard/bacchus-dashboard.service.nix index 8b0fcb9..8b0fcb9 100644 --- a/modules/dashboard/bacchus-dashboard.service.nix +++ b/services/bacchus-dashboard/bacchus-dashboard.service.nix diff --git a/modules/dashboard/dashboard-template.nix b/services/bacchus-dashboard/dashboard-template.nix index 9883a1d..9883a1d 100644 --- a/modules/dashboard/dashboard-template.nix +++ b/services/bacchus-dashboard/dashboard-template.nix diff --git a/services/bacchus-dns.service.nix b/services/bacchus-dns.service.nix new file mode 100644 index 0000000..d6f45f9 --- /dev/null +++ b/services/bacchus-dns.service.nix @@ -0,0 +1,39 @@ +{ lib, config, ... }: +with lib; +let + cfg = config.services.bacchus-dns; +in +{ + options.services.bacchus-dns = { + enable = mkEnableOption "dns server mappings"; + port = mkOption { type = types.int; default = 53; }; + openFirewall = mkEnableOption "open required ports in firewall"; + ttl = mkOption { type = types.int; default = 3600; }; + fallback = mkOption { type = types.listOf types.str; default = [ "1.1.1.1" ]; }; + hosts = mkOption { type = types.attrsOf types.str; default = {}; }; + }; + + config = { + services.coredns = mkIf cfg.enable { + enable = true; + extraArgs = [ "-dns.port=${toString cfg.port}" ]; + config = '' + . { + hosts { + ${concatStringsSep "\n" ( + mapAttrsToList (domain: target: "${target} ${domain}") cfg.hosts)} + fallthrough + } + forward . ${concatStringsSep " " cfg.fallback} + cache ${toString cfg.ttl} + errors + } + ''; + }; + + networking.firewall = mkIf cfg.openFirewall { + allowedTCPPorts = [ cfg.port ]; + allowedUDPPorts = [ cfg.port ]; + }; + }; +} diff --git a/modules/network/service-router.service.nix b/services/service-router.service.nix index 14fc1b2..e52280f 100644 --- a/modules/network/service-router.service.nix +++ b/services/service-router.service.nix @@ -1,17 +1,12 @@ -{ config, lib, dns, ... }: +{ config, lib, ... }: with lib; let cfg = config.services.service-router; - domainAZone = domain: record: { - A = [ record ]; - SOA = { - nameServer = "ns.${domain}."; - adminEmail = "dont@email.me"; - serial = 2019030800; - }; - NS = [ "ns.${domain}." ]; - }; in { + imports = [ + ./bacchus-dns.service.nix + ]; + options.services.service-router = { enable = mkEnableOption "enable router"; routes = mkOption { @@ -20,8 +15,7 @@ in { host = mkOption { type = types.str; default = "127.0.0.1"; }; protocol = mkOption { type = types.str; default = "http"; }; basePath = mkOption { type = types.str; default = ""; }; - nginx = mkOption { type = types.attrs; default = {}; }; - extraOptions = mkOption { type = types.attrs; default = {}; }; + extraNginxOptions = mkOption { type = types.attrs; default = {}; }; }; }); default = {}; }; @@ -33,27 +27,21 @@ in { recommendedOptimisation = true; virtualHosts = lib.mapAttrs (_: val: let - opts = if hasAttr "extraOptions" val then val.extraOptions else {}; + opts = if hasAttr "extraNginxOptions" val then val.extraNginxOptions else {}; in { - locations."/" = if val.nginx == {} then { + locations."/" = { proxyPass = "${val.protocol}://${val.host}:${toString val.port}${val.basePath}"; proxyWebsockets = true; - } // opts else val.nginx; + } // opts; } ) cfg.routes; }; - services.nsd = { + # Hostname mapping + services.bacchus-dns = { enable = true; - interfaces = [ "0.0.0.0" ]; - zones = lib.mapAttrs (domain: val: { - data = dns.lib.toString domain (domainAZone domain val.host); - }) cfg.routes; + hosts = mapAttrs (_: val: val.host) cfg.routes; }; - networking.firewall.allowedTCPPorts = [ 53 ]; - networking.firewall.allowedUDPPorts = [ 53 ]; - - networking.hosts."127.0.0.1" = lib.mapAttrsToList (name: _: name) cfg.routes; }; } |
