The following Rule export does what you asked, for users created in the UI. In D8. I have tested it and it works. You will also need to use the (temporary) patch from https://www.drupal.org/project/rules/issues/2725525#comment-11438731 to work around the problem with in assigning roles.
The concept to understand is that Rules knows about the base fields for the entity type. But if you add fields, that's a new entity bundle, so you need to tell Rules that your data is of a certain bundle. To do that, you use the "Entity is of bundle" condition, as I show below. Then all the fields for that bundle will show up in the data selector.
langcode: en
status: true
dependencies: { }
id: set_a_role_for_new_users
label: 'Set a role for new users.'
events:
-
event_name: 'rules_entity_insert:user'
description: 'Assign the ''student'' role to new users who identify themselves as students. Requires a boolean field ''field_is_student'' on the user object and requires an available role with machine id ''student''.'
tags: { }
weight: 0
config_version: '3'
expression:
id: rules_rule
uuid: 36de9619-1401-4b21-a651-d3927c5b8dac
weight: 0
conditions:
id: rules_and
uuid: 416e90b0-d24c-4f37-8272-de0ecee5c375
weight: 0
conditions:
-
id: rules_condition
uuid: bafe6fc4-f88f-4df2-af9b-2b3558257c2b
weight: 0
context_values:
type: user
bundle: user
context_mapping:
entity: user
context_processors:
type:
rules_tokens: { }
bundle:
rules_tokens: { }
provides_mapping: { }
condition_id: rules_entity_is_of_bundle
negate: false
-
id: rules_condition
uuid: 28787d22-54ca-49cf-af42-6f1011ed6494
weight: 0
context_values:
operation: '=='
value: '1'
context_mapping:
data: user.field_is_student.value
context_processors:
operation:
rules_tokens: { }
value:
rules_tokens: { }
provides_mapping: { }
condition_id: rules_data_comparison
negate: false
actions:
id: rules_action_set
uuid: 2933681a-a079-496d-bc79-f27ff53144eb
weight: 0
actions:
-
id: rules_action
uuid: 38e8a3bb-0470-427f-80e1-53f6a703e8bf
weight: 0
context_values:
roles:
- student
context_mapping:
user: user
context_processors:
roles:
rules_tokens: { }
provides_mapping: { }
action_id: rules_user_role_add