List Installed Packages (without version numbers)

When I list installed packages, it prints the list with actual version numbers

$ nix-store --query --requisites /run/current-system|head

Can I ask this command to just list the package names, as a list I could put into a configuration.nix?

There is no correlation between the store path name and the attribute name. You can not produce a list that would do what you ask for.

And you wouldn’t even put a lot of those things into the configuration.nix.

Like about anything in the list you have already shown… As libraries are generally not installed that way.

Short answer: No.

Long answer:
Those names are the derivation names, which aren’t actually correlated, except by happenstance, to the attribute names by which you install things in configuration.nix.

In general, there’s no way to go from a built generation in the nix store to the configuration that built it, except if you’ve explicitly taken steps to preserve that configuration as part of the result.

Furthermore, not all the derivations that are part of your system closure are actually installed directly. Many of them only show up as indirect dependencies, and might even break things if they were installed directly.

1 Like

ok, fortunately, I had this:

  environment.etc."current-system-packages".text =
      packages = (p: "${}") config.environment.systemPackages;
      sortedUnique = builtins.sort builtins.lessThan (lib.unique packages);
      formatted = builtins.concatStringsSep "\n" sortedUnique;

, so /etc/current-system-packages contains a list of my packages, but they have version numbers;)

Any way to list this list without version numbers, so as to provide them as input to configuration.nix?:wink:

It seems I can’t just assume that they have semantic versioning, as some have full dates in them

Unfortunately, that’s still the package names, not the attribute names, though you do at least no longer include indirect dependencies.

It will also include packages installed by nixos by default, which you probably don’t want.

Is there any reason it isn’t sufficient for you to just include your entire config in the result?

This list is missing services you had enabled.

Though you can (for some) of them get the derivation name using p.pname, but not all have that set. p.pname or should get you close.

but this will just give you a list of names, which are unrelated to the name within pkgs and also do not tell from which input you installed, if mix stable and unstable.

Lets just take erlang and erlang_nox, both have the name (and no pname):

$ nix eval nixpkgs\
$ nix eval nixpkgs\