how to find which packages are installed system-wide in NixOS?
Solution 1
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.
Solution 2
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.
Solution 3
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.
Related videos on Youtube
![illabout](https://i.stack.imgur.com/TcwLC.png?s=256&g=1)
illabout
Updated on September 18, 2022Comments
-
illabout almost 2 years
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:
Let's say I add a package to
/etc/nixos/configuration.nix
inenvironment.systemPackages
, but I forget whether I have runnixos-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.I have
programs.bash.enableCompletion
set totrue
in/etc/nixos/configuration.nix
. Without looking at the option in nixpkgs, I would guess that this option would set thebash-completion
package to be installed. It would be nice if there was a command that I could run that checked whether thebash-completion
package actually was in the system environment.
-
Jake Ireland about 4 yearsFor OSX, this list is located in your home directory:
nix-store -q --requisites "${HOME}/.nix-profile"
. -
Vladimír Čunát about 4 years
~/.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 bynix-env --profile path