What is going on with mkIf here?

Since mkIf is not actually implemented using if, this behavior is justified.

These should help you:

https://nixos.org/manual/nixos/stable/#sec-option-definitions-delaying-conditionals