Internals
Deploying noxlang.com and the registry
This page documents how the project's own web presence is run: the noxlang.com site and the noxpkg package registry. Both are Nox programs, they run as containers on one machine, and one Cloudflare Tunnel exposes them. Nothing here is needed to use Nox; it is for maintainers.
Topology#
| Hostname | Service | What it is |
|---|---|---|
noxlang.com |
noxlang-site |
A Nyx application (services/noxlang-site/) that serves the generated site |
www.noxlang.com |
noxlang-site |
Redirects (301) to noxlang.com |
nyx.noxlang.com |
frameworks-site |
The Nyx guide. Same process as the two rows below; the Host header picks the tree |
aether.noxlang.com |
frameworks-site |
The Aether guide |
aura.noxlang.com |
frameworks-site |
The Aura guide |
noxpkg.noxlang.com |
noxpkg |
The package index and admin panel (services/noxpkg/) |
noxpkg.2mtechnology.org |
noxpkg |
The registry's previous name, kept so older noxc releases keep working |
The stack is described by one Compose file, deploy/web/docker-compose.yml, with five services: noxlang-site, frameworks-site, noxpkg, noxpkg-backup and cloudflared. Containers publish only to 127.0.0.1; the tunnel is the only way in, and
the host has no open ports 80 or 443. It is the same tunnel as before (10d2b429-9912-44a6-8615-11ef5910ba74); the framework hostnames are extra ingress rules, not a second tunnel.
Framework sites#
services/frameworks-site/ is one Nyx application. scripts/build_framework_sites.py writes three static trees, public/nyx, public/aether and public/aura, from services/frameworks-site/content/. They reuse the noxlang.com stylesheet and script. html[data-site] swaps the brand color. Every page’s top bar links to https://noxlang.com, and the Nox site’s Frameworks menu links back.
The process reads Host (nyx.noxlang.com, aether.noxlang.com, aura.noxlang.com) and serves that tree. SITE_NAME=nyx|aether|aura is the override for a request that arrives without one of those names (a local curl to 127.0.0.1:8082). Content is loaded on the first request, once per worker, from each tree’s manifest.tsv.
python3 scripts/build_framework_sites.pyDNS for the three names is a proxied CNAME to the existing tunnel, created in the Cloudflare dashboard before the new ingress will answer:
nyx CNAME <tunnel-id>.cfargotunnel.com
aether CNAME <tunnel-id>.cfargotunnel.com
aura CNAME <tunnel-id>.cfargotunnel.comHow the site is built#
The documentation is plain Markdown in docs/, ordered by docs/_toc.yml. scripts/build_site.py turns it into a static tree:
python3 scripts/build_site.py # writes services/noxlang-site/public/
python3 scripts/build_site.py --verify # also compiles and runs the landing-page examples with noxc
python3 scripts/check_docs.py # checks every link, page, and ```nox block in docs/The builder highlights code with a Nox lexer, rewrites links between pages, writes a client-side search index, and emits manifest.tsv, the list of files the server will serve. The Nyx app reads that manifest at start-up and keeps every
file in memory (about 7 MB), so a request is a dictionary lookup. Nyx supplies the configuration, router, security headers, content-security policy, request ids, rate limiting and /healthz.
Two properties of Nox's module-level state shape the app. Each scheduler worker has its own copy of module variables, so the content is loaded by initialiser expressions (not by assignments in the entry file), and the Nyx application is opened lazily, once per worker, on the first request (Concurrency).
Configuration#
Copy deploy/web/.env.example to deploy/web/.env and fill it in. Docker Compose treats $ in values as a variable reference, so every $ in the Argon2 hash must be written $$.
| Variable | Meaning |
|---|---|
NYX_SECRET_KEY |
secret for the site's Nyx app, at least 32 characters |
NOXPKG_ADMIN_PASSWORD_HASH |
Argon2id hash of the registry admin password (noxc run services/noxpkg/scripts/gen_admin_hash.nox -- '<password>') |
NOXPKG_SESSION_SECRET |
secret for the registry's session cookie |
NOXPKG_GITHUB_CLIENT_ID |
client id of the GitHub OAuth App behind noxc login. Create it under GitHub > Settings > Developer settings > OAuth Apps, tick Enable Device Flow; the callback URL is unused (any value works) and no client secret is needed. Leave empty to disable login (and so publishing) |
NOXPKG_ADMIN_GITHUB |
the administrator's GitHub login; packages listed before accounts existed are assigned to it the first time it signs in |
NOXPKG_DATA_DIR |
directory with the registry database noxpkg.db (default services/noxpkg/data) |
BACKUP_DIR |
where local snapshots are kept (default services/noxpkg/backups) |
RESTIC_REPOSITORY, RESTIC_PASSWORD, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY |
optional off-site backup to an S3-compatible bucket such as Cloudflare R2 |
DNS and the tunnel#
deploy/web/cloudflared.yml routes the four hostnames above through the existing tunnel. In the Cloudflare dashboard, create these proxied (orange-cloud) CNAME records pointing at <tunnel-id>.cfargotunnel.com:
noxlang.com CNAME <tunnel-id>.cfargotunnel.com (apex; Cloudflare flattens it)
www CNAME <tunnel-id>.cfargotunnel.com
noxpkg CNAME <tunnel-id>.cfargotunnel.com
nyx CNAME <tunnel-id>.cfargotunnel.com
aether CNAME <tunnel-id>.cfargotunnel.com
aura CNAME <tunnel-id>.cfargotunnel.comDeploying#
From the repository root on the host:
docker compose -f deploy/web/docker-compose.yml --env-file deploy/web/.env up -d --build
docker compose -f deploy/web/docker-compose.yml psThe first build compiles Zig, QBE and noxc inside the image and takes several minutes; later builds reuse the cache. Check https://noxlang.com/healthz and https://noxpkg.noxlang.com/index.json afterwards. To roll back, check out the previous
commit and run the same command again.
Automatic site updates#
The documentation, the download page and the Playground's compiler are baked into the noxlang-site image, so they only change when a new image is deployed. This is automated with a pull-based flow that needs no inbound access to the machine and no secrets:
- Publish. On every stable release (
vX.Y.Z, not-rc), thesite-imagejob ofrelease.ymlbuilds the site image on an arm64 runner and starts it with the production settings.scripts/site_image_smoke.shthen checks the contract —/healthz, the strict content-security policy on ordinary pages, the relaxed one only on/playground, the Playground files and the WebAssembly front end,/api/release, and/version.txtequal to the tagged version. Only if every check passes is the image pushed toghcr.io/mburakmmm/noxlang-siteasX.Y.Zandlatest. The job runs after the release archives have been built, which itself waits for a green CI. - Update. On the production machine,
deploy/web/update-site.shpullslatest; if it differs from what is running it restarts only thenoxlang-siteservice with it and waits (up to two minutes) for the container to become healthy and for/version.txtto report the new version. If that fails it puts the previous image back (kept as:previous), and remembers the bad image so it is not retried every cycle. Overlapping runs are prevented with a lock, a failed pull leaves the site untouched, and--checkonly reports whether an update is waiting.
deploy/web/install-update-timer.sh install # launchd runs update-site.sh every 15 minutes
deploy/web/install-update-timer.sh uninstall
tail -f ~/Library/Logs/nox-site-update.logmacOS keeps launchd agents out of ~/Documents, ~/Desktop and ~/Downloads, so install copies what the updater needs (update-site.sh, prune-docker.sh, docker-compose.yml and .env, the latter mode 0600) to ~/.nox-site-update/deploy/ and points the agent there; run install again after you change the compose file or .env.
One-time setup: after the first release has pushed the image, open the package on GitHub (your profile > Packages > noxlang-site > Package settings) and set its visibility to Public, so the machine can pull it without credentials. The compose file keeps build: as well, so up -d --build still builds locally if you prefer.
Disk and cache housekeeping. Every build or pull leaves old image versions, untagged layers and build cache behind, and the machine hosts other projects too. deploy/web/prune-docker.sh keeps that bounded: it removes the noxlang-site version tags other than latest and previous (the rollback point), untagged images from our releases (and any untagged image older than 24 hours), and build cache older than 48 hours. It never touches an image a running container uses, nor volumes or networks, and it never fails the update. update-site.sh runs it right after every update or rollback and at most once a day otherwise. After a manual docker compose ... up -d --build, run deploy/web/prune-docker.sh yourself. Tune it with DANGLING_MAX_AGE and BUILD_CACHE_MAX_AGE.
The download page does not depend on any of this: it reads the latest GitHub release at request time (/api/release, cached for ten minutes), so new archives appear there without a redeploy. deploy/web/test_update_site.sh exercises the update script against a fake docker and runs in CI.
Backups#
The registry's state is noxpkg.db. Accounts, comments and bug reports live only there. The package catalog and the publish inbox are mirrored to index.json and inbox.json after every write (a temporary file, then a rename). Those JSON files are never deleted: the first boot imports them once, and later writes refresh them from the database. GET /index.json is rendered from the database in the shape noxc search and noxc add already read. ratelimit.txt is still a small text file.
scripts/backup_noxpkg.sh runs in the noxpkg-backup container:
- Every hour it copies
noxpkg.dbwith SQLite's online.backup, then writesindex.jsonandinbox.jsonfrom that copy so the archive cannot contain a stale catalog. It checks integrity and that the JSON names match the database, then writesnoxpkg-<UTC timestamp>.tar.gzwith a.sha256next to it. A bad copy is refused; the previous snapshot stays. The off-site restic copy is that archive, not a live read of the data directory. Before the database exists, the script still archives the JSON files on disk. - Rotation keeps the newest 48 snapshots, the newest one per day for 30 days, and the newest one per week for 12 weeks (
KEEP_HOURLY,KEEP_DAILY,KEEP_WEEKLY). - Off-site (optional): when the four
RESTIC_*/AWS_*variables are set, each run also pushes the data to a restic repository. restic encrypts and de-duplicates it, so the bucket holds only ciphertext.
Restoring never overwrites: the target directory must be empty or absent, and the archive's checksum is verified first.
# list what exists
ls services/noxpkg/backups
# restore the newest snapshot into a fresh directory, then inspect it
sh scripts/backup_noxpkg.sh restore latest /tmp/noxpkg-restored
# prove the newest snapshot can be restored (the container's health check also watches freshness)
docker compose -f deploy/web/docker-compose.yml exec noxpkg-backup /usr/local/bin/backup_noxpkg.sh verifyTo recover production, stop noxpkg, restore into an empty directory, replace the data directory with it, and start noxpkg again. For an off-site restore, use restic restore latest --target <dir> with the same environment variables.
scripts/test_backup.sh tests the script (snapshot, rejection of corrupt data, rotation, restore, checksum failure) and runs on both busybox and GNU/BSD shells.
Security notes#
- The site container runs as an unprivileged user with a read-only root file system; it needs no writable storage.
- The content-security policy allows only same-origin resources; the site loads no third-party scripts, fonts or analytics.
- The registry approves metadata, not code. See Security model.