Flake to setup a local env for atproto development

Compare changes

Choose any two refs to compare.

+1
.gitignore
···
certs
data
+
result
+6 -14
Caddyfile
···
auto_https off
}
-
localhost:8443 {
-
tls ./certs/cert.pem ./certs/key.pem
-
-
header Content-Type "text/plain"
-
respond "Hello World!" 200
-
}
-
-
localhost:8444 {
-
tls ./certs/cert.pem ./certs/key.pem
-
-
header Content-Type "text/plain"
-
respond "Hello API!" 200
-
}
-
pds.example.org:8443 {
tls ./certs/cert.pem ./certs/key.pem
···
reverse_proxy localhost:2582
}
+
+
relay.example.org:8445 {
+
tls ./certs/cert.pem ./certs/key.pem
+
+
reverse_proxy localhost:2470
+
}
+21
LICENSE
···
+
MIT License
+
+
Copyright (c) 2025
+
+
Permission is hereby granted, free of charge, to any person obtaining a copy
+
of this software and associated documentation files (the "Software"), to deal
+
in the Software without restriction, including without limitation the rights
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+
copies of the Software, and to permit persons to whom the Software is
+
furnished to do so, subject to the following conditions:
+
+
The above copyright notice and this permission notice shall be included in all
+
copies or substantial portions of the Software.
+
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+
SOFTWARE.
+60 -26
README.md
···
## Prerequisites
-
Make sure to add these lines to your `/etc/hosts` file:
-
```
-
127.0.0.1 pds.example.org
-
127.0.0.1 plc.example.org
-
```
+
1. **Install mkcert** (required for SSL certificate generation):
+
- On macOS: `brew install mkcert`
+
- On Linux: See [mkcert installation guide](https://github.com/FiloSottile/mkcert#installation)
+
- After installation, run: `mkcert -install`
-
Generate SSL certificates before first use:
-
```bash
-
nix run .#generate-certs
-
```
+
2. **Add hosts file entries:**
+
```
+
127.0.0.1 pds.example.org
+
127.0.0.1 plc.example.org
+
127.0.0.1 relay.example.org
+
```
+
+
3. **Generate SSL certificates before first use:**
+
```bash
+
nix run .#generate-certs
+
```
## Quick Start
···
```bash
nix run .#all
```
-
This will start all services in a 2x2 tmux pane layout:
-
- Top-left: PLC server
-
- Bottom-left: MailHog server
-
- Top-right: PDS server
-
- Bottom-right: Caddy proxy
+
This will start all services in a single-column tmux pane layout:
+
- Pane 0: PLC server
+
- Pane 1: PDS server
+
- Pane 2: Caddy proxy
+
- Pane 3: AT Protocol Relay
+
+
3. **Add PDS host to the relay:**
+
```bash
+
goat relay --relay-host=https://relay.example.org:8445 admin --admin-password=password host add "https://pds.example.org:8443"
+
```
-
3. **Create an invite code:**
+
4. **Create an invite code:**
```bash
scripts/create-invite.sh
```
-
4. **Create a user account:**
+
5. **Create a user account:**
```bash
goat account create \
--pds-host=https://pds.example.org:8443 \
···
--handle=edouard.pds.example.org
```
-
Expected output:
+
6. **Verify the DID is registered:**
+
```bash
+
goat plc --plc-host=https://plc.example.org data <your-did>
```
-
Success!
-
DID: did:plc:pzvsc3jwfjwidojtpbxv4rdd
-
Handle: edouard.pds.example.org
+
+
7. **Login to your account:**
+
```bash
+
goat account login \
+
--username=edouard.pds.example.org \
+
--app-password=password \
+
--pds-host=https://pds.example.org:8443
```
-
5. **Verify the DID is registered:**
+
8. **Create your first post:**
```bash
-
goat --plc-host=https://plc.example.org data did:plc:pzvsc3jwfjwidojtpbxv4rdd
+
goat bsky post "hello world!"
```
## Services
- **Bluesky PDS**: https://pds.example.org:8443
- **DID PLC**: https://plc.example.org:8444
+
- **AT Protocol Relay**: https://relay.example.org:8445
- **MailHog**: http://localhost:8025
-
## Available Tools
+
## Monitoring
+
+
To monitor the AT Protocol relay firehose:
+
```bash
+
goat firehose --relay-host wss://relay.example.org:8445
+
```
-
- `goat` - AT Protocol CLI tool
-
- `curl`, `jq` - HTTP and JSON utilities
-
- `tmux` - Terminal multiplexer
+
This will show real-time events from the relay. You can run this in a separate terminal or tmux pane.
## Management Commands
- `tmux attach -t atproto` - Attach to the services session
- `tmux kill-session -t atproto` - Stop all services
+
- `nix run .#mailhog` - Start MailHog (run separately if needed)
- `nix run .#generate-certs` - Generate SSL certificates
+
+
## โš ๏ธ Security Warning
+
+
**This environment uses a modified AT Protocol relay with SSRF protection disabled.**
+
+
- The relay is built from a forked repository (`edouardparis/indigo`) with SSRF (Server-Side Request Forgery) protections disabled
+
- Custom ports are allowed without restrictions
+
- **This configuration is ONLY safe for local development environments**
+
- **DO NOT use this relay configuration against external hosts or in production**
+
- **DO NOT expose this relay to the internet**
+
+
This setup is designed for controlled local testing where you need flexibility in network access that would normally be restricted for security reasons.
+49 -12
flake.nix
···
caddy-proxy = pkgs.callPackage ./packages/caddy.nix { };
pds = pkgs.callPackage ./packages/pds.nix { };
mailhog = pkgs.callPackage ./packages/mailhog.nix { };
+
indigo-relay = pkgs.callPackage ./packages/indigo-relay.nix { };
in
{
packages.${system} = {
···
pds = pds;
mailhog = mailhog;
+
+
indigo-relay = indigo-relay;
# Script to generate certificates on host
generate-certs = pkgs.writeShellScriptBin "generate-certs" ''
···
127.0.0.1 \
::1 \
pds.example.org \
-
plc.example.org
+
plc.example.org \
+
relay.example.org
echo "Certificates generated in ./certs/"
echo "Files created:"
···
# Create new tmux session with PLC server
tmux new-session -d -s atproto "${plc}/bin/plc"
-
# Split horizontally for PDS server
-
tmux split-window -h -t atproto "${pds}/bin/pds"
+
# Split vertically for PDS server
+
tmux split-window -v -t atproto "${pds}/bin/pds"
-
# Split the right pane vertically for Caddy proxy
-
tmux split-window -v -t atproto.1 "${caddy-proxy}/bin/caddy-proxy"
+
# Split vertically for Caddy proxy
+
tmux split-window -v -t atproto "${caddy-proxy}/bin/caddy-proxy"
+
+
# Split vertically for Relay (with environment variables)
+
tmux split-window -v -t atproto "
+
export RELAY_ADMIN_PASSWORD=password
+
export RELAY_PLC_HOST=https://plc.example.org:8444
+
export RELAY_TRUSTED_DOMAINS=*.example.org
+
export RELAY_ALLOW_INSECURE_HOSTS=true
+
export RELAY_LOG_LEVEL=debug
+
export RELAY_DISABLE_SSRF=true
+
export RELAY_ALLOW_CUSTOM_PORTS=true
+
${indigo-relay}/bin/relay serve
+
"
-
# Split the left pane vertically for MailHog
-
tmux split-window -v -t atproto.0 "${mailhog}/bin/mailhog"
# Select the first pane
tmux select-pane -t atproto.0
···
echo " tmux attach -t atproto - Attach to the session"
echo " tmux kill-session -t atproto - Stop all services"
echo ""
-
echo "๐Ÿ”ฒ Panes layout (2x2 grid):"
-
echo " โ€ข Top-left: PLC server"
-
echo " โ€ข Bottom-left: MailHog server"
-
echo " โ€ข Top-right: PDS server"
-
echo " โ€ข Bottom-right: Caddy proxy"
+
echo "๐Ÿ“‹ Panes layout:"
+
echo " โ€ข Pane 0: PLC server"
+
echo " โ€ข Pane 1: PDS server"
+
echo " โ€ข Pane 2: Caddy proxy"
+
echo " โ€ข Pane 3: AT Protocol Relay"
echo ""
echo "๐Ÿ’ก Use Ctrl+b followed by arrow keys to switch between panes"
+
echo "๐Ÿ’ก To monitor firehose: goat firehose --relay-host wss://relay.example.org:8445"
+
'';
+
+
# Script to start relay with environment
+
relay = pkgs.writeShellScriptBin "relay" ''
+
set -e
+
+
echo "Starting AT Protocol Relay..."
+
echo "Admin password: password"
+
echo "PLC host: https://plc.example.org:8444"
+
echo ""
+
+
# Set relay environment variables
+
export RELAY_ADMIN_PASSWORD="password"
+
export RELAY_PLC_HOST="https://plc.example.org:8444"
+
export RELAY_TRUSTED_DOMAINS="*.example.org"
+
export RELAY_ALLOW_INSECURE_HOSTS="true"
+
export RELAY_LOG_LEVEL="debug"
+
export RELAY_DISABLE_SSRF="true"
+
export RELAY_ALLOW_CUSTOM_PORTS="true"
+
+
${indigo-relay}/bin/relay serve
'';
};
···
echo " nix run .#plc - Start PLC server"
echo " nix run .#pds - Start PDS server"
echo " nix run .#caddy-proxy - Start Caddy proxy"
+
echo " nix run .#relay - Start AT Protocol Relay"
echo " nix run .#mailhog - Start MailHog"
echo " nix run .#generate-certs - Generate SSL certificates"
echo ""
+46
packages/indigo-relay.nix
···
+
{ lib
+
, buildGoModule
+
, fetchFromGitHub
+
}:
+
+
buildGoModule rec {
+
pname = "indigo-relay";
+
version = "unstable-2024-10-03";
+
+
src = fetchFromGitHub {
+
owner = "edouardparis";
+
repo = "indigo";
+
rev = "disable-ssrf-and-allow-custom-ports";
+
hash = "sha256-0Uy/7IT3gVVkfntXauue07O6WDhmU+heNT4fSh+sK5A=";
+
};
+
+
vendorHash = "sha256-7mYvgvR0tZdEnUgUYzKv6d2QyeXXnrFgVwY8/4UM3oU=";
+
+
# Build only the relay binary
+
subPackages = [ "cmd/relay" ];
+
+
# Set the module path
+
modRoot = ".";
+
+
# Build configuration
+
env.CGO_ENABLED = "1";
+
+
# Build flags
+
ldflags = [
+
"-s"
+
"-w"
+
"-X github.com/carlmjohnson/versioninfo.Version=${version}"
+
];
+
+
# Tests require additional services running
+
doCheck = false;
+
+
meta = with lib; {
+
description = "AT Protocol relay daemon from the Indigo project";
+
homepage = "https://github.com/bluesky-social/indigo";
+
license = with licenses; [ mit asl20 ]; # Dual licensed
+
maintainers = with maintainers; [ ];
+
platforms = platforms.linux ++ platforms.darwin;
+
mainProgram = "relay";
+
};
+
}