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.
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):