Inspired by the recent comments of a user, I decided to implement an alternatives system for pkgsrc, similar to the one used by Debian. The purpose of this framework is to manage symbolic links that point to specific programs from a group of utilities with similar behavior.

The easiest example to show what this means comes when looking at Vim and Nvi. Both editors can be generally installed on the same system without conflicts. However, in that case, the system still misses a generic name, such as vi, to launch one as the default editor for the system. The administrator can make that link by hand, but couldn't it be nice if the system itself created it for you?

Alternatives come to improve this situation: multiple packages register themselves as providers for a set of links with a generic name (which I have named as class). The administrator is then free to choose which one should be the default, and the system adjusts the symbolic links to point to the preferred utility. This even works in an unattended manner, because the packages adjust the links at (de)installation if needed.

This is, of course, applicable to many other situations. Consider Java virtual machines, MTAs, window managers, Python interpreters, etc. In fact, I hope that this will simplify some stuff that we already have in pkgsrc to handle wrappers to run Java (i.e., lang/java-wrapper or Python, in a more flexible way.

So let's look at how this actually works from the point of view of a package (in this case, editors/nvi):

ALTERNATIVE_CLASSES=   vi nvi ${PREFIX}/bin/vi ${PREFIX}/bin/nvi ${PREFIX}/man/man1/vi.1 ${PREFIX}/man/man1/nvi.1

Simple, eh? ;-) This is internally handled by the new utility, pkg_alternatives, which is not yet finished. I hope it'll be ready tomorrow. Note that this is still not committed to the tree; in fact, I don't even know if other developers will be against it. Anyway, more on this on the next post.

Edit (20th Jan, 10:39): I've had to change the semantics of the Makefile variables to allow more flexibility, so I've adjusted the example above accordingly.

Go to posts index

Comments from the original Blogger-hosted post: