From 3a6957043dbb19587dcfdeb48cb84c49c7347919 Mon Sep 17 00:00:00 2001 From: Martin Becze Date: Fri, 19 Jun 2026 09:47:26 +0200 Subject: [PATCH] feat: make DNS domain configurable Add a 'domain' option to the NixOS module and JSON config that controls the domain suffix used for internal DNS names. Defaults to 'hyprspace' for backward compatibility. Supports multi-label domains (e.g. 'vpn.internal'). - nixos/settings.nix: add 'domain' option - config/config.go: read Domain from config, default to 'hyprspace' - dns/server.go: use config.Domain instead of hard-coded value - docs: document the new option - dns/server_test.go: add tests for domainSuffix --- config/config.go | 6 +++++ dns/server.go | 11 +++++--- dns/server_test.go | 33 ++++++++++++++++++++++++ docs/content/features/dns.md | 6 ++++- docs/content/features/service-network.md | 4 ++- nixos/settings.nix | 7 +++++ 6 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 dns/server_test.go diff --git a/config/config.go b/config/config.go index fbec53a..4c14b79 100644 --- a/config/config.go +++ b/config/config.go @@ -29,6 +29,7 @@ type Config struct { BuiltinAddr6 net.IP `json:"-"` Services map[string]Service `json:"-"` FilterPrivateAddresses bool `json:"-"` + Domain string `json:"-"` } // Peer defines a peer in the configuration. We might add more to this later. @@ -195,6 +196,11 @@ func Read(path string) (*Config, error) { result.FilterPrivateAddresses = input.FilterPrivateAddresses + result.Domain = input.Domain + if result.Domain == "" { + result.Domain = "hyprspace" + } + // Overwrite path of config to input. result.Path = path return &result, nil diff --git a/dns/server.go b/dns/server.go index b97228e..8864e36 100644 --- a/dns/server.go +++ b/dns/server.go @@ -21,11 +21,14 @@ import ( var logger = log.Logger("hyprspace/dns") func domainSuffix(config config.Config) string { - if config.Interface == "hyprspace" { - return "hyprspace." - } else { - return fmt.Sprintf("%s.hyprspace.", config.Interface) + domain := config.Domain + if domain == "" { + domain = "hyprspace" } + if config.Interface == "hyprspace" { + return domain + "." + } + return fmt.Sprintf("%s.%s.", config.Interface, domain) } func withDomainSuffix(config config.Config, str string) string { diff --git a/dns/server_test.go b/dns/server_test.go new file mode 100644 index 0000000..97edc46 --- /dev/null +++ b/dns/server_test.go @@ -0,0 +1,33 @@ +package dns + +import ( + "testing" + + "github.com/hyprspace/hyprspace/config" +) + +func TestDomainSuffix(t *testing.T) { + tests := []struct { + name string + iface string + domain string + want string + }{ + {"default iface, default domain", "hyprspace", "hyprspace", "hyprspace."}, + {"default iface, custom domain", "hyprspace", "vpn", "vpn."}, + {"custom iface, default domain", "hs0", "hyprspace", "hs0.hyprspace."}, + {"custom iface, custom domain", "hs0", "vpn", "hs0.vpn."}, + {"multi-label domain", "hyprspace", "vpn.internal", "vpn.internal."}, + {"custom iface, multi-label domain", "hs0", "vpn.internal", "hs0.vpn.internal."}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cfg := config.Config{Interface: tt.iface, Domain: tt.domain} + got := domainSuffix(cfg) + if got != tt.want { + t.Errorf("domainSuffix() = %q, want %q", got, tt.want) + } + }) + } +} diff --git a/docs/content/features/dns.md b/docs/content/features/dns.md index ba7522c..fbe5740 100644 --- a/docs/content/features/dns.md +++ b/docs/content/features/dns.md @@ -4,7 +4,11 @@ Hyprspace runs a simple DNS server on the loopback interface for the purpose of ## Domain -All DNS records are placed under a specific domain, based on the name of the network interface that Hyprspace controls. If the interface name is `hyprspace`, then the top-level domain `hyprspace.` is used. Otherwise, the domain `${interfaceName}.hyprspace.` is used. The rest of this document will assume that the domain is `hyprspace.`. +All DNS records are placed under a specific domain, based on the `domain` config key (which defaults to `hyprspace`). If the interface name is `hyprspace` and the default `domain` is used, then the domain `hyprspace.` is used. Otherwise, the domain `${interfaceName}.${domain}.` is used. The rest of this document will assume that the domain is `hyprspace.`. + +## `domain` option + +The `domain` option in the JSON config file or the NixOS module controls the domain used for the internal DNS zone. The default is `hyprspace`. This may be a simple label (e.g. `vpn`) or a multi-label domain (e.g. `vpn.internal`). For example, setting `"domain": "vpn.internal"` would make all DNS names end in `.vpn.internal.` instead of `.hyprspace.`. ## Node lookup diff --git a/docs/content/features/service-network.md b/docs/content/features/service-network.md index 0e1547b..a188653 100644 --- a/docs/content/features/service-network.md +++ b/docs/content/features/service-network.md @@ -20,7 +20,9 @@ The config key `services` is used to configure the services a particular node sh } } ``` -This will make the services `example.mynode.hyprspace` and `other.mynode.hyrpspace` available. Upon connecting to the `example` service, the node establishes a connection to `/ip4/127.0.0.1/tcp/8080` and will relay all traffic between the service and the client. +This will make the services `example.mynode.hyprspace` and `other.mynode.hyprspace` available. Upon connecting to the `example` service, the node establishes a connection to `/ip4/127.0.0.1/tcp/8080` and will relay all traffic between the service and the client. + +> **Note:** The `.hyprspace.` suffix follows the `domain` configuration option. If you change it (e.g. to `vpn.internal`), the hostnames will use that domain instead (e.g. `example.mynode.vpn.internal`). ## Implementation details diff --git a/nixos/settings.nix b/nixos/settings.nix index c5e50ff..ef096b6 100644 --- a/nixos/settings.nix +++ b/nixos/settings.nix @@ -83,6 +83,13 @@ in options = { filterPrivateAddresses = mkEnableOption "filtering of private/link-local addresses from peer discovery. When enabled, the node will not attempt to connect to RFC1918, link-local, or loopback addresses advertised by other peers"; + domain = mkOption { + type = types.str; + description = "Domain suffix used for DNS names within the Hyprspace network."; + default = "hyprspace"; + example = "vpn.internal"; + }; + listenAddresses = mkOption { type = types.listOf t.multiAddr; description = "List of addresses to listen on for libp2p traffic.";