Is there a command that can be used to figure out which packages are installed system-wide in NixOS?

For instance, I can list packages installed for my current user with nix-env -q. I don't know of any way to list packages installed on the whole system from /etx/nixos/configuration.nix.

There are two separate instances I would want to use this:

  1. Let's say I add a package to /etc/nixos/configuration.nix in environment.systemPackages, but I forget whether I have run nixos-rebuild switch yet. It would be nice if there was a command I could run to check whether the package is in the system environment.

  2. I have programs.bash.enableCompletion set to true in /etc/nixos/configuration.nix. Without looking at the option in nixpkgs, I would guess that this option would set the bash-completion package to be installed. It would be nice if there was a command that I could run that checked whether the bash-completion package actually was in the system environment.


3 Answers 3


There's no specific tool for this. You may like the system.copySystemConfiguration option (see the docs for "caveats").

You'll get relatively close with nix-store -q --references /run/current-system/sw – the list of nix store paths directly contained in systemPackages, but note that various NixOS options may add packages in there.

  • For OSX, this list is located in your home directory: nix-store -q --requisites "${HOME}/.nix-profile". May 31, 2020 at 21:48
  • 1
    ~/.nix-profile is per-user profile on any system. To be complete, there's also the imperative system-wide profile in /nix/var/nix/profiles/default (at least on Linuxes, I'm not sure elsewhere... but the OP was phrased as "system-wide" + NixOS anyway) Any of these can be queried by nix-env --profile path Jun 1, 2020 at 19:55

Due to the approach NixOS takes on installing software, there's no such thing as a package which is installed system-wide. Not in the same sense of most package managers, that is.

However, if you treat a user environment (aka. profile) as the equivalent of system-wide, then you can use nix-store -q -R /nix/var/nix/profiles/system-${n}-link to list the dependencies of a given user environment; where ${n} is the profile's generation number. By dependencies, I mean direct and in-direct dependencies.

In addition, if you use the --tree instead of -R argument you can get an ASCII dependency tree.


For your first use case you can use:

nixos-rebuild dry-build

This command shows what would be built and download. If all you want to know is if there are new packages that should be built you can use the above command.

Please note that this won't tell you about packages that are already built but not currently active. Ex. If you add firefox to your configuration.nix, rebuild, remove firefox, rebuild, add firefox then run the above it won't show anything because there is nothing new to build. Nix keeps old packages until garbage collection.

There is also nixos-rebuild dry-activate which builds the new system but does no changes. It will show other changes, like if you disable/enable some services.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.