Looking to drive a value based on current layer rendering

I have a setup where I want to change the value on a mix node in a Cycles material based on the render layer actively rendering. So it would render RenderLayer1 with a mix fac of 0, and then RenderLayer2 with a mix fac of 1. This will result in rendering the same model twice but with different materials.

Is it possible to drive the mix node based on the currently rendering layer? Or would be be possible to write a script that renders RenderLayer1, then changes the value, then renders RenderLayer2?

Thanks