Preparing future NixOS configuration from non-NixOS VM over SSH

I’m slowly growing my first flake by adding more machine I own to it. To add a machine, I need to know it’s configuration.nix / hardware-configuration.nix. Once I know them, I put them in my flake and use nixos-anywhere to provision the machine over SSH.

Getting these configs is tedious, because I have to:

  1. connect that machine to a monitor,
  2. boot that machine with NixOS .iso,
  3. run commands to generate the configs, then copy them over next to my flake source.

Is there a way to collect values of configuration.nix and hardware-configuration.nix over SSH somehow?

Like, run some program/flake that connects to the target machine over SSH, gathers “the facts”, and produces configuration.nix and hardware-configuration.nix on current source machine using the facts gathered?