When I boot with the external monitor connected, xrandr crashes Xorg

I connected an external HDMI monitor to my laptop. Since then I’ve noticed an unusual phenomenon.

  1. When I boot my laptop with the external monitor connected, lightDM mirrors my laptop’s display unto the external monitor. This mirroring effect remains in effect when I log in to my window manager. However, when I try to use xrandr, Xorg crashes.
  2. When I disconnect my external monitor, restart Xorg, and then connect my external monitor, I’m able to use xrandr to modify the monitor layout.
  3. If after completing #2 above, I disconnect my external monitor and then use xrandr to deactivate it, Xorg crashes.

Solved with nixos/nvidia: optionally disable setup commands for reverse sync by emmanuelrosa · Pull Request #318521 · NixOS/nixpkgs · GitHub