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
/nix/store/gfqwbax0x58mjnh89ca6milx41bw49lr-libunistring-1.0
/nix/store/9jqiw71lq60sdpiniywq3msknf3wmd9c-libidn2-2.3.2
/nix/store/v6szn6fczjbn54h7y40aj7qjijq7j6dc-glibc-2.34-210
/nix/store/45yg19sl585bba3xkdsnsrvlqd0gck7r-libjpeg-turbo-2.1.3
/nix/store/528ypr87qk0m8hnmplrj43jzax42lgc2-libXau-1.0.9

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 =
    let
      packages = builtins.map (p: "${p.name}") config.environment.systemPackages;
      sortedUnique = builtins.sort builtins.lessThan (lib.unique packages);
      formatted = builtins.concatStringsSep "\n" sortedUnique;
    in
      formatted;

, 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 p.name 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\#erlang.name
"erlang-25.2.2"
$ nix eval nixpkgs\#erlang_nox.name
"erlang-25.2.2"