Skip to content

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

Replit 8 min read How-to mediumAdept

Dynamic version for Nix derivations

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.

Assumes: Nix derivations basicsgit commit SHAs

Related posts

  • 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.

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

    Replit mediumAdept

    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.

  • 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.

  • Why We’re Moving on From Nix

    Railway mediumAdept

    Railway replaced its Nix-based builder Nixpacks with Railpack, a Go rewrite that generates BuildKit LLB graphs directly instead of linear Dockerfiles. Nix's commit-pinned versioning made patch-level versions hard to support and turned default bumps into surprise build failures. A single /nix/store layer bloated images, and an injected deployment ID env var invalidated caches. Railpack uses Mise for exact version resolution, locks dependencies from successful builds, and runs an analyze → JSON plan → BuildKit graph pipeline. It also hashes only the env vars each step uses so layers cache correctly, and uses BuildKit secrets, cutting base image sizes by 38% (Node) to 77% (Python).

  • DotSlash: Simplified executable deployment

    Meta Engineering mediumAdept

    DotSlash, now open source and written in Rust, replaces platform-specific executables in source control with a small text file (shebang `#!/usr/bin/env dotslash` plus a lenient-JSON manifest) listing per-platform size, hash, format and providers. On execution it hashes the platform entry to a cache key, tries to exec the cached binary, and on ENOENT fetches, verifies (BLAKE3/SHA-256), decompresses and atomically moves the artifact into the cache, using advisory locks to dedupe concurrent fetches. Multiple DotSlash files can share one archive (e.g. node/npm/npx), and at Meta CI automatically builds, publishes and commits DotSlash files with provenance metadata; a GitHub Action and GitHub-releases provider bring the same workflow outside Meta.

The quest for software engineering knowledge.

Look:
Layout: