Home Explore Blog Models CI



nixpkgs

doc/build-helpers/special/mkshell.section.md
08b385c3a6a34b34434942dc5bcecd15150b8be25cc6abd90000000300000595
# pkgs.mkShell {#sec-pkgs-mkShell}

`pkgs.mkShell` is a specialized `stdenv.mkDerivation` that removes some
repetition when using it with `nix-shell` (or `nix develop`).

## Usage {#sec-pkgs-mkShell-usage}

Here is a common usage example:

```nix
{
  pkgs ? import <nixpkgs> { },
}:
pkgs.mkShell {
  packages = [ pkgs.gnumake ];

  inputsFrom = [
    pkgs.hello
    pkgs.gnutar
  ];

  shellHook = ''
    export DEBUG=1
  '';
}
```

## Attributes {#sec-pkgs-mkShell-attributes}

* `name` (default: `nix-shell`). Set the name of the derivation.
* `packages` (default: `[]`). Add executable packages to the `nix-shell` environment.
* `inputsFrom` (default: `[]`). Add build dependencies of the listed derivations to the `nix-shell` environment.
* `shellHook` (default: `""`). Bash statements that are executed by `nix-shell`.

... all the attributes of `stdenv.mkDerivation`.

## Variants {#sec-pkgs-mkShell-variants}

`pkgs.mkShellNoCC` is a variant that uses `stdenvNoCC` instead of `stdenv` as base environment. This is useful if no C compiler is needed in the shell environment.

## Building the shell {#sec-pkgs-mkShell-building}

This derivation output will contain a text file that contains a reference to
all the build inputs. This is useful in CI where we want to make sure that
every derivation, and its dependencies, build properly. Or when creating a GC
root so that the build dependencies don't get garbage-collected.

Chunks
db60a440 (1st chunk of `doc/build-helpers/special/mkshell.section.md`)
Title: Nix: `pkgs.mkShell` for Development Environments
Summary
`pkgs.mkShell` is a specialized `stdenv.mkDerivation` designed to simplify setting up development environments with `nix-shell` or `nix develop`. It allows users to specify executable packages, add build dependencies from other derivations using `inputsFrom`, and execute custom Bash statements via `shellHook`. A variant, `pkgs.mkShellNoCC`, provides an environment without a C compiler. The derivation's output helps ensure all dependencies build correctly and can be used to create GC roots, preventing garbage collection of build dependencies.