Since macOS Catalina, the root drive is read-only. The solution is to create a separate APFS volume and a “synthetic” /nix directory which points to it:
# Check if /nix exists, if not:
echo 'nix' | sudo tee -a /etc/synthetic.conf
# this will create a "synthetic" empty directory /nix
# REBOOT so macOS sees the synthetic directory
# After rebooting, create an APFS volume for Nix
# make sure to replace disk1 with the correct disk number, if different.
sudo diskutil apfs addVolume disk1 APFSX Nix -mountpoint /nix
sudo diskutil enableOwnership /nix
sudo chflags hidden /nix # Don't show the Nix volume on the desktop
echo "LABEL=Nix /nix apfs rw" | sudo tee -a /etc/fstab
# Install Nix as usual
curl https://nixos.org/nix/install | sh