aboutsummaryrefslogtreecommitdiff
path: root/modules/network
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-06-14 16:40:48 +0530
committerAkshay Nair <phenax5@gmail.com>2025-06-14 16:40:48 +0530
commit42df69164dbc74e5ddb54f5a7a01fd66260fef57 (patch)
treebc8b19c39df9edf16ca6827005b3d5e1ef564764 /modules/network
parent58519ea7b12e8ad58c0f97d9636d30572a789b41 (diff)
downloadhomeserver-nixos-config-42df69164dbc74e5ddb54f5a7a01fd66260fef57.tar.gz
homeserver-nixos-config-42df69164dbc74e5ddb54f5a7a01fd66260fef57.zip
Switch to coredns + refactor dns hosts mapping into service + more refactor
Diffstat (limited to 'modules/network')
-rw-r--r--modules/network/default.nix19
-rw-r--r--modules/network/service-router.service.nix59
2 files changed, 14 insertions, 64 deletions
diff --git a/modules/network/default.nix b/modules/network/default.nix
index 290c291..78fac75 100644
--- a/modules/network/default.nix
+++ b/modules/network/default.nix
@@ -8,9 +8,15 @@ in
imports = [
./wireless.nix
./ssh.nix
- ./service-router.service.nix
+ ../../services/service-router.service.nix
+ ../../services/bacchus-dns.service.nix
];
+ networking = {
+ hostName = "bacchus";
+ firewall.enable = true;
+ };
+
services.service-router = {
enable = true;
routes = {
@@ -23,12 +29,15 @@ in
"syncthing.local" = { inherit host; port = ports.syncthing; };
"lidarr.local" = { inherit host; port = ports.lidarr; };
"ntfy.local" = { inherit host; port = ports.ntfy; };
- "grafana.local" = { inherit host; port = ports.grafana; extraOptions.recommendedProxySettings = true; };
+ "grafana.local" = { inherit host; port = ports.grafana; extraNginxOptions.recommendedProxySettings = true; };
};
};
- networking = {
- hostName = "bacchus";
- firewall.enable = true;
+ # Host mappings defined by service-router
+ services.bacchus-dns = {
+ enable = true;
+ port = 53;
+ openFirewall = true;
+ fallback = [ "1.1.1.1" "8.8.8.8" ];
};
}
diff --git a/modules/network/service-router.service.nix b/modules/network/service-router.service.nix
deleted file mode 100644
index 14fc1b2..0000000
--- a/modules/network/service-router.service.nix
+++ /dev/null
@@ -1,59 +0,0 @@
-{ 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"; };
- basePath = mkOption { type = types.str; default = ""; };
- nginx = mkOption { type = types.attrs; default = {}; };
- extraOptions = mkOption { type = types.attrs; default = {}; };
- }; });
- default = {};
- };
- };
-
- config = lib.mkIf cfg.enable {
- services.nginx = {
- enable = true;
- recommendedOptimisation = true;
- virtualHosts = lib.mapAttrs (_: val:
- let
- opts = if hasAttr "extraOptions" val then val.extraOptions else {};
- in {
- locations."/" = if val.nginx == {} then {
- proxyPass =
- "${val.protocol}://${val.host}:${toString val.port}${val.basePath}";
- proxyWebsockets = true;
- } // opts else val.nginx;
- }
- ) 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;
- };
-}