|
| 1 | +# Nix Environment |
| 2 | + |
| 3 | +This repository provides a reproducible development environment using [Nix](https://nixos.org/), with [direnv](https://direnv.net/) for automatic activation and [devenv](https://devenv.sh/) as a convenience layer on top. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- [Nix](https://nixos.org/download.html) with flakes enabled |
| 8 | +- [direnv](https://direnv.net/docs/installation.html) (and its shell hook installed) |
| 9 | +- Optionally, [devenv](https://devenv.sh/getting-started/) for the extras described below |
| 10 | + |
| 11 | +## What the flake provides |
| 12 | + |
| 13 | +The base environment is defined in `flake.nix` at the repository root. Entering the shell (`nix develop`, or automatically via direnv) gives you: |
| 14 | + |
| 15 | +- `nodejs_24` and `pnpm_10` pinned from nixpkgs, so every contributor uses the same toolchain versions |
| 16 | +- `git`, plus `nixpkgs-fmt` and `nil` for editing Nix files themselves |
| 17 | +- Playwright browsers wired up automatically: `PLAYWRIGHT_BROWSERS_PATH` points at the nix-provided browser set and `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` is set, so e2e tests run without downloading browsers |
| 18 | +- A `packages/playwright-browsers` output you can build or reference directly if you need the browser bundle standalone |
| 19 | +- A formatter available as `nix fmt` (runs `nixpkgs-fmt` over the Nix files) |
| 20 | + |
| 21 | +## What devenv adds on top |
| 22 | + |
| 23 | +`devenv.nix` layers convenience on top of the base shell: |
| 24 | + |
| 25 | +- **Cachix** (`ping-javascript-sdk`): artifacts are pulled from the binary cache so first installs are much faster, and pushed back so what you build is shared with the rest of the team |
| 26 | +- **`env.NX_SOCKET_DIR = "/tmp/nx"`**: fixes a macOS issue where the Nx daemon's Unix socket path exceeds the socket length limit because pnpm's deeply nested `node_modules` paths make the socket file path too long. Setting this redirects the socket to a short path. |
| 27 | + |
| 28 | +## How they compose |
| 29 | + |
| 30 | +The `.envrc` at the root wires everything together: |
| 31 | + |
| 32 | +```bash |
| 33 | +use flake |
| 34 | +eval "$(devenv direnvrc)" |
| 35 | +use devenv |
| 36 | +``` |
| 37 | + |
| 38 | +`use flake` provides the base environment from nixpkgs (the flake); `use devenv` layers devenv's project services, env vars, and caching on top. In short: **flake = the base toolchain and environment; devenv = the convenience layer**. You need both files for the full experience, but the flake alone is enough if you only want the toolchain. |
| 39 | + |
| 40 | +Once direnv is hooked into your shell, `cd`-ing into the repository activates everything automatically. |
| 41 | + |
| 42 | +## Troubleshooting |
| 43 | + |
| 44 | +### Nx socket errors on macOS |
| 45 | + |
| 46 | +If you see errors about the Nx daemon failing to bind a Unix socket (path too long), the `NX_SOCKET_DIR` env var from `devenv.nix` fixes this. If you skipped devenv, set it manually: |
| 47 | + |
| 48 | +```bash |
| 49 | +export NX_SOCKET_DIR=/tmp/nx |
| 50 | +``` |
| 51 | + |
| 52 | +## Note on `.devenv/` |
| 53 | + |
| 54 | +The `.devenv/` directory is generated runtime state, gitignored, and recreated automatically the next time the environment is activated. Never commit it or edit files inside it. |
0 commit comments