diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-06-11 13:57:24 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-06-13 15:01:40 +0530 |
| commit | e6b171f9f1d975ffe34e7a34743b5e92e8593847 (patch) | |
| tree | 32714bba7679b5ece2ebcf9aeb795caeab13468e /modules/service-router.service.nix | |
| parent | 2a73a5899124fa15c3962b9bd385ebd415a0ccf9 (diff) | |
| download | homeserver-nixos-config-e6b171f9f1d975ffe34e7a34743b5e92e8593847.tar.gz homeserver-nixos-config-e6b171f9f1d975ffe34e7a34743b5e92e8593847.zip | |
Add service router + nsd server
Diffstat (limited to '')
| -rw-r--r-- | modules/service-router.service.nix | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/modules/service-router.service.nix b/modules/service-router.service.nix new file mode 100644 index 0000000..0b9a873 --- /dev/null +++ b/modules/service-router.service.nix @@ -0,0 +1,49 @@ +{ config, lib, dns, ... }: +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 { + options.services.service-router = { + enable = mkEnableOption "enable router"; + routes = mkOption { + type = types.attrsOf (types.submodule { options = { + port = mkOption { type = types.int; }; + host = mkOption { type = types.str; default = "127.0.0.1"; }; + protocol = mkOption { type = types.str; default = "http"; }; + }; }); + default = {}; + }; + }; + + config = lib.mkIf cfg.enable { + services.nginx = { + enable = true; + virtualHosts = lib.mapAttrs (_: val: { + locations."/" = { + proxyPass = "${val.protocol}://${val.host}:${toString val.port}"; + }; + }) cfg.routes; + }; + + services.nsd = { + enable = true; + interfaces = [ "0.0.0.0" ]; + zones = lib.mapAttrs (domain: val: { + data = dns.lib.toString domain (domainAZone domain val.host); + }) cfg.routes; + }; + networking.firewall.allowedTCPPorts = [ 53 ]; + networking.firewall.allowedUDPPorts = [ 53 ]; + + networking.hosts."127.0.0.1" = lib.mapAttrsToList (name: _: name) cfg.routes; + }; +} |
