Prevent `nixos-rebuild switch` from using flake

As I just got into this issue and needed to got into the source code of nixos-rebuild, it turns out that if a /etc/nixos/flake.nix is created, then nix will automatically switch to flake, trying to build the host matching the current hostname.

So I wanted to document somewhere: how to force nixos-rebuild switch to use the legacy nix mode?

nixos-rebuild switch --no-flake

Ironically, I was getting warnings about experimental feature “flakes” being disabled when I tried to nixos-rebuild switch --no-flake. Something in the depths still needed them. So I added this to my configuration:

nix.settings.experimental-features = [ "nix-command" "flakes" ];

switched to that and then nixos-rebuild switch --no-flake started working.