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] [path]

PARAMETERS

--command
    Command to run in the development environment instead of opening a shell. The default is to open a shell.

--expr
    Nix expression to evaluate.

--impure
    Allow access to mutable state during evaluation (e.g., environment variables).

--ignore-environment
    Do not inherit environment variables from the parent shell.

--no-write-lock-file
    Do not write a lock file.

--profile
    Profile to use.

[path]
    Path to the directory containing the `flake.nix` or `default.nix` file (default: current directory).

DESCRIPTION

The `nix develop` command provides a convenient way to enter a development environment defined by a Nix expression. It automatically sets up the environment with the necessary dependencies and configurations, allowing developers to quickly start working on projects without manually managing dependencies. It reads the `flake.nix` or `default.nix` file in the current directory (or a specified path), evaluates it, and then creates a shell environment containing the specified development tools and libraries. This includes setting environment variables, modifying the PATH, and installing packages. The primary benefit is reproducibility; every developer entering the environment will have the same tooling available.

`nix develop` allows for isolation of project dependencies and prevents conflicts between different projects on the same system. It streamlines the development workflow and eliminates common setup hurdles related to package management and version conflicts.

CAVEATS

The Nix expression used by `nix develop` should define a `devShell` attribute. If you are using flakes, ensure that flakes are enabled.

FLAKES INTEGRATION

`nix develop` integrates seamlessly with Nix Flakes. When used within a directory containing a `flake.nix` file, it automatically uses the flake's `devShell` attribute. This ensures a consistent and reproducible development environment based on the flake's defined dependencies.

ENVIRONMENT VARIABLES

The environment variables set by `nix develop` are defined in the Nix expression. You can access these variables within the development shell using standard shell syntax (e.g., `$VAR_NAME`). Use `--ignore-environment` to avoid inheritance of variables that may interfere with nix configuration.

HISTORY

The `nix develop` command was introduced as part of the Nix Flakes feature to provide a more structured and reproducible approach to development environments. It replaced older methods like `nix-shell` and `shell.nix` in many workflows, offering better integration with Nix's declarative configuration management.

SEE ALSO

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

Copied to clipboard