System profiles and `switch-to-configuration`

I’m sure I should understand this by now, but…

I just had a RPi system break again for unclear reasons. I mounted the hard drive from an Arch (+ nix) system and had a bit of trouble reinstalling (mount: command not found when using nixos-install, nixos-enter didn’t work right, inside the chroot had sandbox and BPF issues) but eventually got things to seem to work.

In my tinkering, I realized that I don’t exactly understand what I’m doing when I “simulate” nixos-rebuild switch with the following:

$ nix build .#nixosConfigurations.mymachine.config.system.build.toplevel
$ nix-env -p /nix/var/nix/profiles/system --set ./result
$ ./result/bin/switch-to-configuration switch

I think I understand the nix build step.

Setting the system profile is the step that I’m really unsure about. What is that? It seems like a different idea than installing something with nix profile.

switch-to-configuration switch – this is activating the configuration and setting it as the default boot target. Right? (Glanced through the source, but I never learned perl.)