LinuxCommandLibrary

nix-develop

Enter a development environment defined by Nix

TLDR

Start a shell with all dependencies of a package from nixpkgs available

$ nix develop [nixpkgs#pkg]
copy

Start a development shell for the default package in a flake in the current directory
$ nix develop
copy

In that shell, configure and build the sources
$ configurePhase; buildPhase
copy

SYNOPSIS

nix develop [options] [flake-ref[#output]]...

PARAMETERS

-c, --command [...]
    Run the command in the environment instead of an interactive shell

--impure
    Allow access to non-Nix store paths and impure evaluation

--rebuild
    Force rebuild of the shell even if unchanged

--refresh
    Update flake inputs to latest versions before building

--no-write-lock-file
    Skip writing flake.lock for the flake

--override-input
    Override a flake input with another flake reference

--ignore-environment
    Clear all environment variables before sourcing

DESCRIPTION

nix develop evaluates a Nix flake's devShell (or specified output) and spawns an interactive shell with the exact build environment, including dependencies, tools, and variables. Flakes ensure reproducibility via flake.lock, pinning inputs like nixpkgs versions.

It builds the shell derivation on-demand, caching results in the Nix store. Multiple flakes can be specified, merging environments (last overrides first). Ideal for project-specific setups without global installs.

Unlike nix-shell (legacy shell.nix), it leverages flake structure for composability, input overrides, and pure evaluation. Exit the shell to leave the environment; re-enter rebuilds only if inputs change.

CAVEATS

Requires Nix ≥2.4 with flakes and nix-command features enabled (e.g., export NIX_CONFIG=experimental-features=nix-command flakes). Flakes are pure by default; impurities need --impure. Not for non-flake projects.

COMMON USAGE

nix develop (local flake default devShell)
nix develop .#myShell (specific output)
nix develop github:owner/repo (remote flake)

DEFAULT OUTPUT

Uses flake's devShells.default or top-level devShell if no #output specified.

HISTORY

Introduced in Nix 2.4 (2021) with experimental flakes/nix-command. Replaced nix-shell for flake workflows. Stabilized in Nix 2.8+; default in many distros like NixOS unstable by 2023.

SEE ALSO

nix-shell(1), nix(1), nix flake(1)

Copied to clipboard