40-drive RAID is moving out of homelab territory and pretty deep into enterprise storage systems.
Do you already have these 40 drives or are you spacing out a new NAS from scratch?
If it’s from scratch I’d first see if I could get it down to 20 or 24 larger drives to allow the whole thing to fit in a single 4U rackmount case.
Bigger than that and you’re probably stuck with proprietary NAS hardware to link together multiple racks.