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 [path] [--command cmd] [--arg name value] [--argstr name value] [--expr expression] [--ignore-environment] [--keep variable] [--unset variable] [--shell path] [--impure] [--override-input input-name path] [--inputs-from flake-ref] [--no-build] [--show-trace] [--verbose]

PARAMETERS

path
    The path to a Nix expression or flake (e.g., '.' for current directory's flake or 'shell.nix').

--command cmd
    Instead of dropping into an interactive shell, execute cmd within the development environment and then exit.

--arg name value
    Pass an argument named name with Nix value value to the Nix expression.

--argstr name value
    Pass a string argument named name with string value value to the Nix expression.

--expr expression
    Evaluate the given Nix expression instead of reading from a file.

--ignore-environment
    Start with a clean environment, ignoring inherited variables from the outside shell.

--keep variable
    Keep the specified environment variable from the outside environment.

--unset variable
    Unset the specified environment variable within the development shell.

--shell path
    Use an alternative shell executable (e.g., 'bash' or 'zsh') for the development environment.

--impure
    Allow the environment to be impure (e.g., inherit PATH). Generally discouraged for reproducibility.

--override-input input-name path
    Override a flake input with a different path or URI.

--inputs-from flake-ref
    Take flake inputs from another flake reference.

--no-build
    Don't build the development environment, just show what would be built.

--show-trace
    Show build traces on error, which can be helpful for debugging Nix expressions.

--verbose
    Increase verbosity of output, showing more details about the build process.

DESCRIPTION

nix-develop is a powerful command within the Nix ecosystem, designed to create and enter reproducible development environments. It leverages Nix expressions, typically defined in a flake.nix file (for flake-based projects) or a shell.nix file (for legacy projects), to specify all necessary dependencies, tools, and environment variables required for a particular project.

When executed, nix-develop builds or fetches these components and then drops the user into a new shell where all the specified packages are available in the PATH and other relevant environment variables are set. This ensures that every developer working on a project operates within an identical environment, eliminating "it works on my machine" issues and streamlining onboarding for new team members. It's the modern, declarative approach to managing project-specific development setups, offering significant advantages over traditional imperative methods.

CAVEATS

Requires Nix installation and understanding of Nix expressions (especially flake.nix or shell.nix).
Flakes are still considered experimental and may require enabling extra-experimental-features = nix-command flakes in your Nix configuration file (nix.conf).
Initial entry can be slow if dependencies need to be built or fetched from binary caches for the first time.

FLAKE INTEGRATION

nix develop is designed to work seamlessly with Nix flakes. By default, it looks for a flake.nix file in the current directory or specified path and uses the devShells attribute within it to define the environment. This provides a standardized, declarative way to declare development dependencies and tools.

REPRODUCIBILITY

One of its core benefits is ensuring that everyone working on a project uses the exact same set of dependencies and tools, thanks to Nix's content-addressable store and flake lock files. This eliminates environment-related discrepancies and enhances collaboration.

TYPICAL USE CASES

Ideal for setting up language-specific toolchains (e.g., Python, Node.js, Rust, Go), database clients, compilers, static analysis tools, and any other project-specific software needed for development without polluting the system's global environment.

HISTORY

nix-develop emerged as part of the Nix "flakes" initiative, aiming to provide a more standardized, discoverable, and hermetic way to define and manage Nix projects. It is essentially the flake-aware successor to the older nix-shell command. While nix-shell was widely used for setting up development environments, nix-develop (as part of the new nix command interface) introduces clearer input management and better integration with the flake ecosystem, which provides reproducible inputs and outputs. It represents a significant step towards making Nix more accessible and robust for modern development workflows.

SEE ALSO

nix-shell(1), nix-build(1), nix-run(1), nix(1)

Copied to clipboard