# When to use \`nix-env\` over configuration.nix (new to NixOS)

**URL:** https://discourse.nixos.org/t/when-to-use-nix-env-over-configuration-nix-new-to-nixos/33921
**Category:** Uncategorized
**Created:** [October 6, 2023, 10:12pm UTC](https://discourse.nixos.org/t/when-to-use-nix-env-over-configuration-nix-new-to-nixos/33921 "2023-10-06T22:12:38Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![testplayername](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@testplayername](https://discourse.nixos.org/u/testplayername)
#### Post date: [October 6, 2023, 11:57pm UTC](https://discourse.nixos.org/t/when-to-use-nix-env-over-configuration-nix-new-to-nixos/33921/4 "2023-10-06T23:57:20Z")

</div>

Check out [https://stop-using-nix-env.privatevoid.net/](https://stop-using-nix-env.privatevoid.net/) for some quick explanations on why `nix-env` should be avoided in (almost) all cases. Much more detailed discussion is in this [thread](https://discourse.nixos.org/t/depreciate-the-use-of-nix-env-to-install-packages/20139/34).

For your specific questions:

- On why `nix-env` exists in the first place:  
It is useful as a “low-level” plumbing command for other tools (e.g. Home Manager). These tools (should) have a high-level API that retains one of Nix’s main features: being able to define your NixOS configuration (among other things) in configuration files, written in a declarative language.
- Benefits of Nix:  
As stated in the first point, one of Nix’s primary strengths is its use of declarative configurations. In practice, for NixOS, this means (nearly) the entire operating system is defined in `/etc/nixos/configuration.nix` and whatever other files `configuration.nix` imports. This declarative approach has many benefits, which I assume you are already aware of since you’re already experimenting with NixOS. Using `nix-env` instead of modifying `/etc/nixos/configuration.nix` to permanently install things go completely against this idea. But see below for temporary installations…
- On long build times:  
When you add new packages to `/etc/nixos/configuration.nix` there is not much you can do to reduce the potentially long processing time. Subsequent `nixos-rebuild switch` commands that you run just to update already-installed packages should complete fairly quickly. If you want to install something temporarily, use [ephemeral shells](https://nix.dev/tutorials/first-steps/ad-hoc-shell-environments#ad-hoc-envs).

---

_[View the full topic](https://discourse.nixos.org/t/when-to-use-nix-env-over-configuration-nix-new-to-nixos/33921)._
