LinuxCommandLibrary

nix3-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 [--arg <name> <value>...] [--argstr <name> <value>...] [--command <cmd>] [--impure] [--json] [--log-format <format>] [--offline] [--refresh] [--show-trace] [--option <name> <value>...] [--extra-experimental-features <features>...] [<flake-url>] [#<attribute-path>]

PARAMETERS

--arg <name> <value>
    Pass the value <value> as an argument <name> to the Nix functions in the flake.

--argstr <name> <value>
    Pass the string <value> as an argument <name> to the Nix functions in the flake.

--command <cmd>
    Instead of dropping into a shell, execute <cmd> within the development environment.

--impure
    Allow the Nix evaluation to access the system’s environment variables.

--json
    Produce JSON output, useful for programmatic consumption.

--log-format <format>
    Set the format of log output (e.g., internal-json).

--offline
    Don't attempt to connect to the network.

--refresh
    Re-fetch the inputs of the flake.

--show-trace
    Show a stack trace in case of Nix evaluation errors.

--option <name> <value>
    Set a Nix configuration option for this command invocation.

--extra-experimental-features <features>
    Enable additional experimental Nix features (e.g., flakes nix-command).

<flake-url>
    The URL of the flake to use (e.g., . for current directory, github:NixOS/nixpkgs).

#<attribute-path>
    The specific attribute path within the flake to develop (e.g., #devShells.x86_64-linux.default or #devShell).

DESCRIPTION

nix develop is a Nix command used to set up and enter a self-contained development environment defined by a Nix flake.
Unlike traditional package managers that install tools globally, nix develop creates an isolated shell where all specified development dependencies (compilers, libraries, tools) are made available.
This ensures project reproducibility, prevents dependency conflicts, and allows multiple projects with different requirements to coexist without interference.
It typically looks for a flake.nix file in the current directory or a specified path, builds the devShell attribute from it, and then spawns a shell with the environment variables and paths configured by the flake.
This command is a core component of modern Nix workflows for software development.

CAVEATS

This command requires Nix 2.4 or newer with experimental features nix-command and flakes enabled.
The development environment created is ephemeral; changes made inside the shell are not persisted unless explicitly saved or managed by a Nix build process.
Performance can vary depending on the complexity of the flake and the efficiency of Nix's caching mechanisms.

FLAKES INTEGRATION

nix develop is fundamentally tied to Nix flakes. It looks for a flake.nix file to define the development environment, specifically utilizing the devShell attribute (or a specific attribute path within devShells) within the flake's outputs to specify dependencies and configurations.

ENVIRONMENT ISOLATION

A key feature of nix develop is its ability to create highly isolated development environments.
Tools and libraries are made available only within the spawned shell, preventing conflicts with global system installations and ensuring consistent development setups across different machines and users.

HISTORY

nix develop was introduced as part of the Nix 2.4 release, alongside the new nix commands and flakes experimental features.
It largely superseded nix-shell as the primary way to define and enter declarative development environments using the new flake structure.
Its development reflects Nix's ongoing evolution towards more ergonomic, reproducible, and standardized project definitions, particularly for software development.

SEE ALSO

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

Copied to clipboard