single file for dns
This commit is contained in:
1 parent
309b61b985
commit
09e2e03423
33 files changed
+319
-574
No files matched your search
@@ -10,6 +10,8 @@ modules/
|
||||
├── lib.nix # makeNixOs / makeIso / makeHomeManagerUsers / makeDarwinModule / eachSystem
|
||||
│ # (registers the `tether` flake input's NixOS module → programs.tether.*)
|
||||
├── main.nix # Base module imported by every host: core/ + nixos/ + network-drives.nix
|
||||
│ # + skyg.internalNetworkingMap (global app registry)
|
||||
├── internal-networking.nix # Renders skyg.internalNetworkingMap → router generalMappings
|
||||
├── skyg-utils.nix # makeHyperlinkScriptToConfigs (symlinks configs/ → ~/.config/;
|
||||
│ # backs up an existing real dir to <path>.backup.<timestamp>)
|
||||
├── macos.nix # macOS / nix-darwin module
|
||||
@@ -30,6 +32,7 @@ All custom options live under `skyg.*`. Never introduce options outside this nam
|
||||
```
|
||||
skyg.user.* → core/user.nix
|
||||
skyg.networkDrives.* → network-drives.nix
|
||||
skyg.internalNetworkingMap.* → main.nix (global app registry; rendered into router DNS by internal-networking.nix)
|
||||
skyg.rootDir → core/default.nix (set by the flake; repo root store path)
|
||||
skyg.nixos.common.* → nixos/common/
|
||||
skyg.nixos.desktop.* → nixos/desktop/
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
# Aggregates `skyg.dns.resolved` across every nixosConfiguration into the shape
|
||||
# the OpenWrt generator consumes (`generalMappings`).
|
||||
#
|
||||
# Usage:
|
||||
# aggregate = import ./modules/dns-aggregate.nix { inherit lib; };
|
||||
# aggregate.records self.nixosConfigurations # -> [ { ip; domains; ... } ]
|
||||
# aggregate.json self.nixosConfigurations # -> { generalMappings = [...]; }
|
||||
#
|
||||
# Evaluation fails if the same name is mapped to two different addresses on any
|
||||
# host, so drift between hosts is caught at `nix eval` / `nix flake check` time.
|
||||
{ lib }:
|
||||
|
||||
let
|
||||
# Per-host records, tagged with the config name they came from.
|
||||
collect = nixosConfigurations:
|
||||
lib.flatten (lib.mapAttrsToList
|
||||
(cfgName: sys:
|
||||
map (r: r // { configName = cfgName; })
|
||||
(sys.config.skyg.dns.resolved or [ ]))
|
||||
nixosConfigurations);
|
||||
|
||||
# name -> list of { ip, wildcard, source, host, configName }
|
||||
byName = all:
|
||||
lib.foldl'
|
||||
(acc: r: lib.foldl'
|
||||
(a: name: a // { ${name} = (a.${name} or [ ]) ++ [ r ]; })
|
||||
acc
|
||||
r.names)
|
||||
{ }
|
||||
all;
|
||||
|
||||
conflicts = all:
|
||||
lib.filterAttrs
|
||||
(_: entries: lib.length (lib.unique (map (e: e.ip) entries)) > 1)
|
||||
(byName all);
|
||||
|
||||
checkConflicts = all:
|
||||
let bad = conflicts all;
|
||||
in
|
||||
if bad == { }
|
||||
then all
|
||||
else
|
||||
throw ''
|
||||
skyg.dns: conflicting DNS records across hosts:
|
||||
${lib.concatStringsSep "\n" (lib.mapAttrsToList
|
||||
(name: entries: " ${name} -> ${lib.concatStringsSep ", " (map
|
||||
(e: "${e.ip} (${e.configName}: ${e.source})") entries)}")
|
||||
bad)}
|
||||
'';
|
||||
|
||||
# Collapse to one entry per (ip, wildcard) pair, with sorted unique names.
|
||||
records = nixosConfigurations:
|
||||
let
|
||||
all = checkConflicts (collect nixosConfigurations);
|
||||
groups = lib.groupBy (r: "${r.ip}|${lib.boolToString r.wildcard}") all;
|
||||
in
|
||||
lib.sort (a: b: a.ip < b.ip) (lib.mapAttrsToList
|
||||
(_: entries: {
|
||||
ip = (lib.head entries).ip;
|
||||
wildcard = (lib.head entries).wildcard;
|
||||
domains = lib.sort (a: b: a < b) (lib.unique (lib.concatMap (e: e.names) entries));
|
||||
sources = lib.sort (a: b: a < b) (lib.unique (map (e: "${e.configName}:${e.source}") entries));
|
||||
})
|
||||
groups);
|
||||
|
||||
in
|
||||
{
|
||||
inherit records;
|
||||
|
||||
# The fragment merged into the router's (secret) config JSON at deploy time.
|
||||
json = nixosConfigurations: {
|
||||
generalMappings = map (r: { inherit (r) ip domains wildcard; }) (records nixosConfigurations);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
# Renders the global `skyg.internalNetworkingMap` into the shape the OpenWrt
|
||||
# generator consumes (`generalMappings`).
|
||||
#
|
||||
# Usage:
|
||||
# internalNetworking = import ./modules/internal-networking.nix { inherit lib; };
|
||||
# internalNetworking.records apps # -> [ { ip; domains; ... } ]
|
||||
# internalNetworking.json apps # -> { generalMappings = [...]; }
|
||||
#
|
||||
# The map is global (identical on every host), so there is nothing to aggregate
|
||||
# across hosts and no cross-host conflicts to detect.
|
||||
{ lib }:
|
||||
|
||||
let
|
||||
# One app -> one record. `wildcard = false` keeps the plain host-record
|
||||
# behaviour the generator expects for Nix-declared names.
|
||||
toRecord = name: app: {
|
||||
ip = app.ip;
|
||||
domains = [ app.effectiveDns ] ++ lib.optional (app.aliasDns != null) app.aliasDns;
|
||||
wildcard = false;
|
||||
source = "internalNetworkingMap/${name}";
|
||||
};
|
||||
|
||||
records = apps:
|
||||
lib.sort (a: b: a.ip < b.ip) (lib.mapAttrsToList toRecord apps);
|
||||
|
||||
in
|
||||
{
|
||||
inherit records;
|
||||
|
||||
# The fragment merged into the router's (secret) config JSON at deploy time.
|
||||
json = apps: {
|
||||
generalMappings = map (r: { inherit (r) ip domains wildcard; }) (records apps);
|
||||
};
|
||||
}
|
||||
@@ -139,6 +139,7 @@ in
|
||||
user
|
||||
rootDir
|
||||
hostName
|
||||
configsDir
|
||||
systemStateVersion
|
||||
homeManagerVersion
|
||||
;
|
||||
@@ -165,6 +166,7 @@ in
|
||||
user
|
||||
rootDir
|
||||
hostName
|
||||
configsDir
|
||||
systemStateVersion
|
||||
homeManagerVersion
|
||||
;
|
||||
|
||||
+86
-11
@@ -5,21 +5,96 @@
|
||||
, configsDir
|
||||
, ...
|
||||
}:
|
||||
{ lib, ... }: {
|
||||
{ lib, config, ... }:
|
||||
let
|
||||
# Global internal app registry: one place to declare each app's LAN IP and
|
||||
# optional public alias. Service files read these instead of hardcoding, and
|
||||
# the flake renders it into the router's DNS records.
|
||||
internalNetworkingMap = config.skyg.internalNetworkingMap;
|
||||
|
||||
appType = lib.types.submodule ({ name, ... }: {
|
||||
options = {
|
||||
ip = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
example = "10.0.101.3";
|
||||
description = "LAN IPv4 address of the app.";
|
||||
};
|
||||
|
||||
aliasDns = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
example = "buzz.home.sosnovsky.ca";
|
||||
description = "Optional public/alternate DNS name for the app.";
|
||||
};
|
||||
|
||||
effectiveDns = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
readOnly = true;
|
||||
description = ''
|
||||
Read-only: the app's internal DNS name, computed as
|
||||
"<app-name>" + skyg.internalNetworkingMap.rootDns.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config.effectiveDns = "${name}${internalNetworkingMap.rootDns}";
|
||||
});
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./core
|
||||
./nixos
|
||||
./network-drives.nix
|
||||
];
|
||||
# Share defaults - using mkDefault so they can be overridden per-host
|
||||
skyg.user = {
|
||||
name = lib.mkDefault user.name;
|
||||
fullName = lib.mkDefault user.fullName;
|
||||
email = lib.mkDefault user.email;
|
||||
|
||||
options.skyg.internalNetworkingMap = {
|
||||
rootDns = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = ".app.internal";
|
||||
description = "Suffix appended to each app name to form its internal DNS name.";
|
||||
};
|
||||
|
||||
subnet = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
example = "10.0.101.0/24";
|
||||
description = "LAN subnet the apps live on (informational).";
|
||||
};
|
||||
|
||||
apps = lib.mkOption {
|
||||
type = lib.types.attrsOf appType;
|
||||
default = { };
|
||||
description = ''
|
||||
Internal apps, keyed by app name. Each app's internal DNS name is
|
||||
"<name>" + rootDns, and the flake renders every app into the router's
|
||||
DNS records.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
# Global internal app registry.
|
||||
skyg.internalNetworkingMap = {
|
||||
rootDns = ".app.internal";
|
||||
subnet = "10.0.101.0/24";
|
||||
apps = {
|
||||
audiobooks = { ip = "10.0.101.4"; };
|
||||
buzz = { ip = "10.0.101.3"; aliasDns = "buzz.home.sosnovsky.ca"; };
|
||||
drawdb = { ip = "10.0.101.2"; };
|
||||
portainer = { ip = "10.0.101.241"; };
|
||||
};
|
||||
};
|
||||
|
||||
# Share defaults - using mkDefault so they can be overridden per-host
|
||||
skyg.user = {
|
||||
name = lib.mkDefault user.name;
|
||||
fullName = lib.mkDefault user.fullName;
|
||||
email = lib.mkDefault user.email;
|
||||
};
|
||||
skyg.rootDir = rootDir;
|
||||
skyg.configsDir = configsDir;
|
||||
skyg.core.hostName = hostName;
|
||||
skyg.home-manager.version = lib.mkDefault "26.05";
|
||||
system.stateVersion = systemStateVersion;
|
||||
};
|
||||
skyg.rootDir = rootDir;
|
||||
skyg.configsDir = configsDir;
|
||||
skyg.core.hostName = hostName;
|
||||
skyg.home-manager.version = lib.mkDefault "26.05";
|
||||
system.stateVersion = systemStateVersion;
|
||||
}
|
||||
@@ -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 = [ ];
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
imports = [
|
||||
./hardware
|
||||
./containers
|
||||
./dns-records
|
||||
./core.nix
|
||||
./networking.nix
|
||||
./user.nix
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
# modules/nixos/common/dns-records/
|
||||
|
||||
Host-level registry of **internal DNS records**. This module configures *nothing* on the
|
||||
host — it is a pure data collection point. Records declared here are aggregated across all
|
||||
hosts at the flake level (`nix eval .#dnsRecords`) and pushed to the OpenWrt router's
|
||||
`dnsmasq.conf` by `skyg openwrt` (see `modules/openwrt/`).
|
||||
|
||||
## Why
|
||||
|
||||
Service IPs live in host configs (e.g. a container's static macvlan address in
|
||||
`hosts/hl-minipc2.nix`), but the router config lives in an encrypted JSON secret. Without a
|
||||
bridge, naming a service means writing its IP in two places that silently drift. This module
|
||||
is the single canonical shape everything writes to:
|
||||
|
||||
```nix
|
||||
{ ip = "10.0.101.2"; names = [ "drawdb.app.internal" ]; wildcard = false; source = "..."; }
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
| Option | Purpose |
|
||||
|---|---|
|
||||
| `skyg.dns.domain` | Default suffix for bare names. Default `app.internal`. |
|
||||
| `skyg.dns.extraRecords` | Hand-written records, keyed by name so they can be overridden. **Use this for arbitrary IPs.** |
|
||||
| `skyg.dns.records` | List form. Modules append here (container-services does). |
|
||||
| `skyg.dns.resolved` | Read-only: the above, names fully qualified + `host` attached. What the aggregator reads. |
|
||||
| `skyg.dns.writeDebugFile` | Dump `resolved` to `/etc/skyg/dns-records.json`. Default true. |
|
||||
|
||||
Names without a `.` get `skyg.dns.domain` appended: `"drawdb"` → `"drawdb.app.internal"`.
|
||||
Names containing a `.` are treated as fully-qualified and passed through untouched.
|
||||
|
||||
`wildcard = false` (the default) emits dnsmasq `host-record=name,ip` — a plain A record with
|
||||
reverse PTR. `wildcard = true` emits `address=/name/ip`, which also catches every subdomain.
|
||||
|
||||
## Examples
|
||||
|
||||
Arbitrary IP, no container involved:
|
||||
|
||||
```nix
|
||||
skyg.dns.extraRecords.nas = {
|
||||
ip = "10.0.0.50";
|
||||
names = [ "nas" "files" ]; # -> nas.app.internal, files.app.internal
|
||||
};
|
||||
```
|
||||
|
||||
From a container service (see `containers/container-services/`, which folds into `records`):
|
||||
|
||||
```nix
|
||||
skyg.nixos.common.container-services.drawdb.services.drawdb = {
|
||||
networks = { lan.ipv4_address = "10.0.101.2"; };
|
||||
dns.names = [ "drawdb" ];
|
||||
};
|
||||
```
|
||||
|
||||
## Deploying
|
||||
|
||||
Records are inert until pushed to the router:
|
||||
|
||||
```sh
|
||||
nix eval .#dnsRecords --json | jq # inspect the aggregate across all hosts
|
||||
skyg openwrt --dry-run # render dnsmasq.conf locally
|
||||
skyg openwrt # diff + confirm + apply on the router
|
||||
```
|
||||
|
||||
Conflicts (the same name mapped to two different IPs, on any host) fail flake evaluation.
|
||||
@@ -1,132 +0,0 @@
|
||||
{ config, lib, ... }:
|
||||
|
||||
let
|
||||
cfg = config.skyg.dns;
|
||||
|
||||
# Bare labels get the default domain appended; anything already containing a
|
||||
# dot is treated as fully-qualified and left alone.
|
||||
qualify = name:
|
||||
if lib.hasInfix "." name || cfg.domain == null || cfg.domain == ""
|
||||
then name
|
||||
else "${name}.${cfg.domain}";
|
||||
|
||||
recordType = lib.types.submodule ({ ... }: {
|
||||
options = {
|
||||
ip = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
example = "10.0.101.2";
|
||||
description = "IPv4 address the names should resolve to.";
|
||||
};
|
||||
|
||||
names = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
example = [ "drawdb" "drawdb.app.internal" ];
|
||||
description = ''
|
||||
DNS names for this address. Bare labels (no dot) are automatically
|
||||
suffixed with skyg.dns.domain.
|
||||
'';
|
||||
};
|
||||
|
||||
wildcard = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
When true, the record also matches every subdomain
|
||||
(dnsmasq `address=/name/ip`). When false, a plain host record is
|
||||
emitted (dnsmasq `host-record=name,ip`), which also provides reverse
|
||||
PTR lookups.
|
||||
'';
|
||||
};
|
||||
|
||||
source = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "manual";
|
||||
description = "Free-form provenance marker, used in generated comments.";
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
# Fully-qualified, host-tagged view of every record on this machine.
|
||||
resolved = map
|
||||
(r: {
|
||||
inherit (r) ip wildcard source;
|
||||
names = map qualify r.names;
|
||||
host = config.networking.hostName;
|
||||
})
|
||||
(cfg.records ++ (lib.attrValues cfg.extraRecords));
|
||||
|
||||
in
|
||||
{
|
||||
options.skyg.dns = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Collect internal DNS records declared on this host. Records are pure
|
||||
data -- they are aggregated at the flake level and pushed to the router
|
||||
by `skyg openwrt`; nothing is configured on the host itself beyond a
|
||||
debug dump in /etc/skyg/dns-records.json.
|
||||
'';
|
||||
};
|
||||
|
||||
domain = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = "app.internal";
|
||||
example = "lab.internal";
|
||||
description = "Default suffix appended to bare (dot-less) record names.";
|
||||
};
|
||||
|
||||
records = lib.mkOption {
|
||||
type = lib.types.listOf recordType;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Internal DNS records contributed by this host. Modules append to this
|
||||
list (see container-services' `dns.names`); prefer `extraRecords` for
|
||||
hand-written entries so they can be overridden by name.
|
||||
'';
|
||||
};
|
||||
|
||||
extraRecords = lib.mkOption {
|
||||
type = lib.types.attrsOf recordType;
|
||||
default = { };
|
||||
example = lib.literalExpression ''
|
||||
{
|
||||
nas = { ip = "10.0.0.50"; names = [ "nas" "files" ]; };
|
||||
}
|
||||
'';
|
||||
description = ''
|
||||
Hand-written DNS records, keyed by an arbitrary name so they can be
|
||||
overridden or removed from another module. Merged into `records`.
|
||||
'';
|
||||
};
|
||||
|
||||
resolved = lib.mkOption {
|
||||
type = lib.types.listOf (lib.types.attrsOf lib.types.anything);
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
description = ''
|
||||
Read-only: `records` + `extraRecords` with names fully qualified and the
|
||||
owning hostname attached. This is what the flake-level aggregator reads.
|
||||
'';
|
||||
};
|
||||
|
||||
writeDebugFile = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = "Write the resolved records to /etc/skyg/dns-records.json.";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
skyg.dns.resolved = resolved;
|
||||
|
||||
assertions = lib.flip map resolved (r: {
|
||||
assertion = r.names != [ ];
|
||||
message = "skyg.dns: record for ${r.ip} (source: ${r.source}) has no names.";
|
||||
});
|
||||
|
||||
environment.etc."skyg/dns-records.json" = lib.mkIf (cfg.writeDebugFile && resolved != [ ]) {
|
||||
text = builtins.toJSON resolved + "\n";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -32,7 +32,7 @@ Desktop/tiler hosts use **DankMaterialShell (DMS)** for the greeter, configured
|
||||
- Enable a compositor (`skyg.nixos.desktop.tiler.niri` or `…tiler.hyprland`), which flips the
|
||||
shared `tiler.enable` for you. Don't set `tiler.enable` directly.
|
||||
- Shared Wayland tooling, keyring, and polkit live in `tiler/default.nix` — add anything
|
||||
common to *all* tilers there, not in the individual compositor files.
|
||||
common to _all_ tilers there, not in the individual compositor files.
|
||||
|
||||
## Theming
|
||||
|
||||
@@ -50,7 +50,7 @@ everything.
|
||||
## Config symlinks
|
||||
|
||||
Some modules symlink files from the repo's `configs/` directory into `~/.config` via
|
||||
activation scripts (e.g. `x11/lib-gesture.nix` → `libinput-gestures.conf`). Edit the file in
|
||||
activation scripts. Edit the file in
|
||||
`configs/`, not the module, when changing that behaviour.
|
||||
|
||||
## Validation
|
||||
|
||||
@@ -99,21 +99,6 @@ in
|
||||
};
|
||||
|
||||
server = {
|
||||
ip = mkOption {
|
||||
type = types.str;
|
||||
default = "10.0.101.241";
|
||||
description = "Static IP on the ipvlan lab network for the server container.";
|
||||
};
|
||||
|
||||
dnsName = mkOption {
|
||||
type = types.str;
|
||||
default = "portainer";
|
||||
description = ''
|
||||
Internal DNS name for the server. The app.internal suffix is added
|
||||
automatically by the DNS module.
|
||||
'';
|
||||
};
|
||||
|
||||
tls = {
|
||||
enable = mkEnableOption "TLS with a lab CA certificate for the Portainer server";
|
||||
|
||||
@@ -183,8 +168,7 @@ in
|
||||
[ "/var/run/docker.sock:/var/run/docker.sock" "portainer_data:/data" ]
|
||||
++ lib.optional (cfg.server.tls.enable && cfg.server.tls.keySecretName != null)
|
||||
"${config.age.secrets.${cfg.server.tls.keySecretName}.path}:/certs/key.pem:ro";
|
||||
networks.lan.ipv4_address = cfg.server.ip;
|
||||
dns.names = [ cfg.server.dnsName ];
|
||||
networks.lan.ipv4_address = config.skyg.internalNetworkingMap.apps.portainer.ip;
|
||||
}
|
||||
// lib.optionalAttrs cfg.server.tls.enable {
|
||||
files."/certs/cert.pem" = cfg.server.tls.cert;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# modules/openwrt/
|
||||
|
||||
Config generator + deploy tooling for the homelab's **OpenWrt** router. This is *not* a NixOS
|
||||
Config generator + deploy tooling for the homelab's **OpenWrt** router. This is _not_ a NixOS
|
||||
module — it's a Nix function that builds a Rust generator and wraps it in an
|
||||
`openwrt-deploy` shell script. OpenWrt is managed out-of-band (the router isn't a NixOS host),
|
||||
so this provides a declarative, reviewable way to push `dnsmasq.conf` and `/etc/ethers`.
|
||||
@@ -24,12 +24,12 @@ exported env vars before inlining each file's content via `builtins.readFile`.
|
||||
## How it works
|
||||
|
||||
1. The router config lives as an **agenix secret** (e.g. `secrets/glmain.json.age`).
|
||||
1b. Before generating, the decrypted JSON's `generalMappings` are **merged** (via `jq`) with
|
||||
`$NIX_DNS_RECORDS` — the DNS records declared across all hosts through `skyg.dns`
|
||||
(see `modules/nixos/common/dns-records/`) and aggregated by `modules/dns-aggregate.nix`
|
||||
1b. Before generating, the decrypted JSON's `generalMappings` are **merged** (via `jq`) with
|
||||
`$NIX_DNS_RECORDS` — the router DNS records rendered from the global
|
||||
`skyg.internalNetworkingMap` (see `modules/main.nix`) by `modules/internal-networking.nix`
|
||||
into `packages.<sys>.skyg-dns-records`. The secret stays the source of truth for
|
||||
devices/MACs; **Nix owns service names**, so a container's DNS name lives next to the
|
||||
host config that owns its IP. Inspect the aggregate with `nix eval .#dnsRecords --json`.
|
||||
devices/MACs; **Nix owns service names**. Inspect the records with
|
||||
`nix eval .#dnsRecords --json`.
|
||||
2. `openwrt-deploy` reads the decrypted JSON from stdin, runs `openwrt-gen dnsmasq`,
|
||||
`openwrt-gen ethers`, and `openwrt-gen firewall` to render the three target files.
|
||||
3. It SSHes to the router, shows a **colorized unified diff** against the current files
|
||||
@@ -61,12 +61,12 @@ is passed as a command-line argument (default `glmain`).
|
||||
```bash
|
||||
skyg openwrt --dry-run
|
||||
# → .tmp/openwrt-glmain/dnsmasq.conf
|
||||
# → .tmp/openwrt-glmain/dns-records.json # the Nix-declared skyg.dns fragment merged in
|
||||
# → .tmp/openwrt-glmain/dns-records.json # the Nix-rendered internalNetworkingMap fragment merged in
|
||||
# → .tmp/openwrt-glmain/ethers
|
||||
# → .tmp/openwrt-glmain/firewall.batch # the exact `uci -m import firewall` input
|
||||
```
|
||||
|
||||
Use this to inspect what a deploy *would* do (especially the firewall rules) before running
|
||||
Use this to inspect what a deploy _would_ do (especially the firewall rules) before running
|
||||
the real `skyg openwrt`.
|
||||
|
||||
`router.ip` / `router.user` are taken from the `config` passed into `default.nix`.
|
||||
|
||||
@@ -17,9 +17,8 @@ in
|
||||
config:
|
||||
|
||||
let
|
||||
# Nix-generated DNS records (skyg.dns, aggregated across all hosts). Merged
|
||||
# into the decrypted secret's generalMappings by the scripts below, so
|
||||
# service names stay declarative next to the host config that owns the IP.
|
||||
# Nix-rendered DNS records from the global skyg.internalNetworkingMap. Merged
|
||||
# into the decrypted secret's generalMappings by the scripts below.
|
||||
# Empty fragment when the caller doesn't supply one.
|
||||
dnsRecords =
|
||||
if config ? dnsRecords && config.dnsRecords != null
|
||||
|
||||
@@ -36,10 +36,10 @@ openwrt-gen firewall < config.json # prints UCI firewall rules (uci batch form
|
||||
`wildcard` defaults to `true` (omitted in existing secrets) and renders
|
||||
`address=/domain/ip` + `address=/.domain/ip`, matching every subdomain too.
|
||||
Set `false` for a plain `host-record=domain,ip` (A record + reverse PTR) —
|
||||
this is what Nix-declared `skyg.dns` records use by default.
|
||||
this is what the Nix-rendered `skyg.internalNetworkingMap` records use.
|
||||
At deploy time this list is the **union** of the secret's entries and the
|
||||
records aggregated from every host's `skyg.dns` (see
|
||||
`modules/nixos/common/dns-records/`), merged by `jq` in `openwrt-deploy.sh`.
|
||||
records rendered from `skyg.internalNetworkingMap` (see
|
||||
`modules/internal-networking.nix`), merged by `jq` in `openwrt-deploy.sh`.
|
||||
- `networks`: `{ <network>: [ { mac, name, id?, domains?, justMac?, internetOnly? } ] }` —
|
||||
per-network hosts. A device with `internetOnly: true` is restricted to internet-only
|
||||
access (matched by MAC), on any network.
|
||||
@@ -56,7 +56,7 @@ LAN (`10.0.0.0/16` IPv4, `fd59:de0a:bff5::/48` IPv6). Two sources of restriction
|
||||
- **IPv4** — one rule per network matching the whole subnet (catches every device on it).
|
||||
- **IPv6** — one rule per known device MAC. All subnets share a single ULA /64
|
||||
(`fd59:de0a:bff5::/48`, see `network::ULA_PREFIX`), so subnets are not distinguishable
|
||||
in IPv6 and blocking is done per known device. An *unknown* IPv6-only device on those
|
||||
in IPv6 and blocking is done per known device. An _unknown_ IPv6-only device on those
|
||||
subnets is **not** blocked (inherent to the flat-L2 topology).
|
||||
|
||||
**Device-level** — for any device with `internetOnly: true` (on any network):
|
||||
|
||||
@@ -12,14 +12,14 @@ set -euo pipefail
|
||||
|
||||
SERVER="$ROUTER_USER@$ROUTER"
|
||||
|
||||
# Merge the Nix-declared DNS records (skyg.dns, aggregated across all hosts)
|
||||
# into the secret's generalMappings. The secret stays the source of truth for
|
||||
# Merge the Nix-rendered DNS records (skyg.internalNetworkingMap) into the
|
||||
# secret's generalMappings. The secret stays the source of truth for
|
||||
# devices/MACs; Nix owns service names.
|
||||
CONFIG=$(cat | jq --slurpfile nix "$NIX_DNS_RECORDS" \
|
||||
'.generalMappings = ((.generalMappings // []) + $nix[0].generalMappings)')
|
||||
|
||||
NIX_COUNT=$(jq '.generalMappings | length' "$NIX_DNS_RECORDS")
|
||||
echo "Merged $NIX_COUNT Nix-declared DNS mapping(s) from skyg.dns."
|
||||
echo "Merged $NIX_COUNT Nix-declared DNS mapping(s) from skyg.internalNetworkingMap."
|
||||
|
||||
DNSMASQ=$(echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen dnsmasq)
|
||||
ETHERS=$(echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen ethers)
|
||||
|
||||
@@ -11,7 +11,7 @@ if [ $# -ge 1 ]; then ROUTER="$1"; else ROUTER=glmain; fi
|
||||
OUTDIR=".tmp/openwrt-$ROUTER"
|
||||
mkdir -p "$OUTDIR"
|
||||
|
||||
# Same merge as the real deploy: secret config + Nix-declared skyg.dns records.
|
||||
# Same merge as the real deploy: secret config + Nix-rendered skyg.internalNetworkingMap records.
|
||||
CONFIG=$(cat | jq --slurpfile nix "$NIX_DNS_RECORDS" \
|
||||
'.generalMappings = ((.generalMappings // []) + $nix[0].generalMappings)')
|
||||
|
||||
@@ -25,4 +25,4 @@ echo "Dry-run configs written to $OUTDIR (no router changes made):"
|
||||
echo " $OUTDIR/dnsmasq.conf"
|
||||
echo " $OUTDIR/ethers"
|
||||
echo " $OUTDIR/firewall.batch"
|
||||
echo " $OUTDIR/dns-records.json # Nix-declared skyg.dns records merged in"
|
||||
echo " $OUTDIR/dns-records.json # Nix-rendered skyg.internalNetworkingMap records merged in"
|
||||
Reference in new issue
Block a user