single file for dns

This commit is contained in:
ari committed 2026-09-26 01:47:42 -04:00
1 parent 309b61b985
commit 09e2e03423
33 files changed
+319 -574

No files matched your search

@@ -23,28 +23,6 @@ let
# When composeFile is set, networks/volumes/extraConfig declared alongside it
# are rendered as a base overrides file merged in via an earlier -f flag, so
# the composeFile's own definitions win on any overlapping keys.
# ---- internal DNS (skyg.dns) ----------------------------------------------
# Every service with dns.names set contributes a record. The address is taken
# from dns.ip when given, otherwise derived from the service's `networks`
# mapping (the compose form `{ lan.ipv4_address = "10.0.101.2"; }`).
serviceStaticIps = svcCfg:
if builtins.isAttrs svcCfg.networks
then lib.filter (v: v != null) (lib.mapAttrsToList (_: n: n.ipv4_address or null) svcCfg.networks)
else [ ];
dnsServices = lib.flatten (lib.mapAttrsToList
(groupName: grpCfg: lib.mapAttrsToList
(svcName: svcCfg: { inherit groupName svcName svcCfg; })
(lib.filterAttrs (_: svcCfg: svcCfg.dns.names != [ ]) grpCfg.services))
enabledGroups);
dnsServiceIp = s:
if s.svcCfg.dns.ip != null
then s.svcCfg.dns.ip
else
let ips = serviceStaticIps s.svcCfg;
in if lib.length ips == 1 then lib.head ips else null;
mkOverridesFileFor = groupName: grpCfg:
if grpCfg.composeFile != null
&& (grpCfg.networks != { } || grpCfg.volumes != { } || grpCfg.extraConfig != { })
@@ -75,28 +53,7 @@ in
message =
"skyg.nixos.common.container-services.${name}: set either composeFile OR services, not both.";
})
enabledGroups
++ map
(s: {
assertion = dnsServiceIp s != null;
message = ''
skyg.nixos.common.container-services.${s.groupName}.services.${s.svcName}:
dns.names is set but no address could be determined. Found
${toString (lib.length (serviceStaticIps s.svcCfg))} ipv4_address
entries in `networks` (exactly one is required). Set dns.ip
explicitly.
'';
})
dnsServices;
# Internal DNS records for services that asked for a name.
skyg.dns.records = map
(s: {
ip = dnsServiceIp s;
inherit (s.svcCfg.dns) names wildcard;
source = "container-services/${s.groupName}/${s.svcName}";
})
(lib.filter (s: dnsServiceIp s != null) dnsServices);
enabledGroups;
# Create tmpfiles rules for state dirs and file dirs
systemd.tmpfiles.rules =
@@ -166,51 +166,6 @@
'';
};
dns = lib.mkOption {
default = { };
description = ''
Internal DNS names for this service. Folded into
skyg.dns.records, aggregated across hosts at the flake level,
and pushed to the router by `skyg openwrt`. Nothing is
configured on the host itself.
'';
type = lib.types.submodule {
options = {
names = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
example = [ "drawdb" ];
description = ''
DNS names for this service. Bare labels (no dot) are
suffixed with skyg.dns.domain, so [ "drawdb" ] becomes
drawdb.app.internal.
'';
};
ip = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
Address the names resolve to. When null (the default)
it is derived from this service's `networks` block --
which requires exactly one ipv4_address to be present.
Set explicitly for host-networked services or when the
service is attached to several networks.
'';
};
wildcard = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Also resolve every subdomain of these names
(dnsmasq `address=/name/ip` instead of `host-record=`).
'';
};
};
};
};
extra_hosts = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
+18 -20
View File
@@ -217,37 +217,35 @@ group starts; groups only reference it (`external: true`) and never create it.
## Internal DNS names
A service with a static IP can declare its own internal DNS name. The record is folded into
`skyg.dns.records`, aggregated across every host at the flake level, and pushed to the
OpenWrt router's `dnsmasq.conf` by `skyg openwrt`. **Nothing is configured on the host.**
Internal DNS names are declared centrally in `skyg.internalNetworkingMap` (see
`modules/main.nix`), not per service. Each app gets an internal name (`<name>` + `rootDns`,
e.g. `drawdb.app.internal`) and an optional public alias, and the flake renders them into
the OpenWrt router's `dnsmasq.conf` via `skyg openwrt`. **Nothing is configured on the host.**
```nix
# modules/main.nix
skyg.internalNetworkingMap.apps.drawdb = { ip = "10.0.101.2"; };
```
Service files read the IP/names from the map instead of hardcoding them:
```nix
skyg.nixos.common.container-services.drawdb.services.drawdb = {
image = "ghcr.io/drawdb-io/drawdb:latest";
networks = { lan = { ipv4_address = "10.0.101.2"; }; };
dns.names = [ "drawdb" ]; # -> drawdb.app.internal
networks.lan.ipv4_address = config.skyg.internalNetworkingMap.apps.drawdb.ip;
};
```
| Option | Default | Notes |
|---|---|---|
| `dns.names` | `[ ]` | Bare labels get `skyg.dns.domain` (default `app.internal`) appended; names containing a `.` are used as-is. |
| `dns.ip` | `null` | Derived from the service's `networks` block when it contains exactly one `ipv4_address`. Required for host-networked or multi-network services. |
| `dns.wildcard` | `false` | `true` also resolves every subdomain (`address=/name/ip` instead of `host-record=`). |
Setting `dns.names` without a derivable address is an **eval error** that names the offending
service. Two hosts mapping the same name to different IPs is also an eval error.
For IPs that aren't container services, use the host-level escape hatch instead:
```nix
skyg.dns.extraRecords.nas = { ip = "10.0.0.50"; names = [ "nas" "files" ]; };
```
| Field | Notes |
| -------------- | ---------------------------------------------------------------------- |
| `ip` | LAN IPv4 address the app's names resolve to. |
| `aliasDns` | Optional extra name (e.g. a public domain) that also resolves to `ip`. |
| `effectiveDns` | Read-only; computed as `<app-name>` + `rootDns`. |
Verify and deploy:
```sh
nix eval .#dnsRecords --json | jq # every record, all hosts
nix eval .#dnsRecords --json | jq # every record
skyg openwrt --dry-run # render dnsmasq.conf locally
skyg openwrt # diff + confirm + apply
```