Rebuilding or updating causes screen to go black and reboot into an empty OS session

Hey guys, I’m trying to get everything set up for the first time on my new M2 machine. I’m trying to use nix-darwin through home-manager as exactly described in this tutorial.

When I run darwin-rebuild switch --flake ~/src/system-config/.# my whole graphical interface shutsdown and reboots with none of the previous programs running.

Here is a youtube recording i just made showing the system rebooting when this happens. https://youtu.be/88J7DUMVbeU

Running nix-channel --update also causes the same problem to occur. Running nix build --show-trace also does the same.

See below for some context. Has anyone seen this error happen before or can point me what to debug next. I’ve been trying to find some answers for a few days now and completely lost.

Thanks in advance!

josh@Josh> echo $NIX_PATH                                                                              
/Users/josh/.nix-defexpr/channels:darwin-config=/Users/josh/.nixpkgs/darwin-configuration.nix:/nix/var/nix/profiles/per-user/root/channels

josh@Josh> which nix                                                                                   
/nix/var/nix/profiles/default/bin/nix

josh@Josh> nix-channel --list                                                                          
darwin https://github.com/LnL7/nix-darwin/archive/master.tar.gz
home-manager https://github.com/nix-community/home-manager/archive/release-23.05.tar.gz
nixpkgs https://nixos.org/channels/nixpkgs-unstable

if l look at the last few entries in /var/log/system.log file it seems its logging me out and starting a whole new user process everytime.

Jul  4 16:01:31 Joshuas-Mac-Studio login[49017]: USER_PROCESS: 49017 ttys000
Jul  4 16:01:31 Joshuas-Mac-Studio login[49019]: USER_PROCESS: 49019 ttys001
Jul  4 16:01:58 Joshuas-Mac-Studio login[49194]: USER_PROCESS: 49194 ttys000
Jul  4 16:01:58 Joshuas-Mac-Studio login[49195]: USER_PROCESS: 49195 ttys001
Jul  4 16:06:25 Joshuas-Mac-Studio login[49621]: USER_PROCESS: 49621 ttys000
Jul  4 16:06:25 Joshuas-Mac-Studio login[49622]: USER_PROCESS: 49622 ttys001
Jul  4 16:07:36 Joshuas-Mac-Studio login[49947]: USER_PROCESS: 49947 ttys000
Jul  4 16:07:36 Joshuas-Mac-Studio login[49949]: USER_PROCESS: 49949 ttys001
Jul  4 16:13:47 Joshuas-Mac-Studio syslogd[116]: ASL Sender Statistics
Jul  4 16:14:32 Joshuas-Mac-Studio login[50421]: USER_PROCESS: 50421 ttys000
Jul  4 16:14:32 Joshuas-Mac-Studio login[50423]: USER_PROCESS: 50423 ttys001
Jul  4 16:15:49 Joshuas-Mac-Studio login[50423]: USER_PROCESS: 49949 ttys001
Jul  4 16:23:53 Joshuas-Mac-Studio syslogd[116]: ASL Sender Statistics