lib.mkIf returns an attrset, not a string, so it cannot be used as a list element. Replace with lib.optional. Fixes: error: expected a string but found a set: { _type = "if"; ... }