I suggest you study how library/Xenforo/ControllerAdmin/Permission.php does it and do similar.
In general if you want to know how to do something then just look at how the Xenforo controller code does it and that is usually your answer. ControllerPublic and ControllerAdmin are a gold mine of 'how-to'.
The forum is the name of the permission group and permissionName is the name of your permission. This will add the custom permission under the Forum permission group. You can also create your own permission group, in which case, its name must be entered instead of the forum.
Then you can call your permission in template with this code.
your code to be executed goes here
That would be the gist of it. I hope that it helped.
To add permissions into your add-on, you need your site to be in debug mode. Then, navigate to Development > Permission Definitions in the ACP. Once there, you can create your own permission groups, permissions, and interface groups for your add-on. In code, you have to options to determine if the user has permission: