Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Modern Nix commands: search, shell, run, build, profile

By updated

Improve this page

The modern Nix commands (nix search, nix shell, nix run, nix build, nix profile) replace the old tools (nix-env, nix-build, nix-shell) with a unified interface and more readable outputs. This guide covers the daily workflow: search for a package, try it without installing it, add it to the profile, build it locally, and inspect its metadata. Every command was replayed on Nix 2.35.2, in the official nixos/nix image, with the nixpkgs-unstable of 29 September 2026.

What you will learn

  • Search for a package in nixpkgs with nix search
  • Run a temporary binary with nix shell and nix run
  • Manage installed packages with nix profile (add, remove, upgrade)
  • Build a package locally with nix build
  • Inspect the metadata and dependencies of a package
  • Know the utility commands (nix eval, nix path-info, nix why-depends)

In what context?

The modern commands are enabled by the experimental-features = nix-command flakes option in /etc/nix/nix.conf. They cover most of the daily needs of an administrator who wants to keep the system clean:

  • try a tool quickly without polluting the system (demo, debugging, version comparison),
  • install user tools without root rights and without dependency conflicts,
  • build a project reproducibly before deploying it,
  • inspect the dependencies of a package before shipping it in a container or a VM.

nix search queries a flake whose name you must give as the first argument, here nixpkgs. This is what sets it apart from apt search: the command does not search "the available packages" in general, but the collection you designate. The exact name returned, for example legacyPackages.x86_64-linux.htop, is the one the other Nix commands will expect afterwards.

The term is searched in the attribute path, the name and the description of the packages, which explains the number of results for a common word: abtop shows up here because its description mentions htop.

Terminal window
nix search nixpkgs htop
Result (excerpt)
* legacyPackages.x86_64-linux.abtop (0.5.5)
* legacyPackages.x86_64-linux.htop (3.5.3)
* legacyPackages.x86_64-linux.htop-vim (3.5.3)
* legacyPackages.x86_64-linux.neohtop (1.2.0)

The first evaluation of nixpkgs takes 30 to 60 seconds (evaluation of the full tree). The following searches use a local cache and are almost instant.

Search with a regular expression

nix search accepts regular expressions to narrow things down. Beware: the expression is tested separately against the attribute path, the package name and its description, and a single match is enough.

Terminal window
nix search nixpkgs "^python3$"
Result (excerpt)
* legacyPackages.x86_64-linux.buildbotPackages.python (3.14.7)
* legacyPackages.x86_64-linux.jupyter (3.14.7-env)
* legacyPackages.x86_64-linux.llm (3.14.7-llm-0.31.1)
* legacyPackages.x86_64-linux.python3 (3.14.7)
* legacyPackages.x86_64-linux.python311 (3.11.16)

On this nixpkgs, the command returns 17 results, not just python3: jupyter or llm are Python environments whose package name is exactly python3. The ^...$ anchor does rule out variants such as python3Packages.*, but not these namesakes; to check a precise attribute, nix eval is more direct.

Display the metadata

To get the description of a package:

Terminal window
nix eval nixpkgs#hello.meta.description
Result
"Program that produces a familiar, friendly greeting"

Try without installing: nix shell and nix run

These two commands download the package into the store and make it executable immediately, without ever touching the profile or the system. This is the usage that replaces the classic "I install it to try, I will uninstall it afterwards": there is nothing to uninstall since nothing was installed. The package still takes up disk space until the next garbage collection.

nix shell, a temporary shell with packages

nix shell opens a new shell with the requested packages in the $PATH. Nothing is installed in the profile:

Terminal window
nix shell nixpkgs#cowsay -c cowsay "Temporary Nix shell"
Result
_____________________
< Temporary Nix shell >
---------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||

After it runs, cowsay is no longer available:

Terminal window
which cowsay
# cowsay not found

The -c option runs a single command and exits. Without -c, an interactive shell opens with the packages in the $PATH, until you type exit.

Combine several packages

Each extra package is added as a separate argument, prefixed with its flake: there is no separator and no list to quote.

Terminal window
nix shell nixpkgs#jq nixpkgs#curl -c sh -c 'curl -s https://api.github.com/repos/NixOS/nix | jq .stargazers_count'

Both packages are available in the same temporary shell: jq 1.8.2 and curl 8.22.0 on the nixpkgs of the day. The sh -c is needed because the pipe has to be interpreted by a shell.

nix run, run a binary directly

nix run downloads the package and runs its main binary without opening a shell:

Terminal window
nix run nixpkgs#bat -- --version
Result
bat 0.26.1

The -- separates the arguments of nix run from those passed to the binary: without it, --version would be read by nix itself and would print the Nix version.

Difference between nix shell and nix run

The four forms below differ on two points: whether a shell is opened, and whether several packages are reachable. Remember that nix run only launches the main binary declared by the package, which excludes the additional tools it installs alongside; in that case, use nix shell.

CommandBehaviourUse case
nix shell nixpkgs#toolOpens a shell with tool in the $PATHExplore, run several commands
nix shell nixpkgs#tool -c cmdRuns cmd in a temporary shellScript, pipeline
nix run nixpkgs#toolRuns the main binary directlyQuick test, one-shot
nix run nixpkgs#tool -- argsRuns with argumentsCheck a version, start a server

Manage installed packages: nix profile

The profile is the set of packages made permanently available to your account, without root rights and without conflict with those of the distribution. Every operation creates a numbered generation in it, which makes installation and removal reversible. The subcommands follow the same logic as any package manager: add, list, remove, upgrade.

Add a package

No sudo is needed: the package is added to the profile of the current user, not to the system.

Terminal window
nix profile add nixpkgs#fd

fd is now permanently available in your $PATH:

Terminal window
fd --version
Result
fd 10.5.0

List installed packages

For each entry, the output gives the requested source (flake:nixpkgs), the nixpkgs locked revision at the time it was added, and the store path, the only way to know the version actually installed, since the package name does not contain it.

Terminal window
nix profile list
Result
Name: fd
Flake attribute: legacyPackages.x86_64-linux.fd
Original flake URL: flake:nixpkgs
Locked flake URL: https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1082290.b6c8664de9b6/nixexprs.tar.zst?narHash=sha256-k8Fu4c9Z%2B4Nh7mUr0cfw%2B%2BITQiyEhlWxoJBOkI3tOcQ%3D
Store paths: /nix/store/4xblm8snjdb609iygrqyrx9l07mqfp2c-fd-10.5.0
Name: jq
Flake attribute: legacyPackages.x86_64-linux.jq
Original flake URL: flake:nixpkgs
Locked flake URL: https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1082290.b6c8664de9b6/nixexprs.tar.zst?narHash=sha256-k8Fu4c9Z%2B4Nh7mUr0cfw%2B%2BITQiyEhlWxoJBOkI3tOcQ%3D
Store paths: /nix/store/gpc36qrvyhyqb6axmj1c0ivx74ni7d8d-jq-1.8.2-man /nix/store/m3y7hqmy20nd1ps6qy8410a326255bf0-jq-1.8.2-bin
Name: ripgrep
Flake attribute: legacyPackages.x86_64-linux.ripgrep
Original flake URL: flake:nixpkgs
Locked flake URL: https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1082290.b6c8664de9b6/nixexprs.tar.zst?narHash=sha256-k8Fu4c9Z%2B4Nh7mUr0cfw%2B%2BITQiyEhlWxoJBOkI3tOcQ%3D
Store paths: /nix/store/vli6118fdbngwy46j1w741ansmrzfszr-ripgrep-15.2.0

Remove a package

Removal is done by package name, not by the full flake reference used at installation.

Terminal window
nix profile remove fd
Result
removing 'flake:nixpkgs#legacyPackages.x86_64-linux.fd'
removed 1 packages, kept 2 packages

The fd binary disappears from the $PATH immediately. The package stays in the store until garbage collection.

Upgrade packages

To upgrade a specific package, designate it by its name:

Terminal window
nix profile upgrade ripgrep

To upgrade all the packages of the profile, use --all:

Terminal window
nix profile upgrade --all
Result (excerpt)
upgrading 'legacyPackages.x86_64-linux.jq' from flake 'https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1082290.b6c8664de9b6/nixexprs.tar.zst?narHash=...' to 'https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1082290.b6c8664de9b6/nixexprs.tar.zst?narHash=...'

The old form nix profile upgrade '.*', still quoted by many tutorials, no longer works: Nix 2.35.2 answers warning: Package name '.*' does not match any packages in the profile. and upgrades nothing.

History and rollback

Every operation on the profile creates a generation. Look at the history and go back if needed:

Terminal window
nix profile history
Terminal window
nix profile rollback # back to the previous generation
nix profile rollback --to 2 # switch to a specific generation

Build locally: nix build

nix build produces a package in the store without adding it to the profile, so without making it available in the $PATH. In practice the build is often instant: Nix first checks whether the result already exists in the public binary cache and then simply downloads it. A local compilation only happens if no prebuilt version matches exactly.

Build and inspect the result

nix build builds (or downloads from the cache) a package and creates a result symbolic link in the current directory:

Terminal window
nix build nixpkgs#hello
Terminal window
ls -la result
Result
result -> /nix/store/5z2yp3ysx8476c8g5w25b0smlgkjvaq3-hello-2.12.3
Terminal window
./result/bin/hello
Result
Hello, world!

The result link acts as a GC root: as long as it exists, the package will not be deleted by the garbage collector.

Without a result link, there is no GC root any more: the built package becomes eligible for deletion at the next garbage collection.

Terminal window
nix build nixpkgs#hello --no-link

The package is built in the store but no result link is created. Useful to prefill the cache without cluttering the current directory.

Inspect packages: utility commands

These three commands answer the questions that come up before shipping a package in a container image or a VM: how much does it weigh once its dependencies are counted, why does it pull in a given library, and how is it built. None of them modifies the profile or the system.

nix path-info, path and size in the store

With no option, the command only prints the path; you need -s for the own size, -S for the closure and -h for readable units.

Terminal window
nix path-info nixpkgs#ripgrep
Result
/nix/store/vli6118fdbngwy46j1w741ansmrzfszr-ripgrep-15.2.0

With the sizes (own and closure):

Terminal window
nix path-info -sSh nixpkgs#ripgrep
Result
/nix/store/vli6118fdbngwy46j1w741ansmrzfszr-ripgrep-15.2.0 6.7 MiB 55.7 MiB

The first column of figures is the own size of the package, the second its closure size (all dependencies included).

nix why-depends, trace a dependency

To understand why a package depends on another, give both to nix why-depends. The target must designate a single store path: since pcre2 produces several outputs (out, bin, man…), you have to name the one you are looking for, here .out.

Terminal window
nix why-depends nixpkgs#ripgrep nixpkgs#pcre2.out
Result
/nix/store/vli6118fdbngwy46j1w741ansmrzfszr-ripgrep-15.2.0
└───/nix/store/7v8b5idfzwfl06hx6n0cvd5ikd5p0sbg-pcre2-10.48

Without .out, Nix 2.35.2 refuses with error: argument 'flake:nixpkgs#pcre2' should evaluate to one store path.

nix derivation show, build recipe

The output is a large JSON document, hence the head -c 400 of the example; the 2>&1 redirection also captures the evaluation messages printed on the error output.

Terminal window
nix derivation show nixpkgs#hello 2>&1 | head -c 400
Result (excerpt)
{"derivations":{"cnraiw0hbdl6jzdhbkn8dah2hqj7xgij-hello-2.12.3.drv":{"args":["-e","/nix/store/l622p70vy8k5sh7y5wizi5f2mic6ynpg-source-stdenv.sh","/nix/store/shkw4qm9qcw5sc5n1k5jznc83ny02r39-default-builder.sh"],"builder":"/nix/store/10dxp0qxqxxsyiljrh2kp0xqhz6arhcx-bash-5.3p15/bin/bash","env":{"out":"/nix/store/5z2yp3ysx8476c8g5w25b0smlgkjvaq3-hello-2.12.3"},

A derivation is the complete recipe to build a package: sources, dependencies, builder, environment variables. It is the fundamental element that guarantees reproducibility.

Summary of the commands

The right-hand column is the most useful day to day: it separates the commands that leave the system unchanged from those that create a new profile generation. The former have no consequence and can be tried freely; the latter are undone with nix profile rollback.

CommandUsageModifies the profile?
nix search nixpkgs <term>Search for a packageNo
nix shell nixpkgs#pkgTemporary shell with the packageNo
nix run nixpkgs#pkgRun the main binaryNo
nix build nixpkgs#pkgBuild and create ./resultNo
nix profile add nixpkgs#pkgInstall into the profileYes
nix profile remove pkgUninstall from the profileYes
nix profile upgrade pkg (or --all)UpgradeYes
nix profile listList installed packagesNo
nix profile historyHistory of generationsNo
nix profile rollbackBack to the previous generationYes
nix eval nixpkgs#pkg.attrEvaluate an expressionNo
nix path-info nixpkgs#pkgPath and size in the storeNo
nix why-depends A BTrace a dependencyNo
nix derivation show nixpkgs#pkgShow the recipe (.drv)No

Key points

  • nix search explores the 100,000+ packages of nixpkgs, the first evaluation is slow, the following ones are instant.
  • nix shell and nix run let you try a tool without installing it, ideal for debugging or comparing versions.
  • nix profile manages permanently installed packages with a full history and an atomic rollback; nix profile upgrade --all upgrades everything.
  • nix build builds a package and creates a result link, useful to inspect or deploy the result.
  • The utility commands (eval, path-info, why-depends, derivation show) help understand how a package is made up.
  • All these commands use the nixpkgs#package syntax to designate a package, a flake reference, detailed in the Flakes guide.

Knowledge check

Check that the essentials of this guide are acquired. The questions only cover what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer