Commons Computing NixOS Configuration

Infrastructure-as-code for Commons Computing's ATProto services.

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 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. Do not activate the new configuration before following its backup and migration steps.

Administrative SSH

Enable Tailscale, then connect to asusmini on port 2224:

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

Prerequisites

nix develop

Or install direnv to automatically get the devshell going.

This provides agenix and dnscontrol.

Managing Secrets

Secrets are managed with agenix. If you're unfamiliar with agenix, here is a good introduction.

Adding a New User's Key

  1. Get their SSH public key (ed25519 or RSA)
  2. Add it to secrets/secrets.nix in the appropriate key list
  3. Re-encrypt all secrets:
    cd secrets
    agenix -e pds-env.age  # repeat for each secret
    

Creating/Editing Secrets

cd secrets
agenix -e pds-env.age

This opens your $EDITOR with the decrypted content. Save and close to re-encrypt.

Adding New Secrets

  1. Add the secret to secrets/secrets.nix:
    "new-secret.age".publicKeys = allKeys;
    
  2. Create it:
    cd secrets
    agenix -e new-secret.age
    
  3. Reference it in your NixOS config:
    age.secrets.new-secret = {
      file = ../../secrets/new-secret.age;
      mode = "0400";
      owner = "service-user";
    };
    

Deployment

Manual Deployment

From an administrative root shell on the server, with a clean checkout:

cd /etc/commonscomputing-nix
git pull --ff-only
nixos-rebuild build --flake .#asusmini
nixos-rebuild switch --flake .#asusmini

For the first Spaces upgrade, take the offline backup described below between build and switch. There is no separate activation script. Do not run nix flake update unless you intend to update the pinned dependencies too.

Auto-Update

The timer is gated until scripts/upgrade-knot.sh completes the Tangled migration and smoke tests. It then resumes weekly updates. Tangled is pinned to reviewed stable v1.20.1, not its development branch: later Tangled releases need an explicit tag bump. Other flake inputs continue updating weekly.

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. 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.

Setup required:

# On the server, generate SSH key for git push
ssh-keygen -t ed25519 -f /root/.ssh/commons-nix-deploy -N ""
cat /root/.ssh/commons-nix-deploy.pub
# Add the public key as a write-enabled deploy key on our forge:
# https://git.commonscomputer.com/aynish/commoncomputing-nix

# If this is the chosen deploy key, configure SSH to use it:
cat >> /root/.ssh/config <<EOF
Host git.commonscomputer.com
  IdentityFile /root/.ssh/commons-nix-deploy
EOF

# Verify the existing key before generating/replacing anything on a live host:
git -C /etc/commonscomputing-nix push --dry-run

Manual trigger:

sudo systemctl start auto-update

Check status:

sudo systemctl status auto-update
sudo journalctl -u auto-update

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.

One-time backup before the Spaces and Tangled stable upgrade

Use an administrative root shell in /etc/commonscomputing-nix. If needed, bootstrap Git/curl/jq with: nix shell --inputs-from . nixpkgs#git nixpkgs#curl nixpkgs#jq --command bash. The new configuration installs these tools normally. Tangled stays on stable v1.20.1; its unreleased development-branch security fixes are not included. Spindle keeps its existing CORS policy and unlimited cache quota rather than adopting the new wildcard-CORS and 5 GiB cache defaults.

Pause the timer and take its shared lock before updating the checkout:

systemctl stop auto-update.timer
exec 9>/run/lock/commonscomputing-update.lock
flock --nonblock 9

Stop if the lock is busy. The three existing server edits are duplicates of committed fixes; discard only those paths, then use the normal pull/build steps:

git restore -- hosts/asusmini/atproto.nix hosts/asusmini/default.nix scripts/upgrade-knot.sh
git pull --ff-only https://git.commonscomputer.com/aynish/commoncomputing-nix.git main
nixos-rebuild build --flake .#asusmini

Tangled v1.20.1 also adds automatic Spindle database migrations. After a successful build, stop the three application services and take one consistent backup. Spindle may wait for running jobs to drain before it stops:

umask 077
backup=/var/backups/pds-spaces-$(date -u +%Y%m%dT%H%M%SZ)
mkdir -p "$backup"
readlink -f /run/current-system > "$backup/old-system"
cp flake.lock "$backup/flake.lock"
systemctl stop bluesky-pds knot-rs spindle
tar --acls --xattrs --numeric-owner -C / -cpf "$backup/state.tar" var/lib/pds var/lib/knot var/lib/spindle
tar --compare -f "$backup/state.tar" -C / var/lib/pds var/lib/knot var/lib/spindle
cp --dereference /run/agenix/pds-env "$backup/pds-env"
cp --dereference /run/agenix/knot-env "$backup/knot-env"

Stop on any failure. If backup fails before activation, restart the unchanged services. Keep the backup root-only; it contains private keys.

Then use the normal nixos-rebuild switch --flake .#asusmini and ensure systemctl start bluesky-pds knot-rs spindle succeeds. Check PDS local and public health/migration counters, hosted PLC KEM keys, and Knot/Spindle/SSH health. Verify root's git push --dry-run succeeds and the checkout is clean. After all checks pass:

systemctl reset-failed auto-update.service
systemctl start auto-update.timer
exec 9>&-

Do not blindly roll back databases or PLC changes after activation has started.

Development

Updating Flake Inputs

nix flake update

Testing Changes Locally

nixos-rebuild build --flake .#asusmini

DNS Management

DNS is managed with dnscontrol (available in dev shell). See dns/README.md for details.

Architecture

┌─────────────────────────────────────────┐
│           Internet (HTTPS)              │
└────────────────┬────────────────────────┘
                 │
         ┌───────▼────────┐
         │  Caddy (80/443)│
         └───────┬────────┘
                 │
     ┌───────────┼───────────────┐
     │           │               │
┌────▼─────┐ ┌──▼────┐ ┌───────▼──────┐
│PDS (5556)│ │Knot   │ │Spindle (6555)│
│          │ │(5555) │ │              │
└──────────┘ └───────┘ └──────────────┘

Key Files

  • flake.nix - Main flake configuration
  • hosts/asusmini/ - Server-specific configuration
    • default.nix - Base system config
    • atproto.nix - ATProto service configs
    • hardware-configuration.nix - Hardware-specific settings
  • secrets/secrets.nix - Secret encryption keys
  • secrets/*.age - Encrypted secrets

Admin Contact

Primary admin: Anish

Notes

  • System uses NixOS unstable
  • All services run under dedicated system users
  • Secrets are encrypted at rest and decrypted on boot to /run/agenix/
  • Keep at least one personal SSH key in addition to the system key for emergency access
S
Description
Nix config for our non-cloudron server
Readme
410 KiB
1 Stars 1 Watchers 0 Forks
Languages
Python 45.2%
Nix 38.2%
Shell 15.7%
JavaScript 0.9%