···
pkgs = nixpkgs.legacyPackages.${system};
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 { };
did-plc-server = did-plc-server;
21
+
caddy-proxy = caddy-proxy;
# Script to generate certificates on host
generate-certs = pkgs.writeShellScriptBin "generate-certs" ''
···
echo "Certificates generated in ./certs/"
44
-
caddy-proxy = pkgs.writeShellScriptBin "caddy-proxy" ''
49
-
CADDYFILE="./Caddyfile"
52
-
while [[ $# -gt 0 ]]; do
63
-
echo "Usage: $0 [--cert-dir <directory>] [--caddyfile <file>]"
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"
70
-
echo "The certificate directory should contain:"
71
-
echo " - cert.pem (certificate file)"
72
-
echo " - key.pem (private key file)"
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"
82
-
echo "Unknown option: $1"
88
-
# Convert to absolute paths
89
-
CERT_DIR=$(realpath "$CERT_DIR")
90
-
CADDYFILE=$(realpath "$CADDYFILE")
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"
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."
106
-
# Check for required certificates
107
-
if [ ! -f "$CERT_DIR/cert.pem" ]; then
108
-
echo "ERROR: Missing cert.pem in $CERT_DIR"
112
-
if [ ! -f "$CERT_DIR/key.pem" ]; then
113
-
echo "ERROR: Missing key.pem in $CERT_DIR"
117
-
echo "Starting Caddy..."
118
-
echo "Caddyfile: $CADDYFILE"
119
-
echo "Certificates: $CERT_DIR"
120
-
echo "Press Ctrl+C to stop"
123
-
# Set environment variables that can be used in Caddyfile
125
-
export CERT_FILE="$CERT_DIR/cert.pem"
126
-
export KEY_FILE="$CERT_DIR/key.pem"
128
-
# Run Caddy with the specified Caddyfile
129
-
${pkgs.caddy}/bin/caddy run --config "$CADDYFILE"
132
-
# Script to start bluesky-pds
133
-
pds = pkgs.writeShellScriptBin "pds" ''
136
-
# Default port for bluesky-pds
137
-
PORT=''${BLUESKY_PDS_PORT:-3000}
139
-
# Create data directories
140
-
mkdir -p ./data/pds/blocks
141
-
mkdir -p ./data/pds/db
143
-
echo "Starting Bluesky PDS on port $PORT..."
144
-
echo "Data directory: ./data/pds"
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"
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
157
-
export PDS_PLC_ROTATION_KEY_K256_PRIVATE_KEY_HEX="$(cat ./data/pds/plc-rotation-key.txt)"
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
164
-
export PDS_JWT_SECRET="$(cat ./data/pds/jwt-secret.txt)"
166
-
# Set admin password
167
-
export PDS_ADMIN_PASSWORD="admin"
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"
173
-
# Enable development mode
174
-
export PDS_DEV_MODE="true"
176
-
${pkgs.bluesky-pds}/bin/pds