Flake to setup a local env for atproto development

Add pds

edouard.paris 42f26759 65e74fc2

verified
Changed files
+86 -3
+1
.gitignore
···
certs
···
certs
+
data
+12
Caddyfile
···
header Content-Type "text/plain"
respond "Hello API!" 200
}
···
header Content-Type "text/plain"
respond "Hello API!" 200
}
+
+
pds.example.org:8443 {
+
tls ./certs/cert.pem ./certs/key.pem
+
+
reverse_proxy localhost:3000
+
}
+
+
plc.example.org:8444 {
+
tls ./certs/cert.pem ./certs/key.pem
+
+
reverse_proxy localhost:2582
+
}
+73 -3
flake.nix
···
-key-file key.pem \
localhost \
127.0.0.1 \
-
::1
echo "Certificates generated in ./certs/"
echo "Files created:"
···
# Run Caddy with the specified Caddyfile
${pkgs.caddy}/bin/caddy run --config "$CADDYFILE"
'';
};
# Development shell
···
caddy
mkcert
curl
];
shellHook = ''
-
echo "Caddy development environment"
echo "Available commands:"
echo " nix run .#generate-certs - Generate test certificates"
echo " nix run .#caddy-proxy - Start Caddy with full config"
-
echo " nix run .#caddy-oneliner - Start Caddy with minimal config"
'';
};
};
···
-key-file key.pem \
localhost \
127.0.0.1 \
+
::1 \
+
pds.example.org \
+
plc.example.org
echo "Certificates generated in ./certs/"
echo "Files created:"
···
# Run Caddy with the specified Caddyfile
${pkgs.caddy}/bin/caddy run --config "$CADDYFILE"
'';
+
+
# Script to start bluesky-pds
+
pds = pkgs.writeShellScriptBin "pds" ''
+
set -e
+
+
# Default port for bluesky-pds
+
PORT=''${BLUESKY_PDS_PORT:-3000}
+
+
# Create data directories
+
mkdir -p ./data/pds/blocks
+
mkdir -p ./data/pds/db
+
+
echo "Starting Bluesky PDS on port $PORT..."
+
echo "Data directory: ./data/pds"
+
+
# Configure for local disk storage
+
export PDS_DATA_DIRECTORY="./data/pds"
+
export PDS_BLOBSTORE_DISK_LOCATION="./data/pds/blocks"
+
export PDS_DB_SQLITE_LOCATION="./data/pds/db/pds.sqlite"
+
export PDS_PORT="$PORT"
+
+
# Generate or use existing PLC rotation key
+
if [ ! -f "./data/pds/plc-rotation-key.txt" ]; then
+
echo "Generating PLC rotation key..."
+
openssl rand -hex 32 > ./data/pds/plc-rotation-key.txt
+
fi
+
export PDS_PLC_ROTATION_KEY_K256_PRIVATE_KEY_HEX="$(cat ./data/pds/plc-rotation-key.txt)"
+
+
# Generate or use existing JWT secret
+
if [ ! -f "./data/pds/jwt-secret.txt" ]; then
+
echo "Generating JWT secret..."
+
openssl rand -hex 32 > ./data/pds/jwt-secret.txt
+
fi
+
export PDS_JWT_SECRET="$(cat ./data/pds/jwt-secret.txt)"
+
+
# Set admin password
+
export PDS_ADMIN_PASSWORD="admin"
+
+
# Set hostname and URL scheme (using example.org domain)
+
export PDS_HOSTNAME="pds.example.org:8443"
+
export PDS_SERVICE_URL="https://pds.example.org:8443"
+
+
# Enable development mode
+
export PDS_DEV_MODE="true"
+
+
${pkgs.bluesky-pds}/bin/pds
+
'';
};
# Development shell
···
caddy
mkcert
curl
+
bluesky-pds
+
openssl
];
shellHook = ''
+
echo "Caddy development environment with Bluesky PDS"
echo "Available commands:"
echo " nix run .#generate-certs - Generate test certificates"
echo " nix run .#caddy-proxy - Start Caddy with full config"
+
echo " nix run .#pds - Start Bluesky PDS server"
+
echo ""
+
echo "Services:"
+
echo " Bluesky PDS: https://pds.example.org:8443 (proxied from port 3000)"
+
echo " DID PLC: https://plc.example.org:8444 (proxied from port 2582)"
+
echo ""
+
echo "Environment variables:"
+
echo " BLUESKY_PDS_PORT=3000 - Port for Bluesky PDS (default: 3000)"
+
echo ""
+
echo "Usage:"
+
echo " 1. Add these lines to your /etc/hosts file:"
+
echo " 127.0.0.1 pds.example.org"
+
echo " 127.0.0.1 plc.example.org"
+
echo " 2. Run 'nix run .#generate-certs' to create certificates"
+
echo " 3. Run 'nix run .#did-plc-server' in one terminal (if needed)"
+
echo " 4. Run 'nix run .#pds' in another terminal"
+
echo " 5. Run 'nix run .#caddy-proxy' in another terminal"
+
echo " 6. Access services at:"
+
echo " - Bluesky PDS: https://pds.example.org:8443"
+
echo " - DID PLC: https://plc.example.org:8444"
'';
};
};