dns + keybinding consolidation

This commit is contained in:
ari committed 2026-09-21 10:52:32 -04:00
1 parent df46627173
commit f8444b1549
23 files changed
+612 -109

No files matched your search

+15 -10
View File
@@ -32,7 +32,12 @@ split under `conf/` and pulled in with `require()`.
inside quickshell-based apps fail silently (hyprwm/Hyprland#14844). There is
intentionally no waybar/hyprpanel.
- **Keybinds:** `conf/keybindings.lua` mirrors `configs/niri/shared/binds.kdl`
and `configs/niri/dms/binds.kdl` as closely as Hyprland allows.
and `configs/niri/dms/binds.kdl` as closely as Hyprland allows. `Mod+Alt+E`
opens this file in Zed (`zeditor`), mirroring niri's `Mod+Alt+E` ->
`shared/binds.kdl`. Windows are moved around with `Mod+Ctrl+arrows`
(`Mod+Ctrl+Left/Right` move in a direction, `Mod+Ctrl+Up/Down` move to a
workspace), and the `Mod+Shift` media/volume binds mirror niri's "Basic Sound
Control" block. Hyprland groups/tabs are intentionally unused.
- **Overview:** A standalone Quickshell config (`configs/fwbook/quickshell/overview/`,
symlinked to `~/.config/quickshell/overview` by the
`skyg.nixos.desktop.tiler.quickshell` module) provides a niri-like scrolling
@@ -62,9 +67,9 @@ hypr/
├── animations.lua # workspaces slide = "slidevert" (niri-like); only the `workspaces`
│ # leaf overridden — other styles: slide, fade, slidefade, slidefadevert
├── monitors.lua # hl.monitor per display (from configs/niri/.../outputs.kdl)
├── inputs.lua # touchpad tap + natural scroll, kb us, hl.gesture
├── inputs.lua # touchpad tap + natural scroll, kb us, hl.gesture (incl. Mod+swipe workspace-to-monitor)
├── window-rules.lua # hl.window_rule floats for small dialogs/utilities
├── keybindings.lua # niri + noctalia binds, scrolling dispatchers (hl.bind/hl.dsp); Mod+Tab toggles the Quickshell overview
├── keybindings.lua # niri + noctalia binds, scrolling dispatchers (hl.bind/hl.dsp); Mod+Tab toggles the Quickshell overview; Mod+Ctrl moves windows, Mod+Shift is media/volume
└── autostart.lua # noctalia + Quickshell overview via setpriv (hl.on hyprland.start; drops compositor caps)
```
@@ -72,11 +77,10 @@ hypr/
- `Mod+Shift+H` (show-hotkey-overlay) — no native Hyprland equivalent; left commented.
- `Mod+Escape` (toggle-keyboard-shortcuts-inhibit) — no native equivalent; omitted.
- `Mod+W` (toggle-column-tabbed-display) — mapped to `hl.dsp.group.toggle()` as the nearest
analog. Additional group binds were added on top via `hyprctl dispatch` (the extra
dispatchers aren't wrapped by `hl.dsp`): `Mod+Shift+W` (merge into an adjacent group),
`Mod+Alt+W` (pull out of a group), `Mod+Alt+Left/Right` (cycle through the active
group's tabs; no-op outside a group), and `Mod+Shift+G` (lock/unlock the group).
- `Mod+C` (center-column) — Hyprland runs the `focus current` scrolling dispatch.
- `Mod+Ctrl+F` (reset-window-height) — the scrolling layout has no per-window
height reset, so it maps to `layout "fit active"` (resets the focused column
to full width).
- `Mod+Tab` (toggle-overview) — the Quickshell scrolling overview (see above);
previously a pure-Lua wofi picker, then the ScrollOverview plugin, and
`cyclenext` before that.
@@ -88,8 +92,9 @@ niri's 3-finger swipes are mirrored in `conf/inputs.lua`:
- **Horizontal** → `scroll_move` (scroll through columns along the tape)
- **Vertical** → `workspace` (switch workspaces up/down)
- **Mod + swipe (any direction)** → move the whole workspace to the monitor in
that direction (`movecurrentworkspacetomonitor`), mirroring niri's
`Mod+TouchpadScroll*` binds. This replaced the old `Mod + mouse wheel` approach.
that direction (`hyprctl dispatch movecurrentworkspacetomonitor`), mirroring
niri's `Mod+TouchpadScroll*` binds. Swipe direction maps to the same monitor
direction (up→up, down→down, left→left, right→right).
- **4-finger up/down** → open/close the Quickshell scrolling overview (see
Overview above). `hl.gesture` is a discrete trigger, so there's no
swipe-progress animation.
+35
View File
@@ -14,6 +14,41 @@ hl.config({
hl.gesture({ fingers = 3, direction = "horizontal", action = "scroll_move" })
hl.gesture({ fingers = 3, direction = "vertical", action = "workspace" })
-- Mod + 3-finger swipe: move the whole workspace to the monitor in that
-- direction (mirrors niri's Mod+TouchpadScroll* binds).
hl.gesture({
fingers = 3,
direction = "up",
mods = "SUPER",
action = function()
hl.exec_cmd("hyprctl dispatch movecurrentworkspacetomonitor u")
end,
})
hl.gesture({
fingers = 3,
direction = "down",
mods = "SUPER",
action = function()
hl.exec_cmd("hyprctl dispatch movecurrentworkspacetomonitor d")
end,
})
hl.gesture({
fingers = 3,
direction = "left",
mods = "SUPER",
action = function()
hl.exec_cmd("hyprctl dispatch movecurrentworkspacetomonitor l")
end,
})
hl.gesture({
fingers = 3,
direction = "right",
mods = "SUPER",
action = function()
hl.exec_cmd("hyprctl dispatch movecurrentworkspacetomonitor r")
end,
})
hl.gesture({
fingers = 4,
direction = "up",
+24 -56
View File
@@ -10,6 +10,7 @@ hl.bind(mod .. " + T", hl.dsp.exec_cmd("ghostty"))
hl.bind(mod .. " + Z", hl.dsp.exec_cmd("flatpak run app.zen_browser.zen"))
hl.bind(mod .. " + B", hl.dsp.exec_cmd("chromium"))
hl.bind(mod .. " + E", hl.dsp.exec_cmd("wofi-emoji"))
hl.bind(mod .. " + ALT + E", hl.dsp.exec_cmd("zeditor ~/.config/hypr/conf/keybindings.lua"))
hl.bind(mod .. " + Q", hl.dsp.window.close())
-- =========================
@@ -27,58 +28,12 @@ hl.bind(mod .. " + SHIFT + Tab", hl.dsp.focus({ monitor = "+1" }))
-- =========================
-- Window Management
-- =========================
-- hl.bind(mod .. " + CTRL + right", function()
-- hl.dispatch(hl.dsp.resize({x = 1, relative = true}))
-- hl.dispatch(hl.dsp.layout("swapcol r"))
-- end)
-- hl.bind(mod .. " + SHIFT + right", hl.dsp.layout("swapcol r"))
-- hl.bind(mod .. " + SHIFT + left", hl.dsp.layout("swapcol l"))
hl.bind(
mod .. " + SHIFT + right",
hl.dsp.window.move({
direction = "right",
follow = true,
group_aware = true,
into_or_create_group = true,
})
)
hl.bind(
mod .. " + SHIFT + left",
hl.dsp.window.move({
direction = "left",
follow = true,
group_aware = true,
into_or_create_group = true,
})
)
hl.bind(
mod .. " + SHIFT + up",
hl.dsp.window.move({ workspace = "r-1", follow = true, group_aware = true })
)
hl.bind(
mod .. " + SHIFT + down",
hl.dsp.window.move({ workspace = "r+1", follow = true, group_aware = true })
)
-- Move windows around with Mod+Ctrl+arrows (mirrors niri's Mod+Ctrl binds).
hl.bind(mod .. " + CTRL + right", hl.dsp.window.move({ direction = "right", follow = true }))
hl.bind(mod .. " + CTRL + left", hl.dsp.window.move({ direction = "left", follow = true }))
hl.bind(mod .. " + CTRL + up", hl.dsp.window.move({ workspace = "r-1", follow = true }))
hl.bind(mod .. " + CTRL + down", hl.dsp.window.move({ workspace = "r+1", follow = true }))
hl.bind(mod .. " + F", hl.dsp.window.fullscreen({ mode = "maximized", action = "toggle" }))
hl.bind(
mod .. " + CTRL + right",
hl.dsp.window.move({ direction = "right", into_or_create_group = "right" })
)
hl.bind(
mod .. " + CTRL + left",
hl.dsp.window.move({ direction = "left", into_or_create_group = "left" })
)
hl.bind(
mod .. " + CTRL + up",
hl.dsp.window.move({ direction = "up", into_or_create_group = "up" })
)
hl.bind(
mod .. " + CTRL + down",
hl.dsp.window.move({ direction = "down", into_or_create_group = "down" })
)
hl.bind(mod .. " + G", hl.dsp.group.toggle())
hl.bind(mod .. " + SHIFT + F", hl.dsp.window.fullscreen({ mode = "fullscreen", action = "toggle" }))
hl.bind(mod .. " + V", hl.dsp.window.float({ action = "toggle" }))
hl.bind(mod .. " + C", hl.dsp.layout("focus current"))
@@ -91,6 +46,7 @@ hl.bind(mod .. " + minus", hl.dsp.layout("colresize -0.1"))
hl.bind(mod .. " + equal", hl.dsp.layout("colresize +0.1"))
hl.bind(mod .. " + SHIFT + minus", hl.dsp.window.resize({ x = 0, y = -50, relative = true }))
hl.bind(mod .. " + SHIFT + equal", hl.dsp.window.resize({ x = 0, y = 50, relative = true }))
hl.bind(mod .. " + CTRL + F", hl.dsp.layout("fit active"))
-- =========================
-- Screenshots & Recording
@@ -134,12 +90,24 @@ hl.bind(
-- Dismiss all notifications
hl.bind(mod .. " + ALT + L", hl.dsp.exec_cmd("noctalia msg notification-clear-active"))
-- Media & volume (mirrors niri's Mod+Shift block)
hl.bind(mod .. " + SHIFT + right", hl.dsp.exec_cmd("playerctl next"))
hl.bind(mod .. " + SHIFT + left", hl.dsp.exec_cmd("playerctl previous"))
hl.bind(mod .. " + SHIFT + up", hl.dsp.exec_cmd("playerctl volume 0.1+"), { locked = true })
hl.bind(mod .. " + SHIFT + down", hl.dsp.exec_cmd("playerctl volume 0.1-"), { locked = true })
hl.bind(mod .. " + SHIFT + Space", hl.dsp.exec_cmd("playerctl play-pause"), { locked = true })
hl.bind(
mod .. " + SHIFT + M",
hl.dsp.exec_cmd("wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"),
{ locked = true }
)
hl.bind(
mod .. " + SHIFT + S",
hl.dsp.exec_cmd("wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle"),
{ locked = true }
)
-- Media & brightness
-- hl.bind(mod .. " + M + up", hl.dsp.exec_cmd("noctalia msg volume-up"))
-- hl.bind(mod .. " + M + down", hl.dsp.exec_cmd("noctalia msg volume-down"))
-- hl.bind(mod .. " + M + right", hl.dsp.exec_cmd("playerctl next"))
-- hl.bind(mod .. " + M + left", hl.dsp.exec_cmd("playerctl previous"))
-- hl.bind(mod .. " + M + Space", hl.dsp.exec_cmd("playerctl play-pause"))
hl.bind("XF86AudioPause", hl.dsp.exec_cmd("playerctl play-pause"))
hl.bind("XF86AudioRaiseVolume", hl.dsp.exec_cmd("noctalia msg volume-up"), { locked = true })
hl.bind("XF86AudioLowerVolume", hl.dsp.exec_cmd("noctalia msg volume-down"), { locked = true })
@@ -62,7 +62,6 @@ hl.window_rule({
match = { float = true },
name = "float-style",
no_screen_share = true,
xray = true,
})
hl.window_rule({
match = { class = "^chrome-.*" },
+1 -1
View File
@@ -13,6 +13,7 @@ binds {
Mod+Z { spawn "flatpak" "run" "app.zen_browser.zen"; }
Mod+B { spawn "chromium"; }
Mod+E { spawn "wofi-emoji"; }
Mod+Alt+E { spawn-sh "zeditor ~/.config/niri/shared/binds.kdl"; }
Mod+Q { close-window; }
// =========================
@@ -34,7 +35,6 @@ binds {
Mod+Ctrl+Up { move-window-to-workspace-up; }
Mod+Ctrl+Down { move-window-to-workspace-down; }
Mod+W { toggle-column-tabbed-display; }
Mod+F { maximize-column; }
Mod+Shift+F { fullscreen-window; }
Mod+Ctrl+F { reset-window-height; }
+14 -2
View File
@@ -157,6 +157,7 @@
};
}
;
dnsAggregate = import ./modules/dns-aggregate.nix { inherit (nixpkgs) lib; };
in
{
# Dev Setups
@@ -227,15 +228,26 @@
}
);
lib = lib;
# Flat view of every internal DNS record declared by any host:
# nix eval .#dnsRecords --json | jq
dnsRecords = dnsAggregate.records self.nixosConfigurations;
formatter = lib.eachSystem (system: nixpkgs.legacyPackages.${system}.nixpkgs-fmt);
packages = lib.eachSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
openwrt = import ./modules/openwrt { inherit pkgs; inherit (nixpkgs) lib; };
# Internal DNS records declared across all hosts (skyg.dns), rendered
# as the generalMappings fragment merged into the router config.
dnsRecordsFile = pkgs.writeText "skyg-dns-records.json"
(builtins.toJSON (dnsAggregate.json self.nixosConfigurations));
glmain = (import ./openwrt-routers/glmain.nix) // { dnsRecords = dnsRecordsFile; };
in
{
openwrt-glmain = (openwrt (import ./openwrt-routers/glmain.nix)).deployScript;
openwrt-glmain-dry-run = (openwrt (import ./openwrt-routers/glmain.nix)).dryRunScript;
openwrt-glmain = (openwrt glmain).deployScript;
openwrt-glmain-dry-run = (openwrt glmain).dryRunScript;
skyg-dns-records = dnsRecordsFile;
ds4 = my-nixpkgs.legacyPackages.${system}.ds4;
buzz-desktop = lib.pkgs.${system}.buzz-desktop;
colibri = lib.pkgs.${system}.colibri;
+30 -31
View File
@@ -31,6 +31,13 @@ let
port = 3000;
ip = "10.0.101.3";
bucket = "buzz-media";
images = {
relay = "ghcr.io/block/buzz:main";
posgres = "postgres:17-alpine";
redis = "redis:7-alpine";
minio = "quay.io/minio/minio:RELEASE.2025-09-07T16-13-09Z@sha256:14cea493d9a34af32f524e538b8346cf79f3321eff8e708c1e2960462bd8936e";
mc = "quay.io/minio/mc:RELEASE.2025-08-13T08-35-41Z@sha256:a7fe349ef4bd8521fb8497f55c6042871b2ae640607cf99d9bede5e9bdf11727";
};
};
# NFS-backed volume on tnas1 (repo pattern: compose volume with nfs driver_opts).
# The server must be in `device` (the local driver uses it as the mount source);
@@ -226,33 +233,31 @@ in
};
};
# Buzz — relay + postgres + redis + garage (S3). Reachable at
# Buzz — relay + postgres + redis + minio (S3). Reachable at
# http://buzz.lab.internal:3000 on its own macvlan IP (10.0.101.3).
# Data lives on tnas1 via NFS-backed compose volumes (/mnt/SmallG/buzz).
age.secrets.buzz-env.file = ../secrets/buzz-env.age;
skyg.nixos.common.container-services.buzz = {
enable = true;
autoUpdate.enable = true;
# Image pulls on first start / after a tag moves can exceed the 120s default.
timeoutStartSec = 600;
networks = {
internal = { driver = "bridge"; };
# Shared macvlan network created by skyg.nixos.common.containers.networks.lab.
lan = config.skyg.nixos.common.containers.networks.lab.compose;
};
volumes = {
buzz-postgres = nfsVolume "postgres";
buzz-redis = nfsVolume "redis";
buzz-garage = nfsVolume "garage";
s3 = nfsVolume "s3";
buzz-git = nfsVolume "git";
};
services = {
relay = {
image = "ghcr.io/block/buzz:main";
dependsOn = [ "postgres" "redis" "garage" ];
image = buzz.images.relay;
dependsOn = [ "postgres" "redis" "minio" ];
networks = {
internal = { };
lan = { ipv4_address = buzz.ip; };
@@ -266,8 +271,8 @@ in
BUZZ_MEDIA_BASE_URL = "http://${buzz.domain}:${toString buzz.port}/media";
BUZZ_MEDIA_SERVER_DOMAIN = "${buzz.domain}:${toString buzz.port}";
BUZZ_CORS_ORIGINS = "http://${buzz.domain}:${toString buzz.port}";
BUZZ_S3_ENDPOINT = "http://garage:3900";
BUZZ_S3_REGION = "garage";
BUZZ_S3_ENDPOINT = "http://minio:9000";
BUZZ_S3_REGION = "us-east-1";
BUZZ_S3_ADDRESSING_STYLE = "path";
BUZZ_S3_BUCKET = buzz.bucket;
BUZZ_GIT_REPO_PATH = "/data/git";
@@ -289,7 +294,7 @@ in
};
postgres = {
image = "postgres:17-alpine";
image = buzz.images.posgres;
networks = [ "internal" ];
environmentFiles = [ config.age.secrets.buzz-env.path ];
environment = {
@@ -307,7 +312,7 @@ in
};
redis = {
image = "redis:7-alpine";
image = buzz.images.redis;
networks = [ "internal" ];
environmentFiles = [ config.age.secrets.buzz-env.path ];
volumes = [ "buzz-redis:/data" ];
@@ -319,36 +324,30 @@ in
command = [ "sh" "/usr/local/bin/redis-entrypoint.sh" ];
};
garage = {
image = "dxflrs/garage:v2.4.1";
minio = {
image = buzz.images.minio;
networks = [ "internal" ];
environmentFiles = [ config.age.secrets.buzz-env.path ];
environment.GARAGE_DEFAULT_BUCKET = buzz.bucket;
volumes = [ "buzz-garage:/var/lib/garage" ];
command = [ "/garage" "server" "--single-node" "--default-bucket" ];
files."/etc/garage.toml" = ''
metadata_dir = "/var/lib/garage/meta"
data_dir = "/var/lib/garage/data"
db_engine = "sqlite"
replication_factor = 1
rpc_bind_addr = "[::]:3901"
rpc_public_addr = "127.0.0.1:3901"
[s3_api]
s3_region = "garage"
api_bind_addr = "[::]:3900"
root_domain = ".s3.garage.localhost"
'';
volumes = [ "s3:/data" ];
command = [ "server" "/data" "--console-address" ":9001" ];
healthcheck = {
test = [ "CMD" "/garage" "status" ];
test = [ "CMD" "curl" "-f" "http://127.0.0.1:9000/minio/health/live" ];
interval = "30s";
timeout = "10s";
retries = 5;
start_period = "20s";
};
};
minio-init = {
image = buzz.images.mc;
networks = [ "internal" ];
environmentFiles = [ config.age.secrets.buzz-env.path ];
command = [ "mb" "--ignore-existing" "local/${buzz.bucket}" ];
dependsOn = [ "minio" ];
restart = "on-failure";
};
};
};
+2
View File
@@ -82,6 +82,8 @@ in
PORT = "80";
};
networks = staticIp "10.0.101.2";
# -> drawdb.app.internal (skyg.dns.domain), pushed by `skyg openwrt`
dns.names = [ "drawdb" ];
};
networks = macvlanNetwork;
};
+74
View File
@@ -0,0 +1,74 @@
# 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);
};
}
@@ -23,6 +23,28 @@ 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 != { })
@@ -53,7 +75,28 @@ in
message =
"skyg.nixos.common.container-services.${name}: set either composeFile OR services, not both.";
})
enabledGroups;
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);
# Create tmpfiles rules for state dirs and file dirs
systemd.tmpfiles.rules =
@@ -166,6 +166,51 @@
'';
};
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 = [ ];
@@ -215,6 +215,45 @@ 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.**
```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
};
```
| 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" ]; };
```
Verify and deploy:
```sh
nix eval .#dnsRecords --json | jq # every record, all hosts
skyg openwrt --dry-run # render dnsmasq.conf locally
skyg openwrt # diff + confirm + apply
```
---
## Limitations
- **One unit per group.** No per-container systemd units. Use `docker compose logs` for
+1
View File
@@ -3,6 +3,7 @@
imports = [
./hardware
./containers
./dns-records
./core.nix
./networking.nix
./user.nix
@@ -0,0 +1,65 @@
# 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.
@@ -0,0 +1,132 @@
{ 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";
};
};
}
+7
View File
@@ -24,6 +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`
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`.
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
@@ -55,6 +61,7 @@ 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/ethers
# → .tmp/openwrt-glmain/firewall.batch # the exact `uci -m import firewall` input
```
+13
View File
@@ -17,6 +17,15 @@ 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.
# Empty fragment when the caller doesn't supply one.
dnsRecords =
if config ? dnsRecords && config.dnsRecords != null
then config.dnsRecords
else builtins.toFile "skyg-dns-records-empty.json" (builtins.toJSON { generalMappings = [ ]; });
# Config JSON is read from stdin at deploy time — caller decrypts the age secret.
# Usage: age -d secrets/glmain.json.age | openwrt-deploy
#
@@ -24,10 +33,12 @@ let
# Nix-computed values it needs (router address, generator/apply-script store
# paths) and inlines the file's content after them.
deployScript = pkgs.writeShellScriptBin "openwrt-deploy" ''
export PATH="${lib.makeBinPath [ pkgs.jq ]}:$PATH"
export ROUTER="${config.router.ip}"
export ROUTER_USER="${config.router.user}"
export GENERATOR="${generator}"
export APPLY_SCRIPT="${applyScript}"
export NIX_DNS_RECORDS="${dnsRecords}"
${builtins.readFile ./openwrt-deploy.sh}
'';
@@ -35,7 +46,9 @@ let
# for review. No SSH, no uci, no router changes. Run from the repo root.
# The router name is passed as $1 (defaults to glmain) — see ./openwrt-dry-run.sh.
dryRunScript = pkgs.writeShellScriptBin "openwrt-dry-run" ''
export PATH="${lib.makeBinPath [ pkgs.jq ]}:$PATH"
export GENERATOR="${generator}"
export NIX_DNS_RECORDS="${dnsRecords}"
${builtins.readFile ./openwrt-dry-run.sh}
'';
in
+8 -1
View File
@@ -32,7 +32,14 @@ openwrt-gen firewall < config.json # prints UCI firewall rules (uci batch form
## Input shape (`config.rs`)
- `generalMappings`: `[{ ip, domains[] }]` — shared domain→IP records.
- `generalMappings`: `[{ ip, domains[], wildcard? }]` — shared domain→IP records.
`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.
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`.
- `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.
+19
View File
@@ -17,6 +17,16 @@ pub struct Config {
pub struct GeneralMapping {
pub ip: String,
pub domains: Vec<String>,
/// When true (the default, kept for backwards compatibility with existing
/// router secrets), emit a wildcard `address=/domain/ip` that also matches
/// every subdomain. When false, emit a plain `host-record=domain,ip`,
/// which is a normal A record and also provides reverse PTR lookups.
#[serde(default = "default_true")]
pub wildcard: bool,
}
fn default_true() -> bool {
true
}
#[derive(Deserialize)]
@@ -77,6 +87,15 @@ mod tests {
let config: Config = serde_json::from_str(json).unwrap();
assert_eq!(config.general_mappings[0].ip, "192.168.1.1");
assert_eq!(config.general_mappings[0].domains, vec!["test.local"]);
// Existing secrets omit the flag; wildcard behaviour must be preserved.
assert!(config.general_mappings[0].wildcard);
}
#[test]
fn test_general_mapping_wildcard_false() {
let json = r#"{"generalMappings": [{"ip": "10.0.101.2", "domains": ["drawdb.app.internal"], "wildcard": false}], "networks": {}}"#;
let config: Config = serde_json::from_str(json).unwrap();
assert!(!config.general_mappings[0].wildcard);
}
#[test]
@@ -37,8 +37,13 @@ pub fn generate(config: &Config) -> String {
for gm in &config.general_mappings {
for domain in &gm.domains {
out.push_str(&format!("address=/{}/{}\n", domain, gm.ip));
out.push_str(&format!("address=/.{}/{}\n", domain, gm.ip));
if gm.wildcard {
out.push_str(&format!("address=/{}/{}\n", domain, gm.ip));
out.push_str(&format!("address=/.{}/{}\n", domain, gm.ip));
} else {
// Plain A record (+ reverse PTR), no subdomain wildcard.
out.push_str(&format!("host-record={},{}\n", domain, gm.ip));
}
}
}
@@ -78,6 +83,7 @@ mod tests {
general_mappings: vec![GeneralMapping {
ip: "192.168.1.1".to_string(),
domains: vec!["gw.local".to_string()],
wildcard: true,
}],
networks: BTreeMap::new(),
dns_resolvers: vec![],
@@ -85,6 +91,24 @@ mod tests {
};
let result = generate(&config);
assert!(result.contains("address=/gw.local/192.168.1.1\n"));
assert!(result.contains("address=/.gw.local/192.168.1.1\n"));
}
#[test]
fn test_general_mappings_host_record() {
let config = Config {
general_mappings: vec![GeneralMapping {
ip: "10.0.101.2".to_string(),
domains: vec!["drawdb.app.internal".to_string()],
wildcard: false,
}],
networks: BTreeMap::new(),
dns_resolvers: vec![],
internet_only: vec![],
};
let result = generate(&config);
assert!(result.contains("host-record=drawdb.app.internal,10.0.101.2\n"));
assert!(!result.contains("address=/"));
}
#[test]
+9 -1
View File
@@ -7,11 +7,19 @@
# ROUTER_USER - SSH user
# GENERATOR - store path of the openwrt-gen package (bin/openwrt-gen inside)
# APPLY_SCRIPT - store path of skyg-apply.sh
# NIX_DNS_RECORDS - store path of the Nix-generated generalMappings fragment
set -euo pipefail
SERVER="$ROUTER_USER@$ROUTER"
CONFIG=$(cat)
# 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
# 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."
DNSMASQ=$(echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen dnsmasq)
ETHERS=$(echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen ethers)
+9 -3
View File
@@ -3,14 +3,19 @@
# - no SSH, no uci, no router changes. Run from the repo root. Router name is
# passed as $1 (defaults to glmain).
#
# Expects GENERATOR to be exported by the Nix wrapper before this file's
# content runs (store path of the openwrt-gen package, bin/openwrt-gen inside).
# Expects GENERATOR and NIX_DNS_RECORDS to be exported by the Nix wrapper before
# this file's content runs (store paths of the openwrt-gen package and of the
# Nix-generated generalMappings fragment).
set -euo pipefail
if [ $# -ge 1 ]; then ROUTER="$1"; else ROUTER=glmain; fi
OUTDIR=".tmp/openwrt-$ROUTER"
mkdir -p "$OUTDIR"
CONFIG=$(cat)
# Same merge as the real deploy: secret config + Nix-declared skyg.dns records.
CONFIG=$(cat | jq --slurpfile nix "$NIX_DNS_RECORDS" \
'.generalMappings = ((.generalMappings // []) + $nix[0].generalMappings)')
cp "$NIX_DNS_RECORDS" "$OUTDIR/dns-records.json"
echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen dnsmasq > "$OUTDIR/dnsmasq.conf"
echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen ethers > "$OUTDIR/ethers"
@@ -20,3 +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"
Binary file not shown.