Automatically generate .nix file from ad hoc environment

Hi there. I just created an ad hoc environment with a good number of packages. I understand in this case I should create a declarative environment in a .nix file. I wonder whether this can be made automatically, in similar fashion to the freeze command provided by pip.

Thank you.

you can list all installed packages using nix-store -q --requisites /run/current-system/sw | sed 's|/nix/store/[^-]*-||', but i dont think there is a way to automatically create a config.