I don’t have enough disk space. Once the new packages are downloaded during the refactoring process, it will fail. Now I modified /etc/nixos/hardware-configuration.nix and added a new larger partition. But I could not successfully rebuild the system so that /etc/fstab could never be updated.
I didn’t use the --upgrade option in the command, but it still pulls new packages remotely. This may be because I have updated before, but it failed (maybe the channel has been updated?).
Yes, this is because you already used --upgrade, this made your channels advance.
There are ways to rollback channels. Check the man page of nix-channel.
In the long term it might be beneficial to use one of the various pinning techniques.
Also a nix-collect-garbage (--delete-older-than …d with an appropriate value for …) might mitigate the problem by getting rid of earlier generations of your system.
nixos-rebuild switch --upgrade isn’t atomic. It first does a nix-channel --update and then a nixos-rebuild switch. If the latter fails, your channel will still be updated, so subsequent nixos-rebuild switches will be based on the newer version.
nix-channel --rollback allows you to undo the effects of the channel update, though I don’t remember the exact form of the command.
Even if you start using a pinning strategy after resolving this, it might also be helpful to set min-free and max-free in the future to prevent running out of disk space inadvertently: Storage optimization - NixOS Wiki
That page also details instructions on how to move the nix store to a bigger partition that will not fail if you’re running out of disk space