# mkShell vs. buildEnv?

**URL:** https://discourse.nixos.org/t/mkshell-vs-buildenv/681
**Category:** Help
**Created:** [August 16, 2018, 7:43pm UTC](https://discourse.nixos.org/t/mkshell-vs-buildenv/681 "2018-08-16T19:43:54Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![akavel](https://discourse.nixos.org/user_avatar/discourse.nixos.org/akavel/32/270_2.png) [@akavel](https://discourse.nixos.org/u/akavel)
#### Post date: [August 16, 2018, 7:43pm UTC](https://discourse.nixos.org/t/mkshell-vs-buildenv/681/1 "2018-08-16T19:43:54Z")

</div>

I’ve seen examples of _nix-shell_ environments, sometimes based on `buildEnv`, sometimes on `mkShell`; are there some important differences? Which one should I use and why?

---

<div class="post-metadata">

### Author: ![manveru](https://discourse.nixos.org/user_avatar/discourse.nixos.org/manveru/32/23_2.png) [@manveru](https://discourse.nixos.org/u/manveru)
#### Post date: [August 17, 2018, 8:23am UTC](https://discourse.nixos.org/t/mkshell-vs-buildenv/681/2 "2018-08-17T08:23:58Z")

</div>

Let’s first take a look at `buildEnv`:

> <https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/buildenv/default.nix>

This is basically a wrapper around the `builder.pl`, and simply provides you with a bunch of symlinks. I’m not sure why you’d use it for a `nix-shell`, but it seems like some people like to put all their `buildInputs` through `buildEnv` to get a reference to all their dependencies within a single directory.

# mkShell

> <https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/mkshell/default.nix>

This one is super simple compared to `buildEnv` and the one I use every day, all it does is provide some defaults for a `stdenv.mkDerivation`. So you don’t need to give it a `src` or `name`, all you really need is `buildInputs`, maybe a `shellHook` that runs when you enter the `nix-shell`, and any env variables you want.

---

<div class="post-metadata">

### Author: ![toraritte](https://discourse.nixos.org/user_avatar/discourse.nixos.org/toraritte/32/6777_2.png) [@toraritte](https://discourse.nixos.org/u/toraritte)
#### Post date: [July 15, 2019, 4:00pm UTC](https://discourse.nixos.org/t/mkshell-vs-buildenv/681/3 "2019-07-15T16:00:58Z")

</div>

See also [Nixpkgs issue 58624, " mkShell needs more documentation in the manual"](https://github.com/NixOS/nixpkgs/issues/58624) for more info.

---

<div class="post-metadata">

### Author: ![ilneit](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/i/b19c9b/32.png) [@ilneit](https://discourse.nixos.org/u/ilneit)
#### Post date: [February 12, 2025, 12:34pm UTC](https://discourse.nixos.org/t/mkshell-vs-buildenv/681/4 "2025-02-12T12:34:55Z")

</div>

The two resulting derivations are completely different. `buildEnv` evaluates to a directory that you can include e.g. via `nix profile install` while `mkShell[NoCC]` evaluates to a shell-script to be loaded. You can’t install it into your profile.

---

<div class="post-metadata">

### Author: ![ilneit](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/i/b19c9b/32.png) [@ilneit](https://discourse.nixos.org/u/ilneit)
#### Post date: [February 12, 2025, 2:05pm UTC](https://discourse.nixos.org/t/mkshell-vs-buildenv/681/5 "2025-02-12T14:05:33Z")

</div>

Side-note: This motivated [https://discourse.nixos.org/t/description-of-the-attribute-inputdrvs-in-the-nix-manual/60190](https://discourse.nixos.org/t/description-of-the-attribute-inputdrvs-in-the-nix-manual/60190).
