29 November 2026 · NixOSaaS
One Laptop, Multiple Projects: Reproducible Development with Nix and devenv.sh
A beginner-friendly guide to separate Python and Node.js development environments on one laptop using Nix and devenv.sh.
Managing multiple projects with different language versions and dependencies can become complicated. Nix enables reproducible, project-specific environments on the same machine, while devenv.sh makes those environments easier to configure and use.
You open an older application to fix a bug. It needs Python 3.11. Your new application uses Python 3.12. Meanwhile, two JavaScript projects need different Node.js versions.
Installing a newer runtime globally can change what happens when you type python or node. A project that worked yesterday may now run with tools it was never tested against.
You can solve this with virtual environments, version managers and containers. Nix offers another approach: describe the tools a project needs in a file, then enter an environment that provides them. devenv makes that approach more convenient for everyday development.
New to the tool? Start with What Is devenv.sh? A Beginner’s Guide to Development Environments, then return here for the multi-project exercises.
Let’s make that concrete, starting with what the words mean.
Three things that are easy to confuse
| Term | Meaning | Example |
|---|---|---|
| Runtime or compiler | Software that executes or builds your code | Python, Node.js, Go |
| Application dependency | A library your code imports | Python’s requests package |
| Development environment | Tools, libraries and settings used while working on a project | Python plus libraries, Git and environment variables |
A Python virtual environment separates installed Python libraries, but does not by itself provision every interpreter, compiler or system library a project needs. Likewise, a JavaScript project’s node_modules directory does not choose which Node.js executable your terminal runs.
This is where declaring the wider environment becomes useful.
How Nix, NixOS and devenv fit together
Nix stores packages under distinct paths in /nix/store. Different versions can coexist because they do not overwrite the same installation directory. Identical package builds can also be shared between projects. [1]
A development shell selects tools for the commands you run inside it. For example, one terminal can select Python 3.11 while another selects Python 3.12. Nix provides development shells directly through tools such as nix-shell and nix develop. [2]
NixOS is a Linux distribution built around Nix. You do not have to install NixOS to use this approach: Nix and devenv also work on supported Linux and macOS systems. Windows users can follow the Linux route inside WSL2. [3]
devenv.sh is the project’s website; devenv is the command you run. It adds convenient configuration for languages, tasks, services and processes on top of Nix.
For a small environment, a plain Nix shell may be enough. For a project with several tools and development services, devenv can reduce the configuration you need to maintain.
Before you start
Use a terminal with Bash or Zsh and a text editor. Install Nix and devenv using the official getting-started guide for your operating system. NixOS already includes Nix.
If you are installing Nix for the first time, our earlier walkthroughs cover setup and a complete Go exercise on Debian, Ubuntu and Fedora and macOS. You can follow their installation sections, then return here to add devenv.
With Nix installed, the guide provides this user-level installation route for devenv:
nix-env --install --attr devenv -f https://github.com/NixOS/nixpkgs/tarball/nixpkgs-unstable
On NixOS, you can instead add pkgs.devenv to your existing environment.systemPackages list and apply your normal system rebuild. Choose one installation method. [3]
Check both commands before continuing:
nix --version
devenv --version
Create a parent directory for these exercises:
mkdir -p ~/devenv-labs
cd ~/devenv-labs
The examples below are original teaching examples checked against the documented configuration options. They have not been executed end to end for this article. Package availability depends on the Nixpkgs revision selected by your environment; the versions shown are examples, not recommendations for every production application.
Prefer a stable release instead of unstable?
Yes. You can select a stable Nixpkgs release, such as 26.05, instead of the rolling nixpkgs-unstable source. There are two separate choices: where you install the devenv command from, and where each project gets its packages.
To install devenv from that stable release, use this instead of the earlier installation command:
nix-env --install --attr devenv -f https://github.com/NixOS/nixpkgs/tarball/nixos-26.05
For project packages, after running devenv init, edit the existing inputs.nixpkgs.url entry in devenv.yaml to look like this. Preserve any other settings in the file:
inputs:
nixpkgs:
url: github:NixOS/nixpkgs/nixos-26.05
Then, from the project directory and outside an existing development shell, resolve the new inputs and enter the environment:
devenv update
devenv shell
devenv update can update other declared inputs too; review and commit the resulting devenv.lock. See the input configuration documentation.
Installing devenv from stable does not automatically change a project’s package source. Likewise, choosing stable project packages does not change your host operating system.
Stable releases generally favour fewer version changes over the newest features. They may contain an older devenv version or lack particular package versions used in a tutorial. Choose a supported release, check package availability, and test the configuration with its devenv version. A stable branch still receives updates; the lock file records the exact revision used by your project.
Example 1: two Python projects, two interpreters and separate libraries
We will create this arrangement:
| Folder | Interpreter | Extra Python library |
|---|---|---|
python-report | Python 3.11 | requests |
python-tools | Python 3.12 | None |
First, initialise the report project:
mkdir -p ~/devenv-labs/python-report
cd ~/devenv-labs/python-report
devenv init
Initialisation creates starter configuration files. Open the generated devenv.nix in your editor and replace its contents with:
{ pkgs, ... }:
{
# Provide Python 3.11 together with its requests library.
packages = [
(pkgs.python311.withPackages (ps: [ ps.requests ]))
];
# A label we can read from our program.
env.PROJECT_NAME = "Python report";
}
Read this slowly:
pkgsis the package collection supplied to the configuration.packages = [ ... ];lists tools to make available in the shell.python311selects the Python 3.11 package.withPackagescreates a Python environment with the listed libraries.ps.requestsselectsrequestsfrom that interpreter’s package collection.env.PROJECT_NAMEcreates an environment variable for this project.
Braces group settings, square brackets contain a list, and assignments end with a semicolon. You do not need to master the Nix language to begin using this pattern. For a slower explanation of values, attribute sets and functions, see our Introduction to the Nix programming language. It explains the syntax behind configurations like this one.
We use Nix-managed Python libraries here so that the dependency declaration is visible in one file. Do not add a second Python interpreter through another configuration option in this same example.
Create a file called app.py beside devenv.nix:
import os
import sys
import requests
print("Project:", os.environ["PROJECT_NAME"])
print("Python:", sys.version.split()[0])
print("Executable:", sys.executable)
print("requests:", requests.__version__)
Enter the environment and run it:
devenv shell
python app.py
The first entry may download packages or build missing ones. The program should print Python report, a Python version beginning with 3.11, the executable path, and the installed requests version. Exact patch versions depend on the locked inputs.
This program makes no network request: importing requests is enough to prove the library is available.
Leave the shell before creating the second project:
exit
mkdir -p ~/devenv-labs/python-tools
cd ~/devenv-labs/python-tools
devenv init
Replace this project’s devenv.nix with:
{ pkgs, ... }:
{
packages = [ pkgs.python312 ];
env.PROJECT_NAME = "Python tools";
}
Create its own app.py:
import importlib.util
import os
import sys
print("Project:", os.environ["PROJECT_NAME"])
print("Python:", sys.version.split()[0])
print("Executable:", sys.executable)
print("requests available:", importlib.util.find_spec("requests") is not None)
Run it:
devenv shell
python app.py
You should see Python 3.12.x and requests available: False, assuming you have not introduced external Python packages through settings such as PYTHONPATH.
The first project’s library has not been added to the second project’s declared Python environment. Its interpreter has not been replaced either.
For the clearest demonstration, leave this shell with exit, then open two fresh terminal tabs. In one, enter the report project’s directory and run devenv shell. In the other, do the same for the tools project. Run python app.py in both. The two environments can remain active simultaneously.
For larger Python projects, devenv also integrates with virtual environments and tools such as uv and Poetry. Those workflows still need their application dependency declarations and locks; selecting Python alone does not lock all imported libraries. [4]
Example 2: two Node.js versions running the same program
Now we will show that changing project environments does not require changing application code.
In a fresh terminal:
mkdir -p ~/devenv-labs/node22-app
cd ~/devenv-labs/node22-app
devenv init
Replace devenv.nix with:
{ pkgs, ... }:
{
languages.javascript.enable = true;
languages.javascript.package = pkgs.nodejs_22;
env.PROJECT_NAME = "Node 22 application";
}
Here, enable switches on JavaScript tooling, while package selects the Node.js runtime. These are documented devenv language options. [5]
Create app.js:
console.log("Project:", process.env.PROJECT_NAME);
console.log("Node.js:", process.version);
console.log("Executable:", process.execPath);
console.log("Calculation:", 6 * 7);
Enter and run:
devenv shell
node app.js
Expect a version beginning with v22. and a calculation result of 42.
Leave the environment and create another project:
exit
mkdir -p ~/devenv-labs/node24-app
cd ~/devenv-labs/node24-app
devenv init
cp ../node22-app/app.js ./app.js
Replace the new devenv.nix with:
{ pkgs, ... }:
{
languages.javascript.enable = true;
languages.javascript.package = pkgs.nodejs_24;
env.PROJECT_NAME = "Node 24 application";
}
Run the same program:
devenv shell
node app.js
This time, expect v24.. The calculation still produces 42. Each project selects its own runtime without a global Node.js version switch.
This example deliberately uses only built-in JavaScript features. In a real npm project, retain package.json and package-lock.json, and use npm ci to install its locked dependencies. The Nix input lock and the npm dependency lock serve different purposes.
What about Go?
The same approach applies to Go. In a separate initialised project, a minimal configuration is:
{ pkgs, ... }:
{
languages.go.enable = true;
languages.go.package = pkgs.go;
}
pkgs.go selects the default Go package from the locked package collection. It does not express a particular Go release line. To require one, choose an available versioned package from that collection. Keep go.mod and go.sum with your application, and account for Go’s own automatic toolchain selection when enforcing an exact compiler version. [8]
What makes an environment reproducible?
A configuration says what you want; a lock records the resolved inputs used to provide it.
| File | Purpose |
|---|---|
devenv.nix | Project tools, settings and behaviour |
devenv.yaml | Input sources and related configuration |
devenv.lock | Resolved revisions of Nix inputs |
| Application lock files | Dependencies managed by npm, uv or another language tool |
Keep the generated devenv.lock alongside the configuration in version control. Without a shared lock, two developers initialising the same configuration at different times may resolve different inputs. [6]
For the Python example, the locked Nixpkgs input also fixes which Nix-packaged requests is selected. If you instead install libraries with pip or uv, manage and lock those dependencies separately.
Do not commit generated caches, local virtual environments or secrets. Retain the generated .gitignore and review it for your project.
Reproducibility still has practical limits: operating systems and CPU architectures differ, packages must support the target system, and application data or external APIs are not frozen by a development environment lock.
What entering and leaving actually does
devenv shell starts a shell with the project’s tools and settings. exit leaves that shell. Downloaded packages remain available for reuse; exiting does not uninstall them. [7]
Simply typing cd into another folder inside an existing shell does not activate that folder’s devenv configuration. For these exercises, leave the current shell first, then enter the next project. Automatic activation can be added later with direnv.
A normal development shell is not a security boundary. It still uses your host’s kernel, filesystem permissions and network. Host environment variables or executable paths may affect commands. Two development servers can also collide if they bind the same port. Containers or VMs remain useful when you need stronger separation.
If something looks wrong
| Symptom | First check |
|---|---|
devenv: command not found | Confirm installation, then open a fresh terminal. |
| Unexpected Python or Node.js version | Check the project directory and enter its shell; inspect command -v python or command -v node. |
requests appears in the second Python project | Start from a fresh terminal and inspect inherited virtual environments or PYTHONPATH. |
| A package attribute is missing | Check whether that package exists in the project’s locked Nixpkgs revision. |
| First entry is slow | Initial downloads or source builds can take time; later entries can reuse them. |
| Editor uses another interpreter | Select the project’s interpreter in the editor; terminal activation alone may not configure it. |
Your environment becomes part of your project
The useful change is that a project’s setup becomes reviewable code. A colleague can inspect which interpreter you selected, recreate the declared tools and propose an upgrade through the same review process as an application change.
Start with two small projects. Run the version checks, inspect executable paths and keep the lock files. Once that behaviour is familiar, extend the environment with your application’s services and development tasks.
Where to go next
Once you can confidently switch between these environments, the next step is running a complete application with its supporting services. That deserves a separate hands-on tutorial: a Python API with PostgreSQL and Redis, automatic environment activation, development tasks, tests and live reload. Keeping that exercise separate lets us explain service readiness, persistent data and port conflicts without rushing past the basics covered here.
References
- Nix: how packages and multiple versions work
- Nix: declarative shell environments
- devenv: installation and getting started
- devenv: Python environments and integrations
- devenv: JavaScript and Node.js options
- devenv: pinning inputs
- devenv: shell basics
- devenv: Go options
Explore NixOS services and developer environment training at NixOSaaS.