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.

Add postgres to did plc

+69 -5
+6 -4
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 + plc = pkgs.callPackage ./packages/plc.nix { inherit did-plc-server; }; 13 14 caddy-proxy = pkgs.callPackage ./packages/caddy.nix { }; 14 15 pds = pkgs.callPackage ./packages/pds.nix { }; 15 16 mailhog = pkgs.callPackage ./packages/mailhog.nix { }; ··· 17 18 { 18 19 packages.${system} = { 19 20 20 - did-plc-server = did-plc-server; 21 + plc = plc; 21 22 22 23 caddy-proxy = caddy-proxy; 23 24 ··· 60 61 bluesky-pds 61 62 openssl 62 63 mailhog 64 + postgresql 63 65 ]; 64 66 65 67 shellHook = '' ··· 67 69 echo "Available commands:" 68 70 echo " nix run .#generate-certs - Generate test certificates" 69 71 echo " nix run .#caddy-proxy - Start Caddy with full config" 70 - echo " nix run .#did-plc-server - Start DID PLC server" 72 + echo " nix run .#plc - Start DID PLC server with PostgreSQL" 71 73 echo " nix run .#pds - Start Bluesky PDS server" 72 74 echo " nix run .#mailhog - Start MailHog email server" 73 75 echo "" 74 76 echo "Services:" 75 77 echo " Bluesky PDS: https://pds.example.org:8443 (proxied from port 3000)" 76 - echo " DID PLC: https://plc.example.org:8444 (proxied from port 2582)" 78 + echo " DID PLC: https://plc.example.org:8444 (proxied from port 2582, PostgreSQL on 5433)" 77 79 echo " MailHog: http://localhost:8025 (SMTP on port 1025)" 78 80 echo "" 79 81 echo "Environment variables:" ··· 85 87 echo " 127.0.0.1 plc.example.org" 86 88 echo " 2. Run 'nix run .#generate-certs' to create certificates" 87 89 echo " 3. Run 'nix run .#mailhog' in one terminal" 88 - echo " 4. Run 'nix run .#did-plc-server' in another terminal (if needed)" 90 + echo " 4. Run 'nix run .#plc' in another terminal" 89 91 echo " 5. Run 'nix run .#pds' in another terminal" 90 92 echo " 6. Run 'nix run .#caddy-proxy' in another terminal" 91 93 echo " 7. Access services at:"
+2 -1
packages/did-method-plc.nix
··· 46 46 # Copy the source and dependencies 47 47 cp -r . $out/share/did-plc-server/ 48 48 49 - # Create the executable wrapper 49 + # Create the executable wrapper for just the PLC server 50 50 makeWrapper "${lib.getExe pnpm_9}" "$out/bin/did-plc-server" \ 51 51 --chdir "$out/share/did-plc-server" \ 52 52 --set-default LOG_ENABLED "true" \ 53 53 --set-default LOG_LEVEL "debug" \ 54 + --set-default DATABASE_URL "postgresql://$(whoami)@localhost:5433/plc" \ 54 55 --add-flags "--filter" \ 55 56 --add-flags "@did-plc/server" \ 56 57 --add-flags "start"
+61
packages/plc.nix
··· 1 + { pkgs, did-plc-server }: 2 + 3 + pkgs.writeShellScriptBin "plc" '' 4 + set -e 5 + 6 + echo "Starting PLC services (PostgreSQL + DID PLC Server)..." 7 + 8 + # Set PostgreSQL environment 9 + export PGHOST="localhost" 10 + export PGDATA="./data/plc/db" 11 + export PGPORT="5433" 12 + export PGUSER="$(whoami)" 13 + 14 + # Create data directory 15 + mkdir -p "$PGDATA" 16 + 17 + echo "Using PostgreSQL at $PGDATA" 18 + 19 + # Initialize PostgreSQL data directory if it doesn't exist 20 + if [ ! -d "$PGDATA/base" ]; then 21 + echo "Initializing PostgreSQL database..." 22 + ${pkgs.postgresql}/bin/pg_ctl initdb -D "$PGDATA" -o "--auth-local=trust --auth-host=trust" 23 + 24 + # Add some logging configuration 25 + echo "log_min_messages = warning" >> "$PGDATA/postgresql.conf" 26 + echo "log_min_error_statement = error" >> "$PGDATA/postgresql.conf" 27 + echo "log_connections = on" >> "$PGDATA/postgresql.conf" 28 + echo "log_disconnections = on" >> "$PGDATA/postgresql.conf" 29 + fi 30 + 31 + # Start PostgreSQL server 32 + echo "Starting PostgreSQL on port $PGPORT..." 33 + ${pkgs.postgresql}/bin/pg_ctl -D "$PGDATA" -o "-p $PGPORT --unix_socket_directories='$PWD'" start 34 + 35 + # Wait for PostgreSQL to be ready 36 + echo "Waiting for PostgreSQL to be ready..." 37 + until ${pkgs.postgresql}/bin/pg_isready -p "$PGPORT" -h localhost; do 38 + sleep 1 39 + done 40 + 41 + # Create database if it doesn't exist 42 + ${pkgs.postgresql}/bin/createdb -p "$PGPORT" -h localhost plc 2>/dev/null || true 43 + 44 + # Set DATABASE_URL 45 + export DATABASE_URL="postgresql://$PGUSER@localhost:$PGPORT/plc" 46 + 47 + echo "PostgreSQL ready at: $DATABASE_URL" 48 + echo "Starting DID PLC Server..." 49 + 50 + # Cleanup function using pg_ctl 51 + cleanup() { 52 + echo "Shutting down PostgreSQL..." 53 + ${pkgs.postgresql}/bin/pg_ctl -D "$PGDATA" stop -m fast 2>/dev/null || true 54 + } 55 + 56 + # Set trap to cleanup on exit 57 + trap cleanup EXIT INT TERM 58 + 59 + # Start the PLC server (don't use exec so cleanup trap works) 60 + ${did-plc-server}/bin/did-plc-server 61 + ''