---
title: "Building a web app with Nix (Because why not?)"
description: "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."
url: "https://swe.quest/articles/building-a-web-app-with-nix-because-why-not-53b9f7ab22ec7d0e"
canonical: "https://replit.com/blog/nix_web_app"
source: "Replit"
published: "2021-07-16"
difficulty: "medium"
kind: "How-to"
reading_minutes: 16
tags: ["functional-programming","build-systems","python"]
---

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

A post on [Replit](https://swe.quest/sources/replit.md), published 2021-07-16, 16 min read, How-to. Original: [https://replit.com/blog/nix\_web\_app](https://replit.com/blog/nix_web_app)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Functional programming](https://swe.quest/tags/functional-programming.md) (Languages)
- [Build systems](https://swe.quest/tags/build-systems.md) (Engineering practices)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- Nix package manager basics
- Python http.server ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))
- HTTP request methods

## Keywords

Nix, nix eval, runCommand, Replit, Replit Database, nixpkgs

## Related posts

- [Dynamic version for Nix derivations](https://swe.quest/articles/dynamic-version-for-nix-derivations-ecd33aca5a26fee8.md): Replit · 2021-06-25 · Medium · 8 min read · Build systems, CI/CD, Functional programming
  Replit derives a Nix derivation's version automatically from the git short SHA instead of editing default.nix by hand for every release.
- [Faster Nix Repl Startup](https://swe.quest/articles/faster-nix-repl-startup-b982aebd762e09bf.md): Replit · 2021-10-13 · Medium · 3 min read · Caching, Performance engineering, Developer tools
  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.
- [How we went from supporting 50 languages to all of them](https://swe.quest/articles/how-we-went-from-supporting-50-languages-to-all-of-them-937edb0cd8b8b0b8.md): Replit · 2021-05-24 · Easy · 3 min read · Build systems, Containers, Developer tools
  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.
- [Build Apps in Deno with Frameworks such as React, Vue, Express, and more.](https://swe.quest/articles/build-apps-in-deno-with-frameworks-such-as-react-vue-express-and-more-c17610b126d7b402.md): Deno · 2022-11-16 · Medium · 11 min read · JavaScript, Frontend, React, TypeScript
  Deno 1.28's npm support lets you use npm-distributed frameworks like Express, React and Vue directly via \`npm:\` specifiers.
- [Working with ChatGPT Functions on Heroku](https://swe.quest/articles/working-with-chatgpt-functions-on-heroku-40f46570b8427314.md): Heroku Engineering · 2024-01-30 · Medium · 11 min read · LLMs, JavaScript, React, Cloud platforms
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
