---
title: "Faster Nix Repl Startup"
description: "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."
url: "https://swe.quest/articles/faster-nix-repl-startup-b982aebd762e09bf"
canonical: "https://replit.com/blog/nix-perf-improvements"
source: "Replit"
published: "2021-10-13"
difficulty: "medium"
kind: "Case study"
reading_minutes: 3
tags: ["caching","performance","developer-tools"]
---

# Faster Nix Repl Startup

A post on [Replit](https://swe.quest/sources/replit.md), published 2021-10-13, 3 min read, Case study. Original: [https://replit.com/blog/nix-perf-improvements](https://replit.com/blog/nix-perf-improvements)

## Summary

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.

Written by swe.quest, not by the author.

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

## Topics

- [Caching](https://swe.quest/tags/caching.md) (Backend & APIs)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Developer tools](https://swe.quest/tags/developer-tools.md) (Engineering practices)

## Prerequisites

- Nix basics
- environment variables and PATH

## Keywords

Nix, nix-shell, nixpkgs, Replit, Polygott, replit.nix

## Related posts

- [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.
- [Building a web app with Nix (Because why not?)](https://swe.quest/articles/building-a-web-app-with-nix-because-why-not-53b9f7ab22ec7d0e.md): Replit · 2021-07-16 · Medium · 16 min read · Functional programming, Build systems, Python
  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.
- [Replit²](https://swe.quest/articles/replit2-f7f8a0a22edfb202.md): Replit · 2021-08-06 · Medium · 15 min read · JavaScript, Sandboxing & isolation, Load balancing, Python
  A Replit Nix repl can act as a code-execution backend: a Koa.js server spawns a Python child process and feeds user code through stdin, using code.InteractiveInterpreter, which avoids shell injection and keeps crashes from taking down the server.
- [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.
- [Introducing the Python package cache](https://swe.quest/articles/introducing-the-python-package-cache-d61a4cbacb3d2ae6.md): Replit · 2021-03-19 · Medium · 3 min read · Python, Caching, Build systems, Linux, Performance engineering
  Replit pre-populates pip's cache with the most popular Python packages and pre-built wheels so UPM can skip most downloads and compilation when a repl starts.

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)
