Nix + Bun Architecture

Architecture Overview: This application demonstrates a hybrid architecture where Nix generates HTML content and Bun serves it, along with handling API endpoints and database operations.

System Information

Nix System: x86_64-linux

Nix Version: 2.24.12

Subscribe to Updates

This form demonstrates how Nix-generated content can interact with Bun's API and database:

Interaction Example:

  1. The email form above is a Web Component defined in static/js/app.js
  2. Nix includes this JavaScript in the page using builtins.readFile
  3. When you submit an email, the component sends a POST request to /api/emails
  4. Bun's API handler validates the email and stores it in the SQLite database
  5. The component shows success or error messages based on the response

How This Architecture Works

Request Flow:

  1. Your browser makes a request to the server (e.g., /nix)
  2. Bun receives the request and routes it to the appropriate handler
  3. For content pages like this one, Bun executes:
    nix eval --arg route "/nix" --raw -f ./app get
  4. Nix evaluates the expression in app/default.nix, which imports app/get.nix
  5. Nix reads HTML templates from static/html/ and JS from static/js/
  6. Nix generates the HTML content you're viewing right now
  7. Bun returns the generated HTML to your browser

Technology Roles:

Nix's Role

Bun's Role