Antenna Tower on Linux, with a web Manager
Superseded 2026-11-03. The Swift server (
StationServer,RelayServer,antenna-tower-server,control-room, the Manager's launchd helper and MCP assistant) was replaced by the Go tower intower/(ADR 0005). What follows is history.
Planned 2026-10-19; nothing built yet. The decisions are in ADR 0003.
Goal: the station's server (Antenna Tower, ADR 0002) runs on a Linux box in the homelab as well as on the Mac mini, and the station can be managed there from a browser. The Apple TVs, phones and Mac Managers don't change. They already get everything from the server and R2 (ADR 0001), not iCloud.
Where it stands #
-
Builds for Linux in principle:
RetroLineup(Foundation-only; guardsFoundationNetworkingandSQLite3),RelayKit,RelayAdmin,RelayServer(Hummingbird) andretro-relay. None of it has been built on Linux yet. -
Known breakages:
Xtream.swiftimportsosunguarded;PlaybackDiagnosticsIO.swiftimportsNetwork;RemoteControlusesNetwork(it stays Apple-only: it's the phone and TV's remote).
-
The server is app code.
TowerMain(Sources/AntennaTower) builds fromSources/Sharedand the Manager's files withRELAY. The pieces it starts, and what holds each to the Mac:Piece Mac-only bits RemoteServernone beyond CryptoKit(useswift-crypto)StationMirror/StationKeysthe Keychain RelayHostNetwork,NetService(Bonjour)EventRefresherAppKit,SMAppService(the login item)VODLibrary,OnDemandCatalog,OnDemandTagger,EventScannone seen; they live in app folders VOD fetch ( ReadAheadSession)NWListener; the VPN route (NetworkRoute)the assistant (MCP) NWListener; drivesStationModel
Stages #
Each stage ships on its own, and the Mac mini keeps serving until stage 4.
1. The packages build on Linux #
Done 2026-10-29, without the Forgejo job yet: see packages.md, step 4.
just linux-check:swift buildandswift testforRetroLineupandRetroRelayin the officialswift:6.xcontainer, plus a Forgejo Actions job to match.- Guard
import os(a smallLogshim) and movePlaybackDiagnosticsIO'sNetworkuse behind#if canImport(Network). - Leave out
RemoteControlon Linux (.when(platforms:)). - Done when both packages' tests pass on Linux.
2. The server moves into a package #
Under way as a reorganization of the whole station into packages by layer:
packages.md. StationCore and StationServer are built,
and build on Linux (stage 1 done the same way: just linux-check).
- New target
StationServerinPackages/Station. Move the pieces above one at a time, smallest first:RemoteServerandStationMirror, then the On Demand catalog and tagger, the event jobs, and VOD fetch. - Platform services behind protocols (ADR 0003 decision 3):
SecretStore(Keychain or file),Advertiser(NetServiceoravahi-publish),Log.UserDefaultsworks on Linux, soswift-corelibs-foundationbacks it with a plist; keep it. NWListenerservers (VOD fetch's local server, the assistant) move onto Hummingbird, like the relay.EventRefresherlosesAppKit: the login item stays in the Manager.TowerMainon the Mac linksStationServerand behaves exactly as now.- Done when the Mac's Antenna Tower runs from the package and
StationServer's tests pass on Linux.
3. antenna-tower for Linux #
Built 2026-10-29, not deployed yet:
antenna-tower-server, an executable inPackages/Station. It startsTower.serve()(StationServer), the same serving the Mac's helper starts once the Manager hands it the station, on a plain dispatch main loop.- Configured by environment:
STATION_DATA: one folder for everything. It's where Foundation's XDG folders go:config(settings),data(station.sqlite, the On Demand catalog, posters, downloads),cacheandsecrets(0600files).STATION_SECRETS: the secrets alone, if they belong elsewhere.STATION_RELAY_NAME: the name screens know the server by. They follow a moved server by it, so the station moved from the Mac mini keeps "Samuel’s Mac mini" (default: the host's name).- The port is the relay's, 8766.
just tower-imagebuildsantenna-tower:devfromPackages/antenna-tower.Dockerfile(Swift built with a static stdlib, on Ubuntu noble; about 420 MB). Tried in Docker: it starts, keeps everything in/data, and answers/v1/hello(401 without the household token).- Still to do:
- CI to build the image, and the deploy through the homelab GitOps repo
(the
deploy-app-to-homelabskill). It needsnetwork_mode: host, for mDNS and port 8766, and a volume for/data. - Advertising:
avahi-publishis in the image, but it needs an Avahi daemon. Mount the host's (/var/run/dbusand/var/run/avahi-daemon/socket); without it the relay serves but isn't found by Bonjour, only by the address in the settings. - Run it beside the Mac mini under a test station (separate R2 prefix, its own keys) until the screens, invites and the mirror check out.
- CI to build the image, and the deploy through the homelab GitOps repo
(the
4. The move #
- Export from the Mac mini:
station.sqlite,StationKeysand the data folder, through a one-timeantenna-tower import <bundle>(the same idea as ADR 0002's handover, across machines). - The Mac mini publishes the new server address in the settings before it stops. Devices pick it up from the server or from R2, so nobody re-joins.
- The Mac mini's Manager then joins the Linux server as a client, and its relay toggle stays off.
- Before this, decide where On Demand downloads live and what happens to the VPN route (see Open).
5. The web Manager #
- The browser joins with a pairing code and gets a device key with a manager
profile, kept in an
HttpOnlycookie. Pages call the same/v1/adminhandlers in the same process. - Server-rendered pages (Hummingbird and Mustache) with htmx. Panes, in the
order they're used:
- channels and numbers (on dial, rename, renumber, remove or restore);
- IPTV logins and feeds (order, preferred login), with a "did it answer" test and no picture;
- groups;
- sports: folders, overrides, aliases, the Jev review queue;
- On Demand: catalogs, downloads, the Video Store;
- devices and invites (QR code drawn as SVG, not CoreImage), profiles;
- status, errors, storage, the relay.
- No stream preview (ADR 0003 decision 6). MBTA and World settings come in through their modules' get/set fields, as plain forms.
6. The control room on Linux #
Agreed 2026-10-30, replacing "the assistant moves into Antenna Tower". The Manager's jobs and its assistant leave the Mac too, but not into the tower: into a second headless service beside it, the control room. The tower is the broadcast and rarely changes; the control room holds the logic that changes often and can be redeployed without restarting what the screens use.
Why it's needed at all: the jobs (event schedules, sports, Jev's review,
channel linking, guide files) only run in a control-room Manager, the one on
the Mac with the tower or the server's own (EventRefresher.isControlRoom).
Once the tower is on Linux and the Mac Manager is only a client, nothing would
refresh the sport channels' games.
- It's a headless Manager client. It pairs with the tower once (a pairing
code, given by environment on first start), gets a device key with a
manager profile, and its settings changes reach the tower through
RemoteLink, as any Manager's do. The jobs already work that way: they save into the settings (EventGames, the status lines) and don't touch the server's files. - It's the control room by what it is, not where it is:
AppKind .controlRoom. A Mac Manager runs the jobs only where it serves the station itself, as now. - Steps:
StationJobsinPackages/Station:EventRefresher(its login item stays in the Manager),EventScan,SportReview,IPTVLinker,GuideFiles. The Manager links it, as it linksStationServer.control-room, an executable and image likeantenna-tower-server: pair, then run the jobs.- The assistant: rewrite the MCP tools against the settings and the jobs
instead of
StationModel, on Hummingbird's HTTP, in the control room. Same tool names and arguments, sodocs/mcp.mdand clients barely change. Then the Manager'sAssistantServergoes.
- The Mac Manager stays the UI, paired as a client. The web Manager (stage 5) is for managing from a phone or a browser, later.
Remote access #
Agreed 2026-10-19 (ADR 0003 decision 9). It applies wherever the server runs, the Mac mini included.
- First, the loopback fix.
RemoteServertrusts loopback (pair-code,playing-now), andcloudflared(liketailscale serve) connects from localhost. So anything from a tunnel would count as "this Mac" and could get a pairing code. The tower opens a second port for proxied traffic. It serves only the device API and the web Manager, never a loopback-only route, andcloudflaredpoints only there. - Cloudflare Tunnel + Access in front of that port, on its own hostname.
- The policy allows your emails and your family's, by Google login or a one-time code by email.
- The ingress rules end in
http_status:404. - No video goes through the tunnel: On Demand fetch stays on the home network.
- Apps log in through Access:
- The app opens
/v1/app-login(a route behind Access) inASWebAuthenticationSession. - The person logs in, and the server reads the verified
Cf-Access-Jwt-Assertion. - The server redirects to
rabbitears://access?token=…. - The app keeps the token in its Keychain and sends it as the
cf-access-tokenheader, next to its device key. - When the Access session ends (set it to a month), the app opens the login again.
- This covers iOS and macOS. tvOS has no browser, so a TV away from home uses Tailscale, or a service token if it ever needs one.
- The app opens
- The server checks Access as well: the
Cf-Access-Jwt-Assertionsignature against the team's keys and the app's audience tag, on every request on the proxied port, then the device key. - The home network is unchanged: devices that reach the server directly skip Access, and R2 stays the path when the server can't be reached.
- Tailscale stays an option for your own devices, including a TV away from home. Tailscale Funnel is ruled out: it puts the server on the internet with no login in front of it.
Open #
- Which box: a homelab host (luigi?) or a container on the cluster. It needs host networking and room for On Demand downloads.
- On Demand downloads and Plex: today they go to the Mac mini's disk. On Linux, do they land on a NAS share that Plex reads?
- The VPN route (
NetworkRoute) the providers need: a route on the Linux host, or a container sharing a VPN sidecar's network. - Access login in the app: does Access accept a redirect to the custom scheme from our own route, and how long can a session last on the free plan?
Built, 2026-11-01 #
Not run against a real tower, a real provider or R2. just linux-check
passes on Linux (RetroLineup, RetroRelay, and Station with the socket and MCP
tests); the rest is type-checked on the Mac and, where noted, tested.
- Stage 6, the control room (
control-room,just control-room-image): pairs fromSTATION_SERVERandSTATION_PAIR_CODE, runsEventRefresher, and serves MCP (MCPServer) with the settings-only tools. Tested: the MCP server over a real socket (MCPServerTests). Not done: the lineup's tools (channels, groups, numbers, feeds,test_stream) are still the Mac assistant's, because they readStationModel. - Stage 3, read-ahead on Linux:
SocketListener(BSD sockets) in place ofNWListener, tested on the Mac over a real socket. The Apple path is as it was. - Stage 3, the proxy:
STATION_PROXYsends provider requests (Xtream's API and streams, read-ahead's downloads) through the VPN's HTTP proxy, and nothing else.deploy/docker-compose.ymlis the reference for luigi. - CI:
.forgejo/workflows/linux.ymlrunsjust linux-check, which now runs the Station tests too, and builds both images. - Stage 4, the move:
antenna-tower export <folder>(the tower helper in the Manager's bundle,Contents/Helpers/, since it holds the station on a Mac that's handed over) writes the bundle (handover.plist,station.sqlite, the On Demand catalog);antenna-tower-server import <folder> [--force]takes it in. Untested both ways: the export reads the tower's own defaults and keychain and wasn't run against the real station.
Running on luigi, 2026-11-02 #
The station moved from the Mac mini to luigi the same day. What it showed, and what it runs as now:
- Native, not Docker. The tower and the control room are systemd user services (
retrotv-tower,retrotv-control-room; linger on) built on luigi in a Swift dev container with a persistent build volume (build.sh, about 35 s when little has changed, against 5 to 6 minutes for an image). Only Gluetun is a container (the homelab repo'sluigi/retrotv/).deploy/docker-compose.ymlis the plan that came first and is no longer what runs.swift build --producthonours only the last flag: build with none. - The main actor. On Linux
dispatchMain()stopped serving it once startup was over, so an MCP request, the tower's admin routes and timers never came back. Both programs end inRunLoop.main.run()now. - Preferences don't last on Linux, and the station's database is the station. Three things follow:
- The tower loads the stored settings into the preferences at startup (
RemoteServer.loadStoredSettings). Without that, its first look found every setting gone and the ledger recorded each as deleted, which paired devices then pick up. importsaves its settings to the database (saveSettingsNow): they were only in memory and vanished on exit.- A Linux client (the control room) seeds its preferences from the server state it saved (
server-settings.plist) before comparing. Otherwise its empty preferences against that state looked like every setting deleted here, and it sent the deletions to the tower on each restart: this wiped luigi's station three times, and only while the control room ran. - The household token is kept in
$STATION_SECRETS/relay-token.json. It must be the one the screens hold, or every one of them gets a 401 from the relay. The export doesn't carry it.
- The tower loads the stored settings into the preferences at startup (
- Names and addresses. Screens follow a moved server by its Bonjour name:
STATION_RELAY_NAMEkeeps the old one ("Samuel's Mac mini"). The address the tower publishes is the default route's interface, not the first of Docker's bridges (LocalAddress.ipv4(); it was10.89.0.1).avahi-publishexits if Avahi isn't up yet, so it's started again within seconds. - Not carried by the export: the On Demand catalog (a cache: luigi fetches its own, which also fixed the macOS
httpprovider that App Transport Security had blocked since 19 October), the household token, and API keys the Mac's tower never had (TMDB, OpenSubtitles). A Manager has to pair with luigi again. - Don't
pkill -forpgrep -foversshwith a pattern that's in the command itself: it kills the session.
Phin Tech docs
Rabbit Ears Manager in the store →