Home Explore Blog Models CI



nix

1st chunk of `src/nix/develop.md`
5899c1afb301c0ac64d2c95ca973fd5278c1cb5214c790e10000000100000a64
R""(

# Examples

* Start a shell with the build environment of the default package of
  the flake in the current directory:

  ```console
  # nix develop
  ```

  Typical commands to run inside this shell are:

  ```console
  # configurePhase
  # buildPhase
  # installPhase
  ```

  Alternatively, you can run whatever build tools your project uses
  directly, e.g. for a typical Unix project:

  ```console
  # ./configure --prefix=$out
  # make
  # make install
  ```

* Run a particular build phase directly:

  ```console
  # nix develop --unpack
  # nix develop --configure
  # nix develop --build
  # nix develop --check
  # nix develop --install
  # nix develop --installcheck
  ```

* Start a shell with the build environment of GNU Hello:

  ```console
  # nix develop nixpkgs#hello
  ```

* Record a build environment in a profile:

  ```console
  # nix develop --profile /tmp/my-build-env nixpkgs#hello
  ```

* Use a build environment previously recorded in a profile:

  ```console
  # nix develop /tmp/my-build-env
  ```

* Replace all occurrences of the store path corresponding to
  `glibc.dev` with a writable directory:

  ```console
  # nix develop --redirect nixpkgs#glibc.dev ~/my-glibc/outputs/dev
  ```

  Note that this is useful if you're running a `nix develop` shell for
  `nixpkgs#glibc` in `~/my-glibc` and want to compile another package
  against it.

* Run a series of script commands:

  ```console
  # nix develop --command bash -c "mkdir build && cmake .. && make"
  ```

# Description

`nix develop` starts a `bash` shell that provides an interactive build
environment nearly identical to what Nix would use to build
[*installable*](./nix.md#installables). Inside this shell, environment variables and shell
functions are set up so that you can interactively and incrementally
build your package.

Nix determines the build environment by building a modified version of
the derivation *installable* that just records the environment
initialised by `stdenv` and exits. This build environment can be
recorded into a profile using `--profile`.

The prompt used by the `bash` shell can be customised by setting the
`bash-prompt`, `bash-prompt-prefix`, and `bash-prompt-suffix` settings in
`nix.conf` or in the flake's `nixConfig` attribute.

# Flake output attributes

If no flake output attribute is given, `nix develop` tries the following
flake output attributes:

* `devShells.<system>.default`

* `packages.<system>.default`

If a flake output *name* is given, `nix develop` tries the following flake
output attributes:

* `devShells.<system>.<name>`

* `packages.<system>.<name>`

* `legacyPackages.<system>.<name>`

)""

Title: `nix develop` Command: Examples and Description
Summary
This document describes the `nix develop` command, which launches a `bash` shell providing an interactive build environment for packages, replicating what Nix uses internally. It sets up necessary environment variables and shell functions for interactive and incremental building. Examples demonstrate its use for starting default build environments, running specific build phases, specifying packages from `nixpkgs`, recording and using build environments with profiles, redirecting store paths for development, and executing custom shell commands. The prompt is customizable, and `nix develop` determines the build environment by checking specific flake output attributes like `devShells.<system>.default` or `packages.<system>.default`.