All checks were successful
Run nix flake check / flake-check (push) Successful in 2m17s
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2.3 KiB
2.3 KiB
DNS Automation
Status: Completed (2026-02-04)
Goal: Automatically generate DNS entries from host configurations
Approach: Leverage Nix to generate zone file entries from flake host configurations
Since most hosts use static IPs defined in their NixOS configurations, we can extract this information and automatically generate A records. This keeps DNS in sync with the actual host configs.
Implementation
- Add optional CNAME field to host configurations
- Added
homelab.dns.cnamesoption inmodules/homelab/dns.nix - Added
homelab.dns.enableto allow opting out (defaults to true) - Documented in CLAUDE.md
- Added
- Create Nix function to extract DNS records from all hosts
- Created
lib/dns-zone.nixwith extraction functions - Parses each host's
networking.hostNameandsystemd.network.networksIP configuration - Collects CNAMEs from
homelab.dns.cnames - Filters out VPN interfaces (wg*, tun*, tap*, vti*)
- Generates complete zone file with A and CNAME records
- Created
- Integrate auto-generated records into zone files
- External hosts separated to
services/ns/external-hosts.nix - Zone includes comments showing which records are auto-generated vs external
- External hosts separated to
- Update zone file serial number automatically
- Uses
self.sourceInfo.lastModified(git commit timestamp)
- Uses
- Test zone file validity after generation
- NSD validates zone at build time via
nsd-checkzone
- NSD validates zone at build time via
- Deploy process documented
- Merge to master, run auto-upgrade on ns1/ns2
Files Created/Modified
| File | Purpose |
|---|---|
modules/homelab/dns.nix |
Defines homelab.dns.* options |
modules/homelab/default.nix |
Module import hub |
lib/dns-zone.nix |
Zone generation functions |
services/ns/external-hosts.nix |
Non-flake host records |
services/ns/master-authorative.nix |
Uses generated zone |
services/ns/secondary-authorative.nix |
Uses generated zone |
Usage
View generated zone:
nix eval .#nixosConfigurations.ns1.config.services.nsd.zones.'"home.2rjus.net"'.data --raw
Add CNAMEs to a host:
homelab.dns.cnames = [ "alias1" "alias2" ];
Exclude a host from DNS:
homelab.dns.enable = false;
Add non-flake hosts: Edit services/ns/external-hosts.nix