nixos-rebuild switch --offline
should take care of that. Switching your system configuration to use a different DNS server seems silly to me, though.
If you use NetworkManager, you can use nmcli
to temporarily switch off a DNS server for a specific connection, though this requires you to set up NetworkManager to manage DNS in general, and in turn means you need to configure each connection to use a specific DNS server individually, which is a bit of a PITA.
IMO a nice generic solution to various DNS configuration problems is to use a local “stub” dns resolver, e.g. unbound, which just forwards your queries to whatever you configure it to, and usually locally caches resolved domains, which is a nice side-effect (in fact, why isn’t this set up by default more?). These usually have fully-fledged DNS server features, so you if you configure them as your nameserver, you can in turn use normal DNS server configuration to make it do just about anything.
Unbound specifically has a cli tool which you can use to update its settings at runtime, and you can use that to update the forward-zone to point at whatever the network you just connected to uses as its DNS server, which will let you resolve whatever login page you need to access, after which you can just use the cli tool to switch back to your chosen DNS server. I’d personally write some scripts to do that.
I’ve not made the switch to secure DNS yet, but here’s my config to set up unbound with the basics to make unbound-control
work: dotfiles/nixos-config/networking/default.nix at f95801fef3c6017d901de0fef252878ef37e90e0 · TLATER/dotfiles · GitHub
Its configuration is a lil’ confusing if you haven’t worked much with DNS before, though, and it’ll take a bit of scripting. Do please share if you try this, I’d quite like to set this up as well, just haven’t gotten around to doing so yet 
You can do some really neat stuff in general with this, I for example use unbound to automatically resolve server domain names through a wireguard network after NetworkManager brings it up, so that I can whitelist my IP address without having to set that to an address that may or may not be static (and controlled by an ISP), as well as to redirect hostnames on a local zone to a qemu bridge, which lets me test servers deployed into VMs with real host names - quite handy when you use reverse proxies to create subdomains.