5. Search for Nix packages
→ Use the nix search
command to find packages in Nixpkgs
→ Explore the search.nixos.org web interface
→ Use the nix flake show
command to explore packages output by flakes
One great thing about Nix is that there are tons of packages available in the Nix ecosystem that you can use in Nix development environments, in your NixOS installations, and more. While Nixpkgs is by far the largest Nix package collection—over 100,000 packages and counting 😎—any Nix flake can provide package outputs.
But navigating all of this plenty can be tricky, so in this guide we’ll learn how to search for packages in Nixpkgs using the nix search
command and using the web application at search.nixos.org.
Then we’ll learn how to explore packages in other flakes.
The nix search
command
The Nix CLI has a search
command that you can use to search the packages in a flake based on a search term.
Let’s start by searching Nixpkgs, which is where we’re mostly likely to find packages we want.
This command will tell us if cargo is available in Nixpkgs:
In this command, the nixpkgs
flake reference is shorthand for github:NixOS/nixpkgs
.
The first time you run nix search
, the Nix CLI needs to download the full
Nix code contents of Nixpkgs—or whichever flake you’re
searching—and then cache it. Future nix search
runs for Nixpkgs should
be much speedier. Furthermore, Nixpkgs is the largest flake in existence and
running nix search
on other flakes should be much faster in general.
This brings up many results of the form legacyPackages.{system}.{package}
, the first of which should look like this on an Apple Silicon (aarch64-darwin
) system:
The system attribute varies on other platforms (you may see x86_64-linux
or something else).
After that first result, you should see many others, including packages like cargo-about
and cargo-audit
.
legacyPackages
isn't legacy software You can also output search results as JSON using the --json
flag:
This can be useful if you want to parse the output using a tool like jq.
search.nixos.org
The web interface at search.nixos.org has a few advantages over the nix search
command:
- It enables you to select a release channel for Nixpkgs, such as 22.11 and unstable
- It enables you to search across a range of public flakes beyond Nixpkgs (those flakes are listed here)
Exploring a flake with the nix flake show
command
As an example, let’s explore a popular flake for the Wayland window system protocol.
You can also display the outputs as JSON:
The first time you run nix flake show
, the Nix CLI needs to download the
full contents of nixpkgs-wayland
—or whichever flake
you’re running nix flake show
on—and then cache it. Future nix flake show
runs for the same flake reference should be much speedier.
nix search
vs. nix flake show
Should you use nix flake show
or nix search
? A good rule of thumb is to
always use nix search
with Nixpkgs and to initially use nix flake show
with other flakes. If the package outputs for nix flake show
are big enough
to be tricky to navigate, use nix search
for that flake instead.
System specificity
One thing you’ll notice about the search output for nix search
, search.nixos.org, and nix flake show
is that all the packages listed in the query results are for your current system (x86_64-linux
for an AMD/Intel Linux system, aarch64-darwin
for an Apple Silicon system, and so on).
That’s because Nix works in a fundamentally system-specific way.
The cargo
package on a Linux machine is considered a different package from cargo
on a non-Linux system.