Get started with Nix-based development on a new host
Set up a new Mac, Windows (WSL) or NixOS machine for Nix-based projects with flakes, direnv and VS Code, using Avunu's ready-made development configurations.
On this page
Use this page to get a new computer ready to work on any Avunu Nix project, such as frappe-nix, odoo-nix or wordpress-nix. Pick your platform, follow its steps top to bottom, then finish with the shared steps at the end.
How it works
Every platform follows the same five steps. Only the first two differ.
Install Nix with flakes enabled. We use Determinate Nix, which has flakes on by default.
Enable direnv, so a project's tools load automatically when you enter its folder.
Install the direnv extension in VS Code.
Clone the project.
Run
direnv allowin the project folder.
To save you the setup work on steps 1 and 2, Avunu publishes development configurations for each platform. They install Nix settings, direnv, and the common toolchain (Git, Node, Bun, Python, container tools) in one command.
| Platform | Configuration |
|---|---|
| macOS | nix-dev-macos |
| Windows | nixos-wsl (NixOS on WSL) |
| NixOS | nixos-dev-workstation |
macOS
Works on Apple Silicon and Intel Macs.
Apply the Avunu configuration by running the following in a terminal window. It installs direnv and the development toolchain.
sudo nix run nix-darwin/master#darwin-rebuild -- switch \ --flake github:Avunu/nix-dev-macos#default --refresh --impureIf activation stops because an existing
/etcfile is in the way, it prints a message naming the file. Move the file aside as the message says (for examplesudo mv /etc/zshrc /etc/zshrc.before-nix-darwin) and run the command again.Install VS Code if you don't have it.
Continue with Install the direnv extension.
The configuration keeps itself current. A daily job rebuilds the system when the repository changes, and you can run system-upgrade to update right away.
Windows
Windows development runs inside NixOS on WSL 2, and VS Code on Windows connects into it.
Install VS Code on Windows, then add the WSL extension (
ms-vscode-remote.remote-wsl).Install NixOS-WSL. Download
nixos.wslfrom the NixOS-WSL releases page, then run this in PowerShell from the download folder:wsl --install --from-file nixos.wslOpen the NixOS terminal.
wsl -d NixOSApply the Avunu configuration inside NixOS. It enables flakes, direnv with nix-direnv, and the VS Code server integration.
sudo nixos-rebuild switch --flake github:Avunu/nixos-wsl#nixos --refresh --impureClose the terminal and run
wsl --shutdownin PowerShell, then reopen NixOS so the new settings apply.Continue with Install the direnv extension. Do the VS Code steps from a window connected to WSL (run
code .from the NixOS terminal).
Important
Clone projects into the Linux home directory (~/), not under /mnt/c. Nix and file watchers are many times slower on the Windows filesystem.
Tip
If a rebuild fails and leaves NixOS unusable, run wsl -d NixOS --system --user root -- /mnt/wslg/distro/bin/nixos-wsl-recovery in PowerShell, then retry step 4.
The machine updates itself daily from the repository. Run system-upgrade to update sooner.
NixOS
Moving a machine to NixOS is optional and replaces the existing operating system. Use nixos-dev-workstation directly if you want a ready-made Avunu workstation, or as a reference for your own configuration.
Use it as a reference
On a machine that already runs NixOS, copy only what you need from the profile. The minimum for this workflow is direnv with nix-direnv:
{
programs.direnv = {
enable = true;
nix-direnv.enable = true;
};
}
Install the direnv extension
Do this once per VS Code installation. On Windows, do it in a window connected to WSL so the extension installs in WSL.
Open VS Code, press
Ctrl+Shift+X(Cmd+Shift+Xon macOS), and search for direnv.Install the extension by
mkhl(mkhl.direnv), or run this in a terminal:code --install-extension mkhl.direnv
Clone the project and allow direnv
Clone the project into a folder in your home directory.
git clone https://github.com/<OWNER>/<PROJECT>.git ~/Development/<PROJECT> cd ~/Development/<PROJECT>Allow direnv for the folder. This tells direnv you trust the project's
.envrc.direnv allowOpen the folder in VS Code.
code .
The first load downloads and builds the project's tools, which can take several minutes. After that it loads in seconds and happens automatically whenever you enter the folder. If Nix asks whether to trust a binary cache, answer yes for Avunu projects.
Note
Run direnv allow again whenever the project's .envrc changes. direnv blocks a changed file until you approve it.
Check that it works
From the project folder, confirm the environment loaded:
direnv status
nix --version
The status output should say the .envrc is allowed and loaded. If VS Code does not pick up the tools, run direnv: Restart from the Command Palette (Ctrl+Shift+P).
Troubleshooting
| Symptom | Fix |
|---|---|
direnv: command not found or nothing happens on cd |
Open a new terminal. If it persists, the configuration step did not finish; rerun it. |
direnv: error .envrc is blocked |
Run direnv allow in the project folder. |
| VS Code terminals have the tools but the editor and extensions do not | Install mkhl.direnv, then run direnv: Restart. On Windows, check it is installed in WSL. |
| Slow file access or builds on Windows | The project is under /mnt/c. Move it into ~/. |
experimental Nix feature 'flakes' is disabled |
Nix was not installed with Determinate Nix, or the configuration has not been applied yet. |
Sources
This article is in the public domain (CC0 1.0), code samples included. Use it however helps you.