refactor: реестр адресов флота lib/xlib/net.nix

Один адрес — одно имя. Раньше 192.168.1.20 был написан 41 раз, 100.64.0.0
— семь, а зона CoreDNS и vhost'ы nginx жили в разных файлах и разъезжались
(например, kuma.zeroq.su остался в DNS после отключения uptime-kuma).

Реестр: хосты (LAN/tailscale/public), публичные DNS, сети, общие порты.
Все хардкоды адресов флота переведены на xlib.net.*.

Намеренно не тронуто: 127.0.0.1 и 0.0.0.0 (константы языка, не топология),
сеть 10.66.0.0/24 (у PXE-инфраструктуры своя опционная поверхность) и
home/modules/opencode.nix (рабочая конфигурация агента владельца, её
рефакторинг запрещён ADR-0009).

Поведение не изменилось: config-fingerprint до/после совпадает по всем
шести хостам.
This commit is contained in:
oqyude committed 2026-11-15 06:34:12 +03:00
1 parent 53df473609
commit 0ab45578d1
11 files changed
+225 -80

No files matched your search

+3 -3
View File
@@ -154,9 +154,9 @@
# (см. configurations/mini-laptop.nix).
host.engipy-frontend = {
enable = true;
# По умолчанию backendHost = "192.168.1.102" (rydiwo LAN IP).
# Если rydiwo переедет на другой адрес — переопределить здесь.
backendHost = "192.168.1.102";
# По умолчанию — LAN-адрес rydiwo из реестра флота (lib/xlib/net.nix).
# Если rydiwo переедет на другой адрес — менять нужно там, а не здесь.
backendHost = xlib.net.hosts.rydiwo.lan;
};
system = {
+2 -2
View File
@@ -55,8 +55,8 @@
networking.firewall.interfaces.tailscale0.allowedTCPPorts = [ 22 ];
networking = {
nameservers = [
"1.1.1.1"
"8.8.8.8"
xlib.net.dns.cloudflare
xlib.net.dns.google
];
networkmanager.enable = true;
tempAddresses = "disabled";
+7 -7
View File
@@ -249,31 +249,31 @@
ControlPersist = "no";
};
sapphira = {
HostName = "192.168.1.20";
HostName = xlib.net.hosts.sapphira.lan;
User = xlib.device.username;
};
sapphira-tailscale = {
HostName = "100.64.0.0";
HostName = xlib.net.hosts.sapphira.tailscale;
User = xlib.device.username;
};
otreca-old = {
HostName = "217.60.3.12";
HostName = xlib.net.hosts.otreca.publicOld;
User = xlib.device.username;
};
otreca = {
HostName = "109.248.161.5";
HostName = xlib.net.hosts.otreca.public;
User = xlib.device.username;
};
otreca-tailscale = {
HostName = "100.64.1.0";
HostName = xlib.net.hosts.otreca.tailscale;
User = xlib.device.username;
};
rydiwo = {
HostName = "192.168.1.102";
HostName = xlib.net.hosts.rydiwo.lan;
User = xlib.device.username;
};
epral = {
HostName = "192.168.1.101";
HostName = xlib.net.hosts.epral.lan;
User = xlib.device.username;
Port = 8022;
};
+8
View File
@@ -4,6 +4,7 @@
# device.nix identity + capability flags from the device type
# dirs.nix well-known paths, derived from username
# helpers.nix pure helper functions shared by modules
# net.nix registry of fleet addresses and shared ports
#
# `mkXlib` is called in flake-level code (configurations/default.nix) and
# handed to every module as the `xlib` argument via lib/mkSystem.nix, so
@@ -24,6 +25,10 @@ let
mkDirs = import ./dirs.nix;
helpers = (import ./helpers.nix { inherit lib; });
# Fleet topology: addresses and shared ports. The same for every host —
# the fleet is the fleet.
net = import ./net.nix;
in
{
inherit
@@ -31,6 +36,7 @@ in
helpers
mkDevice
mkDirs
net
;
# Full host record: identity + capability flags + well-known paths +
@@ -67,6 +73,8 @@ in
isDesktop = device.isDesktop;
isHeadless = device.isHeadless;
dirs = mkDirs username;
# Fleet addresses and shared ports — see lib/xlib/net.nix.
inherit net;
# Bind the host's ids into the mount helpers, so ntfs3/exfat options
# carry the same uid/gid the primary user actually has.
helpers = import ./helpers.nix {
+127
View File
@@ -0,0 +1,127 @@
# Registry of the addresses and ports the fleet talks to.
#
# Why this file exists: the same literal was written in dozens of places
# (192.168.1.20 alone — 41 occurrences) across modules that had to agree on
# it without knowing about each other. A DHCP lease moves, a Tailscale address
# changes, and the copy nobody noticed keeps pointing at the old address. The
# repo already documents that failure mode for the 3x-ui chain (ADR-0003);
# this file is the same idea applied to plain addresses.
#
# How to use it: `xlib.net.hosts.sapphira.lan`. The registry is pure data and
# is injected into every module as `xlib.net` (see lib/xlib/default.nix), so
# it is available both in NixOS modules and in home-manager modules.
#
# Rules for this file:
# * one address — one name. If a literal appears in two modules, both read
# it from here.
# * Loopback (127.0.0.1) and the wildcard (0.0.0.0) are NOT registered:
# they are language-level constants, not fleet topology, and reading
# `xlib.net.loopback` would be noise.
# * A value owned completely by one module (a service's own port) stays in
# that module. `ports` below holds only the ports that are a contract
# between two or more modules.
# * Modules listed under "not migrated" at the bottom keep their literals
# on purpose — see the note there before touching them.
{
hosts = {
# The home server: runs the services, terminates nginx.
sapphira = {
lan = "192.168.1.20";
# Tailscale address, assigned manually (AGENTS.md invariant 4).
tailscale = "100.64.0.0";
};
# Chuwi MiniBook — desktop (secondary).
rydiwo = {
# DHCP lease. It already moved to another machine once (LAMET), which is
# exactly why the tailscale address below is the one used for upstream.
lan = "192.168.1.102";
tailscale = "100.92.238.19";
};
# Windows workstation — the opencode reference machine. Not described in
# Nix; only its address is known here.
vetymae = {
lan = "192.168.1.100";
};
# Other tailnet members publishing an opencode server.
lamet = {
tailscale = "100.106.21.39";
};
etherea = {
tailscale = "100.125.228.63";
};
dejavu = {
tailscale = "100.86.134.111";
};
# Android device (nix-on-droid), reachable over the LAN on port 8022.
epral = {
lan = "192.168.1.101";
};
# VPS.
otreca = {
public = "109.248.161.5";
# Previous public address — kept for the `otrea-old` ssh alias.
publicOld = "217.60.3.12";
tailscale = "100.64.1.0";
};
# Home router: the LAN gateway and the public address behind
# home.zeroq.su (the wildcard CNAME target for *.opencodes.zeroq.su).
router = {
lan = "192.168.1.1";
public = "37.128.246.126";
};
};
# Public resolvers.
dns = {
cloudflare = "1.1.1.1";
google = "8.8.8.8";
};
# Networks, in CIDR form.
networks = {
lan = "192.168.1.0/24";
tailscale = "100.64.0.0/10";
# Podman's default network and the network tape-rotation creates.
podman = "10.88.0.0/16";
podmanTapeRotation = "10.89.0.0/24";
};
# Static addresses of containers inside the podman networks above. They are
# not fleet machines — they only exist inside their own network.
containerHosts = {
# tape-rotation backend: the frontend reaches it by this address because
# the network has no DNS plugin (--add-host).
tapeRotationBackend = "10.89.0.10";
};
# Ports that are a contract between two or more modules.
ports = {
# opencode server: the systemd user service on sapphira, the nginx vhost
# `opencode.zeroq.su`, and the `oc` wrapper on every host.
opencode = 4096;
# Authelia forward-auth endpoint — nginx asks it about every protected
# vhost.
authelia = 9091;
# Host-side port that publishes the 3x-ui container's REALITY inbound
# (nginx stream forwards 443 -> 15380 -> container:443).
reality3xui = 15380;
# Egress proxy published by the 3x-ui container on the host loopback.
httpProxy = 10808;
};
# Not migrated, on purpose:
# * home/modules/opencode.nix (sapphira) — the working opencode setup of
# the owner; AGENTS.md / ADR-0009 forbid refactoring it. Its proxy
# environment keeps literal addresses.
# * modules/pxe-infra/* — the PXE network has its own option surface
# (modules/pxe-infra/options.nix); a second registry for the same
# addresses would be a worse problem than the literals it replaces.
# * The podman networks of the other containers — assigned by podman
# itself; only the two networks above are referenced from two modules.
}
+3 -3
View File
@@ -70,7 +70,7 @@ in
"--network=taperotation_default"
# Static IP the frontend reaches "backend" at (see --add-host
# in the frontend container; network DNS is disabled).
"--ip=10.89.0.10"
"--ip=${xlib.net.containerHosts.tapeRotationBackend}"
];
};
"taperotation-frontend" = {
@@ -83,7 +83,7 @@ in
"--network=taperotation_default"
# Baked-in nginx upstream is http://backend:8001; resolve it via
# /etc/hosts since the network has no DNS plugin.
"--add-host=backend:10.89.0.10"
"--add-host=backend:${xlib.net.containerHosts.tapeRotationBackend}"
];
};
};
@@ -144,7 +144,7 @@ in
# backend's static IP. Recreate-on-start also self-heals after a
# `podman system prune` removed the (temporarily unused) network.
podman network rm -f taperotation_default >/dev/null 2>&1 || true
podman network create --disable-dns --subnet=10.89.0.0/24 taperotation_default
podman network create --disable-dns --subnet=${xlib.net.networks.podmanTapeRotation} taperotation_default
'';
partOf = [ "podman-compose-tape-rotation-root.target" ];
wantedBy = [ "podman-compose-tape-rotation-root.target" ];
+45 -38
View File
@@ -1,34 +1,41 @@
{
config,
pkgs,
xlib,
...
}:
# CoreDNS — the authoritative server for the `zeroq.su` (public) and
# `home.arpa` (LAN-only) zones.
#
# Every address here comes from the fleet registry (lib/xlib/net.nix): the
# zone and the nginx vhosts have to agree, and a DHCP lease that moved must
# not leave half of the zone pointing at the old machine.
{
services.coredns = {
enable = true;
config = ''
zeroq.su:53 {
hosts {
109.248.161.5 x.zeroq.su
192.168.1.20 authelia.zeroq.su
192.168.1.20 calibre.zeroq.su
192.168.1.20 dns.zeroq.su
192.168.1.20 flux.zeroq.su
192.168.1.20 git.zeroq.su
192.168.1.20 glances.zeroq.su
192.168.1.20 herdr.zeroq.su
192.168.1.20 homebox.zeroq.su
192.168.1.20 immich.zeroq.su
192.168.1.20 kuma.zeroq.su
192.168.1.20 navidrome.zeroq.su
192.168.1.20 nextcloud.zeroq.su
192.168.1.20 open.zeroq.su
192.168.1.20 office.zeroq.su
192.168.1.20 pdf.zeroq.su
192.168.1.20 syncthing.zeroq.su
192.168.1.20 talk.zeroq.su
192.168.1.20 turn.zeroq.su
192.168.1.20 vtimeline.zeroq.su
${xlib.net.hosts.otreca.public} x.zeroq.su
${xlib.net.hosts.sapphira.lan} authelia.zeroq.su
${xlib.net.hosts.sapphira.lan} calibre.zeroq.su
${xlib.net.hosts.sapphira.lan} dns.zeroq.su
${xlib.net.hosts.sapphira.lan} flux.zeroq.su
${xlib.net.hosts.sapphira.lan} git.zeroq.su
${xlib.net.hosts.sapphira.lan} glances.zeroq.su
${xlib.net.hosts.sapphira.lan} herdr.zeroq.su
${xlib.net.hosts.sapphira.lan} homebox.zeroq.su
${xlib.net.hosts.sapphira.lan} immich.zeroq.su
${xlib.net.hosts.sapphira.lan} kuma.zeroq.su
${xlib.net.hosts.sapphira.lan} navidrome.zeroq.su
${xlib.net.hosts.sapphira.lan} nextcloud.zeroq.su
${xlib.net.hosts.sapphira.lan} open.zeroq.su
${xlib.net.hosts.sapphira.lan} office.zeroq.su
${xlib.net.hosts.sapphira.lan} pdf.zeroq.su
${xlib.net.hosts.sapphira.lan} syncthing.zeroq.su
${xlib.net.hosts.sapphira.lan} talk.zeroq.su
${xlib.net.hosts.sapphira.lan} turn.zeroq.su
${xlib.net.hosts.sapphira.lan} vtimeline.zeroq.su
fallthrough
}
cache 300
@@ -36,30 +43,30 @@
}
home.arpa:53 {
hosts {
192.168.1.100 vetymae.home.arpa
192.168.1.20 ca.home.arpa
192.168.1.20 calibre.home.arpa
192.168.1.20 dns.home.arpa
192.168.1.20 flux.home.arpa
192.168.1.20 git.home.arpa
192.168.1.20 glances.home.arpa
192.168.1.20 home.arpa
192.168.1.20 homebox.home.arpa
192.168.1.20 immich.home.arpa
192.168.1.20 kuma.home.arpa
192.168.1.20 navidrome.home.arpa
192.168.1.20 nextcloud.home.arpa
192.168.1.20 office.home.arpa
192.168.1.20 pdf.home.arpa
192.168.1.20 sapphira.home.arpa
192.168.1.20 syncthing.home.arpa
${xlib.net.hosts.vetymae.lan} vetymae.home.arpa
${xlib.net.hosts.sapphira.lan} ca.home.arpa
${xlib.net.hosts.sapphira.lan} calibre.home.arpa
${xlib.net.hosts.sapphira.lan} dns.home.arpa
${xlib.net.hosts.sapphira.lan} flux.home.arpa
${xlib.net.hosts.sapphira.lan} git.home.arpa
${xlib.net.hosts.sapphira.lan} glances.home.arpa
${xlib.net.hosts.sapphira.lan} home.arpa
${xlib.net.hosts.sapphira.lan} homebox.home.arpa
${xlib.net.hosts.sapphira.lan} immich.home.arpa
${xlib.net.hosts.sapphira.lan} kuma.home.arpa
${xlib.net.hosts.sapphira.lan} navidrome.home.arpa
${xlib.net.hosts.sapphira.lan} nextcloud.home.arpa
${xlib.net.hosts.sapphira.lan} office.home.arpa
${xlib.net.hosts.sapphira.lan} pdf.home.arpa
${xlib.net.hosts.sapphira.lan} sapphira.home.arpa
${xlib.net.hosts.sapphira.lan} syncthing.home.arpa
fallthrough
}
cache 300
log
}
.:53 {
forward . 192.168.1.1 1.1.1.1
forward . ${xlib.net.hosts.router.lan} ${xlib.net.dns.cloudflare}
cache 300
}
'';
+4 -3
View File
@@ -1,6 +1,7 @@
{
config,
lib,
xlib,
...
}:
# engipy — frontend-only nginx vhost для sapphira.
@@ -54,12 +55,12 @@ in
backendHost = lib.mkOption {
type = lib.types.str;
default = "192.168.1.102";
default = xlib.net.hosts.rydiwo.lan;
example = "rydiwo.lan";
description = ''
Хост, где крутится uvicorn (engipy-backend). По умолчанию
rydiwo — 192.168.1.102 в LAN. По этому адресу nginx проксирует
/api/* внутри vhost'а.
rydiwo — его LAN-адрес из реестра флота (lib/xlib/net.nix).
По этому адресу nginx проксирует /api/* внутри vhost'а.
'';
};
+7 -7
View File
@@ -78,9 +78,9 @@ in
settings = {
log_type = "file";
trusted_domains = [
"100.64.0.0"
"192.168.1.20"
"37.128.246.126"
xlib.net.hosts.sapphira.tailscale
xlib.net.hosts.sapphira.lan
xlib.net.hosts.router.public
"localhost"
"nextcloud.home.arpa"
"nextcloud.private"
@@ -89,10 +89,10 @@ in
"office.zeroq.su"
];
trusted_proxies = [
"100.64.1.0"
"109.248.161.5"
"192.168.1.20"
"37.128.246.126"
xlib.net.hosts.otreca.tailscale
xlib.net.hosts.otreca.public
xlib.net.hosts.sapphira.lan
xlib.net.hosts.router.public
];
overwriteprotocol = "https"; # maybe no
};
+18 -16
View File
@@ -9,7 +9,9 @@
# x.zeroq.su is the 3x-ui controller panel — see 3x-ui.nix for the
# /subs/, /subsjs/, /clash/ routing logic.
let
server = "192.168.1.20";
# Upstream host for the `sites` list below — the LAN address of the home
# server, from the fleet registry (lib/xlib/net.nix).
server = xlib.net.hosts.sapphira.lan;
mkProxy =
{
@@ -113,11 +115,11 @@ in
enableACME = false;
listen = [
{
addr = "100.64.0.0";
addr = xlib.net.hosts.sapphira.tailscale;
port = 10000;
}
{
addr = "192.168.1.20";
addr = xlib.net.hosts.sapphira.lan;
port = 10000;
}
{
@@ -174,7 +176,7 @@ in
"= /authelia" = {
extraConfig = ''
internal;
proxy_pass http://127.0.0.1:9091/api/authz/forward-auth;
proxy_pass http://127.0.0.1:${toString xlib.net.ports.authelia}/api/authz/forward-auth;
# Never forward the client request body to the auth
# subrequest. nginx relays the original Content-Length to
# /authelia but does not relay the body itself, so Authelia
@@ -236,7 +238,7 @@ in
"= /authelia" = {
extraConfig = ''
internal;
proxy_pass http://127.0.0.1:9091/api/authz/forward-auth;
proxy_pass http://127.0.0.1:${toString xlib.net.ports.authelia}/api/authz/forward-auth;
# Never forward the client request body to the auth
# subrequest. nginx relays the original Content-Length to
# /authelia but does not relay the body itself, so Authelia
@@ -291,7 +293,7 @@ in
enableACME = true;
locations = {
"/" = {
proxyPass = "http://192.168.1.100:8083";
proxyPass = "http://${xlib.net.hosts.vetymae.lan}:8083";
proxyWebsockets = true;
extraConfig = ''
auth_request /authelia;
@@ -311,7 +313,7 @@ in
"= /authelia" = {
extraConfig = ''
internal;
proxy_pass http://127.0.0.1:9091/api/authz/forward-auth;
proxy_pass http://127.0.0.1:${toString xlib.net.ports.authelia}/api/authz/forward-auth;
# Тело запроса в subrequest не отправляем: Authelia решает по
# заголовкам, а без этого он ждёт байты, которых не будет, и
# отвечает 408 — статус, который auth_request не классифицирует
@@ -432,7 +434,7 @@ in
forceSSL = true;
enableACME = true;
locations."/" = {
proxyPass = "http://127.0.0.1:9091";
proxyPass = "http://127.0.0.1:${toString xlib.net.ports.authelia}";
proxyWebsockets = true;
};
};
@@ -445,11 +447,11 @@ in
port = 80;
}
{
addr = "100.64.0.0";
addr = xlib.net.hosts.sapphira.tailscale;
port = 8446;
}
{
addr = "192.168.1.20";
addr = xlib.net.hosts.sapphira.lan;
port = 8446;
}
{
@@ -536,7 +538,7 @@ in
forceSSL = true;
enableACME = true;
locations."/" = {
proxyPass = "http://192.168.1.100:4096";
proxyPass = "http://${xlib.net.hosts.vetymae.lan}:${toString xlib.net.ports.opencode}";
proxyWebsockets = true;
};
};
@@ -544,7 +546,7 @@ in
forceSSL = true;
enableACME = true;
locations."/" = {
proxyPass = "http://100.106.21.39:4096";
proxyPass = "http://${xlib.net.hosts.lamet.tailscale}:${toString xlib.net.ports.opencode}";
proxyWebsockets = true;
};
};
@@ -571,7 +573,7 @@ in
forceSSL = true;
enableACME = true;
locations."/" = {
proxyPass = "http://100.125.228.63:4096";
proxyPass = "http://${xlib.net.hosts.etherea.tailscale}:${toString xlib.net.ports.opencode}";
proxyWebsockets = true;
};
};
@@ -586,7 +588,7 @@ in
forceSSL = true;
enableACME = true;
locations."/" = {
proxyPass = "http://100.86.134.111:4096";
proxyPass = "http://${xlib.net.hosts.dejavu.tailscale}:${toString xlib.net.ports.opencode}";
proxyWebsockets = true;
};
};
@@ -607,7 +609,7 @@ in
forceSSL = true;
enableACME = true;
locations."/" = {
proxyPass = "http://100.92.238.19:4096";
proxyPass = "http://${xlib.net.hosts.rydiwo.tailscale}:${toString xlib.net.ports.opencode}";
proxyWebsockets = true;
};
};
@@ -618,7 +620,7 @@ in
forceSSL = true;
enableACME = true;
locations."/" = {
proxyPass = "http://127.0.0.1:4096";
proxyPass = "http://127.0.0.1:${toString xlib.net.ports.opencode}";
proxyWebsockets = true;
};
};
+1 -1
View File
@@ -7,7 +7,7 @@
}:
let
serviceName = "rsync-services-sync";
serverAddress = "${xlib.device.username}@100.64.0.0";
serverAddress = "${xlib.device.username}@${xlib.net.hosts.sapphira.tailscale}";
serverDir = "${xlib.dirs.services-nodes-folder}/${xlib.device.hostname}";
nodeDir = "${xlib.dirs.services-mnt-folder}";
in