Flake to setup a local env for atproto development
8
fork

Configure Feed

Select the types of activity you want to include in your feed.

New organization per file

+142 -135
+6 -135
flake.nix
··· 10 10 system = "x86_64-linux"; 11 11 pkgs = nixpkgs.legacyPackages.${system}; 12 12 did-plc-server = pkgs.callPackage ./packages/did-method-plc.nix { }; 13 + caddy-proxy = pkgs.callPackage ./packages/caddy.nix { }; 14 + pds = pkgs.callPackage ./packages/pds.nix { }; 13 15 in 14 16 { 15 17 packages.${system} = { 16 18 17 19 did-plc-server = did-plc-server; 20 + 21 + caddy-proxy = caddy-proxy; 22 + 23 + pds = pds; 18 24 19 25 # Script to generate certificates on host 20 26 generate-certs = pkgs.writeShellScriptBin "generate-certs" '' ··· 39 45 echo "Certificates generated in ./certs/" 40 46 echo "Files created:" 41 47 ls -la . 42 - ''; 43 - 44 - caddy-proxy = pkgs.writeShellScriptBin "caddy-proxy" '' 45 - set -e 46 - 47 - # Default values 48 - CERT_DIR="./certs" 49 - CADDYFILE="./Caddyfile" 50 - 51 - # Parse arguments 52 - while [[ $# -gt 0 ]]; do 53 - case $1 in 54 - --cert-dir) 55 - CERT_DIR="$2" 56 - shift 2 57 - ;; 58 - --caddyfile) 59 - CADDYFILE="$2" 60 - shift 2 61 - ;; 62 - --help|-h) 63 - echo "Usage: $0 [--cert-dir <directory>] [--caddyfile <file>]" 64 - echo "" 65 - echo "Options:" 66 - echo " --cert-dir <dir> Directory containing certificates (default: ./certs)" 67 - echo " --caddyfile <file> Path to Caddyfile (default: ./Caddyfile)" 68 - echo " --help, -h Show this help message" 69 - echo "" 70 - echo "The certificate directory should contain:" 71 - echo " - cert.pem (certificate file)" 72 - echo " - key.pem (private key file)" 73 - echo "" 74 - echo "Examples:" 75 - echo " $0 # Use ./certs and ./Caddyfile" 76 - echo " $0 --cert-dir ~/my-certs # Custom cert directory" 77 - echo " $0 --caddyfile ~/my-caddy/Caddyfile # Custom Caddyfile" 78 - echo " $0 --cert-dir ~/certs --caddyfile ./conf/Caddyfile" 79 - exit 0 80 - ;; 81 - *) 82 - echo "Unknown option: $1" 83 - exit 1 84 - ;; 85 - esac 86 - done 87 - 88 - # Convert to absolute paths 89 - CERT_DIR=$(realpath "$CERT_DIR") 90 - CADDYFILE=$(realpath "$CADDYFILE") 91 - 92 - # Check if Caddyfile exists 93 - if [ ! -f "$CADDYFILE" ]; then 94 - echo "ERROR: Caddyfile not found: $CADDYFILE" 95 - echo "Create a Caddyfile or use: nix run .#generate-caddyfile" 96 - exit 1 97 - fi 98 - 99 - # Check if certificate directory exists 100 - if [ ! -d "$CERT_DIR" ]; then 101 - echo "ERROR: Certificate directory does not exist: $CERT_DIR" 102 - echo "Please create the directory and add your certificates." 103 - exit 1 104 - fi 105 - 106 - # Check for required certificates 107 - if [ ! -f "$CERT_DIR/cert.pem" ]; then 108 - echo "ERROR: Missing cert.pem in $CERT_DIR" 109 - exit 1 110 - fi 111 - 112 - if [ ! -f "$CERT_DIR/key.pem" ]; then 113 - echo "ERROR: Missing key.pem in $CERT_DIR" 114 - exit 1 115 - fi 116 - 117 - echo "Starting Caddy..." 118 - echo "Caddyfile: $CADDYFILE" 119 - echo "Certificates: $CERT_DIR" 120 - echo "Press Ctrl+C to stop" 121 - echo "" 122 - 123 - # Set environment variables that can be used in Caddyfile 124 - export CERT_DIR 125 - export CERT_FILE="$CERT_DIR/cert.pem" 126 - export KEY_FILE="$CERT_DIR/key.pem" 127 - 128 - # Run Caddy with the specified Caddyfile 129 - ${pkgs.caddy}/bin/caddy run --config "$CADDYFILE" 130 - ''; 131 - 132 - # Script to start bluesky-pds 133 - pds = pkgs.writeShellScriptBin "pds" '' 134 - set -e 135 - 136 - # Default port for bluesky-pds 137 - PORT=''${BLUESKY_PDS_PORT:-3000} 138 - 139 - # Create data directories 140 - mkdir -p ./data/pds/blocks 141 - mkdir -p ./data/pds/db 142 - 143 - echo "Starting Bluesky PDS on port $PORT..." 144 - echo "Data directory: ./data/pds" 145 - 146 - # Configure for local disk storage 147 - export PDS_DATA_DIRECTORY="./data/pds" 148 - export PDS_BLOBSTORE_DISK_LOCATION="./data/pds/blocks" 149 - export PDS_DB_SQLITE_LOCATION="./data/pds/db/pds.sqlite" 150 - export PDS_PORT="$PORT" 151 - 152 - # Generate or use existing PLC rotation key 153 - if [ ! -f "./data/pds/plc-rotation-key.txt" ]; then 154 - echo "Generating PLC rotation key..." 155 - openssl rand -hex 32 > ./data/pds/plc-rotation-key.txt 156 - fi 157 - export PDS_PLC_ROTATION_KEY_K256_PRIVATE_KEY_HEX="$(cat ./data/pds/plc-rotation-key.txt)" 158 - 159 - # Generate or use existing JWT secret 160 - if [ ! -f "./data/pds/jwt-secret.txt" ]; then 161 - echo "Generating JWT secret..." 162 - openssl rand -hex 32 > ./data/pds/jwt-secret.txt 163 - fi 164 - export PDS_JWT_SECRET="$(cat ./data/pds/jwt-secret.txt)" 165 - 166 - # Set admin password 167 - export PDS_ADMIN_PASSWORD="admin" 168 - 169 - # Set hostname and URL scheme (using example.org domain) 170 - export PDS_HOSTNAME="pds.example.org:8443" 171 - export PDS_SERVICE_URL="https://pds.example.org:8443" 172 - 173 - # Enable development mode 174 - export PDS_DEV_MODE="true" 175 - 176 - ${pkgs.bluesky-pds}/bin/pds 177 48 ''; 178 49 }; 179 50
+89
packages/caddy.nix
··· 1 + { pkgs }: 2 + 3 + pkgs.writeShellScriptBin "caddy-proxy" '' 4 + set -e 5 + 6 + # Default values 7 + CERT_DIR="./certs" 8 + CADDYFILE="./Caddyfile" 9 + 10 + # Parse arguments 11 + while [[ $# -gt 0 ]]; do 12 + case $1 in 13 + --cert-dir) 14 + CERT_DIR="$2" 15 + shift 2 16 + ;; 17 + --caddyfile) 18 + CADDYFILE="$2" 19 + shift 2 20 + ;; 21 + --help|-h) 22 + echo "Usage: $0 [--cert-dir <directory>] [--caddyfile <file>]" 23 + echo "" 24 + echo "Options:" 25 + echo " --cert-dir <dir> Directory containing certificates (default: ./certs)" 26 + echo " --caddyfile <file> Path to Caddyfile (default: ./Caddyfile)" 27 + echo " --help, -h Show this help message" 28 + echo "" 29 + echo "The certificate directory should contain:" 30 + echo " - cert.pem (certificate file)" 31 + echo " - key.pem (private key file)" 32 + echo "" 33 + echo "Examples:" 34 + echo " $0 # Use ./certs and ./Caddyfile" 35 + echo " $0 --cert-dir ~/my-certs # Custom cert directory" 36 + echo " $0 --caddyfile ~/my-caddy/Caddyfile # Custom Caddyfile" 37 + echo " $0 --cert-dir ~/certs --caddyfile ./conf/Caddyfile" 38 + exit 0 39 + ;; 40 + *) 41 + echo "Unknown option: $1" 42 + exit 1 43 + ;; 44 + esac 45 + done 46 + 47 + # Convert to absolute paths 48 + CERT_DIR=$(realpath "$CERT_DIR") 49 + CADDYFILE=$(realpath "$CADDYFILE") 50 + 51 + # Check if Caddyfile exists 52 + if [ ! -f "$CADDYFILE" ]; then 53 + echo "ERROR: Caddyfile not found: $CADDYFILE" 54 + echo "Create a Caddyfile or use: nix run .#generate-caddyfile" 55 + exit 1 56 + fi 57 + 58 + # Check if certificate directory exists 59 + if [ ! -d "$CERT_DIR" ]; then 60 + echo "ERROR: Certificate directory does not exist: $CERT_DIR" 61 + echo "Please create the directory and add your certificates." 62 + exit 1 63 + fi 64 + 65 + # Check for required certificates 66 + if [ ! -f "$CERT_DIR/cert.pem" ]; then 67 + echo "ERROR: Missing cert.pem in $CERT_DIR" 68 + exit 1 69 + fi 70 + 71 + if [ ! -f "$CERT_DIR/key.pem" ]; then 72 + echo "ERROR: Missing key.pem in $CERT_DIR" 73 + exit 1 74 + fi 75 + 76 + echo "Starting Caddy..." 77 + echo "Caddyfile: $CADDYFILE" 78 + echo "Certificates: $CERT_DIR" 79 + echo "Press Ctrl+C to stop" 80 + echo "" 81 + 82 + # Set environment variables that can be used in Caddyfile 83 + export CERT_DIR 84 + export CERT_FILE="$CERT_DIR/cert.pem" 85 + export KEY_FILE="$CERT_DIR/key.pem" 86 + 87 + # Run Caddy with the specified Caddyfile 88 + ${pkgs.caddy}/bin/caddy run --config "$CADDYFILE" 89 + ''
+47
packages/pds.nix
··· 1 + { pkgs }: 2 + 3 + pkgs.writeShellScriptBin "pds" '' 4 + set -e 5 + 6 + # Default port for bluesky-pds 7 + PORT=''${BLUESKY_PDS_PORT:-3000} 8 + 9 + # Create data directories 10 + mkdir -p ./data/pds/blocks 11 + mkdir -p ./data/pds/db 12 + 13 + echo "Starting Bluesky PDS on port $PORT..." 14 + echo "Data directory: ./data/pds" 15 + 16 + # Configure for local disk storage 17 + export PDS_DATA_DIRECTORY="./data/pds" 18 + export PDS_BLOBSTORE_DISK_LOCATION="./data/pds/blocks" 19 + export PDS_DB_SQLITE_LOCATION="./data/pds/db/pds.sqlite" 20 + export PDS_PORT="$PORT" 21 + 22 + # Generate or use existing PLC rotation key 23 + if [ ! -f "./data/pds/plc-rotation-key.txt" ]; then 24 + echo "Generating PLC rotation key..." 25 + ${pkgs.openssl}/bin/openssl rand -hex 32 > ./data/pds/plc-rotation-key.txt 26 + fi 27 + export PDS_PLC_ROTATION_KEY_K256_PRIVATE_KEY_HEX="$(cat ./data/pds/plc-rotation-key.txt)" 28 + 29 + # Generate or use existing JWT secret 30 + if [ ! -f "./data/pds/jwt-secret.txt" ]; then 31 + echo "Generating JWT secret..." 32 + ${pkgs.openssl}/bin/openssl rand -hex 32 > ./data/pds/jwt-secret.txt 33 + fi 34 + export PDS_JWT_SECRET="$(cat ./data/pds/jwt-secret.txt)" 35 + 36 + # Set admin password 37 + export PDS_ADMIN_PASSWORD="admin" 38 + 39 + # Set hostname and URL scheme (using example.org domain) 40 + export PDS_HOSTNAME="pds.example.org:8443" 41 + export PDS_SERVICE_URL="https://pds.example.org:8443" 42 + 43 + # Enable development mode 44 + export PDS_DEV_MODE="true" 45 + 46 + ${pkgs.bluesky-pds}/bin/pds 47 + ''