Tested with WordPress 6.0, and it works:
add_action( 'activated_plugin',function( $plugin,$network_activation ){
add_role( 'your_custom_role_slug', __( 'Your custom role title','your-plugin-domain' ),
array(
'read' => true,
'view_admin_dashboard' => true,
'activate_plugins' => false,
'deactivate_plugins' => false,
'your_custom_capability' => true
)
);
}, 10, 2 );
In the array, you have just some examples of capabilities. And you can add your custom capability without any problem. The custom capability will be stored together with the other capabilities.
With this method, you will not be able to say what you can do with "your_custom_capability", but most of the time like in the case of this question, you need nothing else than checking if the current user can "your_custom_capability".
If you want to show your plugin setting pages only to the users who have the capability "your_custom_capability", you can do it without problems.
Use the inbuilt capabilities when you create the role to decide what are the other things that the user with the role "your_custom_role_slug" should be able to see and do.
This will return true if the user has the role "your_custom_role_slug":
current_user_can( 'your_custom_capability' );
And this will show the settings page only if the user has the capability "your_custom_capability":
add_menu_page( __( 'Your title','eos-dp' ),__( 'Your title','your-domain' ),'your_custom_capability,'your_page_slug','your_function_callback','dashicons-your-icon',20 );
Then on plugin deletion, I would remove the user role with:
remove_role( 'your_custom_role_slug' );