--- name: nix-http-server description: Create HTTP servers for Nix flake projects. Use when serving static files or running development servers. CRITICAL CONSTRAINT - Never suggest Python dependencies. --- # Nix HTTP Server Skill ## Core Constraint **NEVER suggest Python-based HTTP servers** (python -m http.server, etc.) All dependencies MUST come from nixpkgs only. ## When to Use - User needs to serve static files from a Nix project - User wants to create development servers - User needs process orchestration for multiple services - Project has a flake.nix file ## Implementation Pattern ### 1. Use Caddy for HTTP Serving Caddy is the approved HTTP server because: - Available in nixpkgs - Supports configuration as code - Better features than simple Python server - Works with process-compose orchestration ### 2. Configuration Generation Generate configurations at build time using Nix expressions: ```nix makeCaddyConfig = pkgs: port: root: pkgs.writeText "Caddyfile" '' :${toString port} { root * ${root} file_server browse encode gzip log { output stdout format console } } ''; ``` OR generate at runtime for development flexibility: ```bash # Generate Caddyfile at runtime CADDY_CONFIG=$(mktemp) cat > "$CADDY_CONFIG" <` - Path to config file - `--adapter caddyfile` - Parse as Caddyfile format (not JSON) - `run` - Run server (blocking) ### Process-Compose Flags - `--tui=false` - Disable TUI (required for non-interactive environments) - `-f ` - Config file path ### Runtime Config Pattern ```bash #!/usr/bin/env bash set -euo pipefail # Validate directory exists CONTENT_ROOT="$PWD/presentation" if [ ! -d "$CONTENT_ROOT" ]; then echo "Error: presentation/ directory not found" exit 1 fi # Generate config at runtime (allows serving from working directory) CADDY_CONFIG=$(mktemp) trap "rm -f $CADDY_CONFIG" EXIT cat > "$CADDY_CONFIG" <