devsetup local development environment based on pkgsrc - Pierre Pronchery -   EuroBSDcon 2022
Channel: EuroBSDcon
Date: 2023-05-08

pkgsrc is the official source of software packages for NetBSD and SmartOS; that much is clear. It has the focus of developers and users on these two platforms, and it is expected to work well there. In this model, pkgsrc is typically used in _privileged_ mode (the default) where the packages are installed and managed by the system administrator: users and groups are created for packages as required, additional services are provided and can be registered with the Operating System.

Another selling point for pkgsrc is its portability, since it is available and
also working well on a number of other platforms: Linux distributions, FreeBSD (and derivatives like DragonFlyBSD), OpenBSD, or macOS are also supported. But on all of the platforms mentioned, pkgsrc can now also work just as well in _unprivileged_ mode.

In this mode, any local user with a C compiler can clone pkgsrc, build
packages, and manage these packages themselves, by themselves, for themselves. Thanks to the introduction of the `SYSCONFBASE` setting in `mk.conf`, together with ongoing work on the RC scripts provided, local users can even build, install, run, and manage services entirely through pkgsrc's packages.

This brings a new use case for pkgsrc across every platform supported, old or modern: complete development environments can be based on pkgsrc releases, and work and behave consistently regardless of the local platform. This principle is illustrated in a new tool, called _devsetup_, where a single script can be used to bootstrap and maintain a complete development environment, thanks to pkgsrc.

With devsetup, it only takes a single command to reproduce instances of pkgsrc across systems and platforms. This is ideal for pkgsrc developers and package maintainers, when tracking bugs or improving portability on unfamiliar platforms. This is particularly true on macOS for instance, where it can conveniently replace solutions like Homebrew.

This presentation will focus on pkgsrc's unprivileged mode, from bootstrapping to package management. It will dig deeper into the internals of the `pkgtools/rc.subr` support system for the services provided by pkgsrc, and explain the need for the additional `SYSCONFBASE` setting. From there, ongoing and necessary changes to the RC scripts provided will be discussed, considering the differing contexts and environments in which services may be needed and used.