Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Replit 16 min read How-to mediumAdept

Building a web app with Nix (Because why not?)

A toy web app is built in the Nix language by having a Python HTTP server shell out to `nix eval`, passing the request path and body as `--arg` values. Routing is done with attribute sets and `builtins.hasAttr`. A TODO API is backed by the Replit database, using `pkgs.runCommand` with curl to get around Nix's lack of side effects. Along the way it explains Nix language basics, including `let..in`, laziness, default arguments and `import`, plus why a dummy `builtins.currentTime` attribute is needed to defeat derivation caching.

Assumes: Nix package manager basicsPython http.serverHTTP request methods

Related posts

  • Dynamic version for Nix derivations

    Replit mediumAdept

    Replit derives a Nix derivation's version automatically from the git short SHA instead of editing default.nix by hand for every release. The final approach copies the whole source tree, including .git, into the store with copyPathToStore and runs `git rev-parse --short HEAD` inside a runCommand. It then reads the output with builtins.readFile, strips the trailing newline and prefixes a digit to satisfy Nix's version-format rule. The write-up walks through the failures along the way (sandboxed builds can't see the host repo, fetchGit drops .git, runCommand outputs a file) and closes with lessons on Nix laziness, purity and attribute sets.

  • Faster Nix Repl Startup

    Replit mediumAdept

    Replit removed the multi-second (sometimes tens of seconds) "Loading Nix environment" delay on repl startup by caching the environment variables exported by nix-shell after evaluating replit.nix. Because each repl gets a seeded Nix store containing most of nixpkgs, evaluation rarely adds new store paths, so the cached PATH and other variables can be persisted to the repl's filesystem and reused across restarts. The cache is invalidated whenever a cached variable references a Nix store path that no longer exists, falling back to full evaluation so correctness is preserved.

  • How we went from supporting 50 languages to all of them

    Replit easyNovice

    Replit replaced its ever-growing monolithic Docker OS image with Nix, giving every repl access to over 30,000 OS packages through a declarative `replit.nix` file. The packages are prebuilt into a roughly 1 TB shared Nix store disk image that is mounted at `/nix` in every repl, so nothing needs to be downloaded. Nix's content-addressed store lets many versions coexist without conflicts, and each environment exposes only the packages it declares. Planned work includes `.replit` configuration for things like LSP and caching nix-shell environments to remove rebuild delay on run, which an edit notes has since shipped.

  • Build Apps in Deno with Frameworks such as React, Vue, Express, and more.

    Deno mediumAdept

    Deno 1.28's npm support lets you use npm-distributed frameworks like Express, React and Vue directly via `npm:` specifiers. You don't need package.json, node_modules or a separate install step, and Deno's built-in toolchain is available throughout. Step-by-step examples build a dinosaur API with Express. They then build the same dinosaur list/detail app in React (Vite scaffold via create-vite-extra, an Oak backend with CORS, react-router-dom) and in Vue (reactive store, Suspense, vue-router).

  • Working with ChatGPT Functions on Heroku

    Heroku Engineering mediumAdept

    Menu Maker is a Node.js reference app with a React front end and Express back end that turns a user's ingredient list into a fine-dining dish description, ingredient list and recipe using OpenAI's Chat Completions API. Function calling with a JSON-schema `updateDish` definition makes the model return structured arguments, so the front end can parse the response and pass it straight into React state instead of handling free-form prose. The walkthrough covers the prompt and function settings, the POST endpoint, testing with curl, and deploying to Heroku from GitHub with config vars. Development API costs were under $1, and an Eco dyno is enough for hosting.

The quest for software engineering knowledge.

Look:
Layout: