Flake to setup a local env for atproto development

wip: Add relay

edouard.paris 1275c130 1748ea06

verified
+1
.gitignore
···
certs
data
+
result
+6
Caddyfile
···
reverse_proxy localhost:2582
}
+
+
relay.example.org:8445 {
+
tls ./certs/cert.pem ./certs/key.pem
+
+
reverse_proxy localhost:2470
+
}
+8 -5
README.md
···
```
127.0.0.1 pds.example.org
127.0.0.1 plc.example.org
+
127.0.0.1 relay.example.org
```
Generate SSL certificates before first use:
···
```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. **Create an invite code:**
```bash
···
- **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
···
- `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
+37 -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 vertically for Caddy proxy
+
tmux split-window -v -t atproto "${caddy-proxy}/bin/caddy-proxy"
-
# Split the right pane vertically for Caddy proxy
-
tmux split-window -v -t atproto.1 "${caddy-proxy}/bin/caddy-proxy"
+
# Split vertically for Relay (with environment variables)
+
tmux split-window -v -t atproto "RELAY_ADMIN_PASSWORD=password RELAY_PLC_HOST=https://plc.example.org:8444 RELAY_TRUSTED_DOMAINS=*.example.org RELAY_ALLOW_INSECURE_HOSTS=true ${indigo-relay}/bin/relay serve"
-
# Split the left pane vertically for MailHog
-
tmux split-window -v -t atproto.0 "${mailhog}/bin/mailhog"
+
# Make all panes equal size
+
tmux select-layout -t atproto even-vertical
# 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 (single column):"
+
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"
+
'';
+
+
# 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"
+
+
${indigo-relay}/bin/relay serve
'';
};
+46
packages/indigo-relay.nix
···
+
{ lib
+
, buildGoModule
+
, fetchFromGitHub
+
}:
+
+
buildGoModule rec {
+
pname = "indigo-relay";
+
version = "unstable-2024-10-03";
+
+
src = fetchFromGitHub {
+
owner = "bluesky-social";
+
repo = "indigo";
+
rev = "master"; # Latest commit from master branch
+
hash = "sha256-yVj7DKGAUXQO4eTu4reAtm7bTE4ab0jYGX2ba74qazU=";
+
};
+
+
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";
+
};
+
}