substituteInPlace --replace-fail
Now substitution failures result in a script error. This has recently been backported to nixpkgs 23.11.