asusmini: prepare Spaces beta and restore safe automatic updates

This commit is contained in:
Anish Lakhwara committed 2026-11-30 19:48:14 -08:00
1 parent a03340ca37
commit 55328cf620
7 files changed
+129 -33

No files matched your search

+39 -3
View File
@@ -7,14 +7,26 @@ Infrastructure-as-code for Commons Computing's ATProto services.
This flake manages the following services on `asusmini`:
- **PDS** (Personal Data Server) - `pds.commonscomputer.com:5556`
- **Tangled Knot** (Rust Git forge) - HTTP `5555`, Git SSH `2223`
- **Tangled Knot** (Rust Git forge) - HTTP `5555`, Git SSH `22`
- **Tangled Spindle** (CI runner) - `spindle.commonscomputer.com:6555`
All services are proxied through Caddy with automatic HTTPS.
The supervised Go-to-Rust cutover is documented in [TANGLED-MIGRATION.md](TANGLED-MIGRATION.md).
Do not activate the new configuration before following its backup and migration steps.
Administrative SSH stays on port 22; Git SSH on 2223 needs explicit client routing.
### Administrative SSH
Enable Tailscale, then connect to `asusmini` on port **2224**:
```bash
ssh -p 2224 [email protected]
```
This is the confirmed working admin access path. The LAN address is
`192.168.1.249` (also port 2224). Public access to
`pds.commonscomputer.com:2224` timed out; do not assume it is forwarded.
Port 22 on the public hostname serves Tangled Knot's Git SSH, not an admin shell.
## Setup
@@ -93,7 +105,31 @@ A systemd timer runs weekly to:
1. Pull latest git changes
2. Run `nix flake update`
3. Build, activate, and health-check the new configuration
4. Commit and push flake.lock only after successful validation
4. Check Knot, Spindle, SSH, and both local/public PDS health
5. Commit and push flake.lock only after successful validation
Keep the server checkout's Nix files committed; uncommitted changes deliberately
block updates. Git SSH to `git.commonscomputer.com:2222` uses the verified origin
`205.250.24.44` through a host-specific SSH configuration because Cloudflare does
not proxy that port. The existing deploy key remains in use.
### Spaces Public Beta
The temporary PDS overlay selects published tag `v0.4.600` (runtime version
`0.4.6000`, `@atproto/pds` 0.6.0) while nixpkgs still packages `0.4.5051`.
When nixpkgs changes its PDS version, its package takes over automatically.
The pinned nixpkgs already builds with a supported Node 22 runtime.
`PDS_SPACES_MIGRATION_JITTER_WINDOW_MS=0` matches the official production image,
avoiding the library's default initial delay of up to 24 hours. Migration and
PLC KEM-key publication happen automatically. Back up PDS state and its secrets
before activation; switching Nix generations does not undo database or PLC
changes. Do not deploy the Spaces alpha.
After activation, verify `/xrpc/_health` reports `0.4.6000` and inspect its
`spacesMigration` counters. Check that hosted active PLC accounts gain an
`#atproto_kem` verification method. These are migration checks, not a substitute
for an authenticated Spaces application test.
**Setup required:**
```bash
+7 -2
View File
@@ -22,6 +22,8 @@
# Set explicitly so the limit is visible in our config rather than
# depending on whatever default the pinned nixpkgs module ships with.
PDS_BLOB_UPLOAD_LIMIT = "104857600";
# Match the production image: publish Spaces keys without a random 24h delay.
PDS_SPACES_MIGRATION_JITTER_WINDOW_MS = "0";
# We can set a bunch of other things too
# PDS_BSKY_APP_VIEW_URL
# PDS_CRAWLERS
@@ -65,9 +67,9 @@
server = {
hostname = "knot.commonscomputer.com";
admins = [ "did:plc:om5yygegi4yxcbay5gemn2wm" ];
# Caddy is on another machine; administrative sshd keeps port 22.
# Caddy is on another machine; administrative sshd uses port 2224.
listen_addr = "0.0.0.0:5555";
ssh_listen_addr = "0.0.0.0:2223";
ssh_listen_addr = "0.0.0.0:22";
};
git.object_format = "sha1";
atproto.plc_directory = "https://plc.directory";
@@ -88,6 +90,9 @@
"/var/lib/knot/ssh_host_key"
"/var/lib/knot/sealed-keys"
];
# Binding port 22 needs a capability in the host user namespace.
systemd.services.knot-rs.serviceConfig.AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
systemd.services.knot-rs.serviceConfig.PrivateUsers = false;
systemd.services.knot-rs.serviceConfig.ExecStartPre = [
"${pkgs.coreutils}/bin/test -s /var/lib/knot/ssh_host_key"
"${pkgs.coreutils}/bin/test -s /var/lib/knot/sealed-keys"
+4 -1
View File
@@ -51,7 +51,7 @@
# blindly roll back their data format or discard accepted writes.
rm -f /var/lib/knot/.upgrade-verified
${pkgs.systemd}/bin/systemctl stop auto-update.timer
${pkgs.systemd}/bin/systemctl stop knot-rs.service spindle.service
${pkgs.systemd}/bin/systemctl stop knot-rs.service spindle.service bluesky-pds.service
echo "Activation/health failed: application services and updates stopped; inspect state and retained flake.lock" >&2
elif [ "$status" -ne 0 ] && [ "$validated" -eq 1 ]; then
echo "System is healthy, but Git publication failed; retain/reconcile the local lockfile or commit before retrying" >&2
@@ -93,9 +93,12 @@
${pkgs.systemd}/bin/systemctl is-active --quiet knot-rs
${pkgs.systemd}/bin/systemctl is-active --quiet spindle
${pkgs.systemd}/bin/systemctl is-active --quiet sshd
${pkgs.systemd}/bin/systemctl is-active --quiet bluesky-pds
${pkgs.curl}/bin/curl --fail --silent --show-error --max-time 10 --retry 5 --retry-connrefused --retry-delay 1 http://127.0.0.1:5555/xrpc/_health | jq -e '.version | length > 0'
${pkgs.curl}/bin/curl --fail --silent --show-error --max-time 10 --retry 5 --retry-connrefused --retry-delay 1 http://127.0.0.1:6555/_health | jq -e '.status == "ok"'
${pkgs.curl}/bin/curl --fail --silent --show-error --max-time 15 https://knot.commonscomputer.com/xrpc/org.tangled.knot.describeKnot | jq -e '.did == "did:web:knot.commonscomputer.com" and .contact.email == "pds@email.commonscomputer.com"'
${pkgs.curl}/bin/curl --fail --silent --show-error --max-time 10 --retry 5 --retry-connrefused --retry-delay 1 http://127.0.0.1:5556/xrpc/_health | jq -e -s 'length == 1 and (.[0].version | type == "string" and length > 0)'
${pkgs.curl}/bin/curl --fail --silent --show-error --max-time 15 https://pds.commonscomputer.com/xrpc/_health | jq -e -s 'length == 1 and (.[0].version | type == "string" and length > 0)'
validated=1
snapshot_ready=0
+13
View File
@@ -95,6 +95,19 @@
# Enable the OpenSSH daemon.
services.openssh = {
enable = true;
ports = [ 2224 ];
};
# Cloudflare proxies the forge's HTTPS hostname, not its SSH port 2222.
# Route Git SSH to the verified origin while retaining the hostname's key.
programs.ssh.extraConfig = ''
Host git.commonscomputer.com
HostName 205.250.24.44
HostKeyAlias [git.commonscomputer.com]:2222
'';
programs.ssh.knownHosts.commons-forge = {
hostNames = [ "[git.commonscomputer.com]:2222" ];
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHzlORmrVR4Ffde0JgYr2R6tWWH6lS4yednGdP+hGjtl";
};
# Open ports in the firewall.
+29 -23
View File
@@ -1,25 +1,31 @@
final: prev: {
# PDS 0.4.5009 aborts in better-sqlite3 under Node 24. Node 22 satisfies
# PDS's Node 22+ requirement and keeps its native SQLite binding stable.
bluesky-pds = prev.bluesky-pds.overrideAttrs (old: {
nativeBuildInputs =
(builtins.filter (pkg: (pkg.pname or "") != "nodejs") old.nativeBuildInputs)
++ [ prev.nodejs_22 ];
buildPhase = ''
runHook preBuild
pushd ./node_modules/.pnpm/better-sqlite3@*/node_modules/better-sqlite3
npm run build-release --offline --nodedir="${prev.srcOnly prev.nodejs_22}"
find build -type f -exec remove-references-to -t "${prev.srcOnly prev.nodejs_22}" {} \;
popd
makeWrapper "${prev.nodejs_22}/bin/node" "$out/bin/pds" \
--add-flags --enable-source-maps \
--add-flags "$out/lib/pds/index.ts" \
--set-default NODE_ENV production
runHook postBuild
'';
});
# Temporary Spaces beta bridge until nixpkgs updates its pre-Spaces package.
# The published tag is v0.4.600; the service reports version 0.4.6000.
bluesky-pds =
if prev.bluesky-pds.version == "0.4.5051" then
prev.bluesky-pds.overrideAttrs (
finalAttrs: _: {
version = "0.4.6000";
src = prev.fetchFromGitHub {
owner = "bluesky-social";
repo = "pds";
rev = "f3ce8887cbcecf7cda942d482d1c536b7e725fe1";
hash = "sha256-scSKGKUJ3KyQTtQDZoeouwXb+2k3ez0ixv6V0lTnIE8=";
};
sourceRoot = "${finalAttrs.src.name}/service";
pnpmDeps = prev.fetchPnpmDeps {
inherit (finalAttrs)
pname
version
src
sourceRoot
;
pnpm = prev.pnpm_10;
fetcherVersion = 4;
hash = "sha256-rIy6sydaXbewdQcscn11EvsXQOemPJIKIVLLEIwiYc4=";
};
}
)
else
prev.bluesky-pds;
}
Regular → Executable
+1
View File
@@ -16,6 +16,7 @@ runtime_template=/run/knot-upgrade.XXXXXX
system_root=/var/lib/knot-upgrade-system
tools_root=/var/lib/knot-upgrade-tools
mkdir -p "$backup_dir"
if [ "$(id -u)" != 0 ] || [ "$(hostname)" != asusmininix ]; then
printf 'Run this script as root on asusmininix.\n' >&2
exit 1
+36 -4
View File
@@ -71,16 +71,17 @@ elif name == "nix-env":
if fail("ENV_SET_FAIL"):
raise SystemExit(1)
elif name == "systemctl":
if args[:2] == ["is-active", "--quiet"] and fail("HEALTH_FAIL"):
if args[:2] == ["is-active", "--quiet"] and (fail("HEALTH_FAIL") or args[-1] == os.environ.get("SERVICE_FAIL")):
raise SystemExit(1)
if args[:1] == ["stop"] and fail("STOP_FAIL"):
raise SystemExit(1)
elif name == "curl":
if fail("HEALTH_FAIL"):
if fail("HEALTH_FAIL") or args[-1] == os.environ.get("HTTP_FAIL"):
raise SystemExit(1)
print(args[-1])
elif name == "jq":
sys.stdin.read()
if fail("HEALTH_FAIL"):
endpoint = sys.stdin.read().strip()
if fail("HEALTH_FAIL") or endpoint == os.environ.get("JSON_FAIL"):
raise SystemExit(1)
else:
Path(os.environ["UNKNOWN_LOG"]).open("a").write(name + "\n")
@@ -171,6 +172,32 @@ class AutoUpdateTests(unittest.TestCase):
self.assertFalse(any(x.startswith("git commit") or x == "git push" for x in commands))
self.assert_no_unknown()
def test_pds_health_failures_pause_all_updated_stateful_services(self):
local = "http://127.0.0.1:5556/xrpc/_health"
public = "https://pds.commonscomputer.com/xrpc/_health"
cases = [
{"SERVICE_FAIL": "bluesky-pds"},
{"HTTP_FAIL": local},
{"HTTP_FAIL": public},
{"JSON_FAIL": local},
{"JSON_FAIL": public},
]
for flags in cases:
with self.subTest(flags=flags):
self.log.unlink(missing_ok=True)
(self.repo / "flake.lock").write_text("initial lock\n")
(self.state / ".upgrade-verified").touch()
result = self.run_update(**flags)
self.assertNotEqual(result.returncode, 0)
commands = self.commands()
self.assertIn("systemctl stop auto-update.timer", commands)
self.assertIn("systemctl stop knot-rs.service spindle.service bluesky-pds.service", commands)
self.assertFalse((self.state / ".upgrade-verified").exists())
self.assertEqual((self.repo / "flake.lock").read_text(), "updated lock\n")
self.assertEqual(sum(x.startswith("nix-env") for x in commands), 1)
self.assertFalse(any(x.startswith("git commit") or x == "git push" for x in commands))
self.assert_no_unknown()
def test_happy_path_commits_and_pushes_after_health(self):
result = self.run_update()
self.assertEqual(result.returncode, 0, result.stderr)
@@ -180,6 +207,11 @@ class AutoUpdateTests(unittest.TestCase):
push = next(i for i, x in enumerate(commands) if x == "git push")
self.assertLess(health, commit)
self.assertLess(commit, push)
for service in ("knot-rs", "spindle", "sshd", "bluesky-pds"):
self.assertIn(f"systemctl is-active --quiet {service}", commands)
endpoints = [x.split()[-1] for x in commands if x.startswith("curl ")]
self.assertIn("http://127.0.0.1:5556/xrpc/_health", endpoints)
self.assertIn("https://pds.commonscomputer.com/xrpc/_health", endpoints)
self.assert_no_unknown()
def test_publication_failure_retains_deployed_lock_without_rollback(self):