Yes, you can create a User to User lookup field (hierarchy) on the User object, for instance "Custom_Manager__c," and use the following logic. Apex, by default, plays in system modesystem mode.
trigger setManagerFromCustomField on User (before insert, before update) {
for (User u : Trigger.new) {
if (u.Custom_Manager__c != null) {
u.ManagerId = u.Custom_Manager__c;
}
}
}