macOS custom keyboard layout is removed each restart of the OS I copied my custom keyboard layout into /Library/Keyboard Layouts. After that, I can easily choose from System Preferences → Keyboard → Input Sources, and it just works fine. But whenever I restart the computer, the previously added keyboard layout is deleted automatically and has to be added again The computer does not delete the files inside the /Library/Keyboard Layouts directory, it only deletes the entry in System Preferences.

How do I resolve this issue?
Try putting a copy of your custom keyboard layout in ~/Library/Keyboard Layouts directory. The Library directory in your Home directory is hidden by default. To enter it, click Go in Finder menu, press and hold the Option key to reveal Library option.