I recently came across a great answer on Stack Overflow explaining how to show all packages installed on your system in NixOS. In this article I will add a little more explanation to the different commands used.
Showing installed packages
The difficulty of showing all installed packages on NixOS is that there are multiple ways to install packages:
- add a package to
- install packages in your user profile with the command
nix-env --install packagename
- install packages in root's profile with the command
sudo nix-env --install packagename
There is currently no single command that will show packages installed in all three places. Instead, we need to use three different commands depending on where to check for packages.
Listing packages installed from
One way to list packages installed from
configuration.nix is with the
This lists a lot of information about the
environment.systemPackages option. This includes its current value, its default value, which modules add values to it, etc.
Unfortunately, this output is pretty long. We can clean it up a little bit with the following commands. This isn't perfect, but it will do in a pinch:
Listing everything installed from
The problem with the above command is that it doesn't list all transitive dependencies.
One way to list all transitive dependencies is with the
This lists every derivation built when doing
nixos-rebuild switch. The output of this command is also a little hard to read, but we can clean it up:
This command really lists every derivation installed, not just packages. For example, you should also see things like man pages, config files in
Listing packages installed in a user profile
The above commands do not show the packages installed into a user profile with
nix-env --install. For that, we will need to use the
nix-env --query command.
The following shows how to list packages installed in your local user profile:
$ nix-env --query highlight-126.96.36.199 jq-1.5 libreoffice-188.8.131.52
Running the same command as root will list packages installed in root's profile:
$ sudo nix-env --query tcpdump-4.9.2
In order to list packages installed on your system, you need to remember the
nix-store --query, and
nix-env --query commands. It would be nice if there were a single command that would output all of this different information, but for now, there is not.
For now, if you are ever in doubt, you should first try
nix-env --query. If that doesn't have what you're looking for, try pointing
nix-store --query --requisites at