The previous post explained a problem in pkgviews WRT directories used by a program where other packages can install files; the most typical example are directories holding plugins. It also outlined two possible solutions, or better said, workarounds. I'll explain my solution here, which is already implemented but waiting for approval.

The idea is to "configure" programs at run time to let them access the view from where they are executed. This is very easy to do: we just have to patch all programs that have this problem so that they use a global environment variable, say PKG_VIEWBASE, that points to the root directory of the view being used. Picking the XMMS example again, the program could be modified to search for its input plugins from ${PKG_VIEWBASE}/lib/Input, falling back to its depot directory if the variable is not set.

You may now think: "but hey, I have to manually set an environment variable before running programs!". True. But this can be worked around by changing the semantics of pkgviews a bit. That is, instead of creating symlinks for executables, we'd have to create wrappers. The task of these small wrappers is simply to set up the environment variable and then launch the real program.

For example, to make it clearer, /usr/pkg/bin/xmms could be this piece of code:

#!/bin/sh 

PKG_VIEWBASE=/usr/pkg; export PKG_VIEWBASE

/usr/pkg/packages/xmms-1.2.10/bin/xmms "$@"

As you can see, this script also has hardcoded paths in it, but these were written when the package was added to the view. If I want to add XMMS to another view after its installation, I can easily do it, and the appropiate wrapper will be generated on the fly with the right paths.

You may argue that adding a new variable is not needed in some cases, as programs provide their own way to specify the location of files at run time (for example, PKG_CONFIG_PATH in pkgconfig). I know; this is why these wrappers can be easily extended (on a package basis) to override more environment variables (like this one), which simplifies maintenance in such programs (less patches).

Nice, eh? ;-) As I said, this is already implemented and works well for me. When I've got an 'Ok' from one of the main developers of pkgviews, I'll start fixing all programs (basically, GNOME) to use the new environment variable.