Moving from Homebrew to pkgsrc

I already use pkgsrc in SmartOS so the cognitive load of having a package manager per system is just too much for me, so consolidating now in just pkgsrc seems like the easiest way. The first action I took was to remove all homebrew packages installed in my system:

brew list | xargs brew uninstall --force

Now as usual with pkgsrc I followed the instructions at : After that business as usual. Now at first glance there are Apps that are not available in pkgsrc as they are propietary and native macos, that's not a problem at all, I just downloaded them again from the projects urls. In my case I use iterm2 so that's just a click away, the same thing with Calibre. The only roadblock I found was when installing emacs-nox11 and then trying to use vterm an error pops up, as the version of emacs in pkgsrc does not have support for dynamically loaded modules. Now for that I'm just going to recompile emacs form pkgsrc and enable them.

Recompiling from source using pkgsrc

This was not so straight forward also I'm new to MacOS so there are things about xcode and environment variables that I did not know until today. Asking jperkin in #smartos irc channel, he suggested two variables to add to /opt/pkg/etc/mk.conf

DEPENDS_TARGET=		bin-install

DEPENDS_TARGET will fetch the binary packages for dependencies instead of starting fetching sources and compiling them, that saves a lot of time. BINPKG_SITES as the name implies, is where pkgsrc will fetch the dependencies binary packages. Also there is a third variable that controls the MacOS SDK that uses to compile packages:

OSX_SDK_PATH=		/Applications/

But that variable is not needed. Another change that's needed to be able to install packages from source is to modify /opt/pkg/etc/pkg_install.conf


After these changes, I cloned the pkgsrc repository somewhere

git clone
cd pkgsrc
git checkout trunk

Now for testing let's compile games/fortune

#+begin_src shell
cd games/fortunes
 ~/Projects/OSS/pkgsrc/games/fortune/ [trunk*] bmake clean && bmake install
===> Cleaning for fortune-19970829
=> Bootstrap dependency digest>=20211023: found digest-20220214
=> Checksum BLAKE2s OK for fortune-mod-9708.tar.gz
=> Checksum SHA512 OK for fortune-mod-9708.tar.gz
===> Installing dependencies for fortune-19970829
The supported build options for fortune are:


You can select which build options to use by setting PKG_DEFAULT_OPTIONS
or the following variable.  Its current value is shown:

        PKG_OPTIONS.fortune (not defined)

=> Tool dependency mktools-[0-9]*: found mktools-20220614
=> Tool dependency nbpatch-[0-9]*: found nbpatch-20151107
=> Tool dependency cwrappers>=20150314: found cwrappers-20220403
=> Full dependency fortune-strfile>=0: found fortune-strfile-0
===> Skipping vulnerability checks.
WARNING: No /opt/pkg/.pkgdb/pkg-vulnerabilities file found.
WARNING: To fix run: `/opt/pkg/sbin/pkg_admin -K /opt/pkg/.pkgdb fetch-pkg-vulnerabilities'.
===> Overriding tools for fortune-19970829
===> Extracting for fortune-19970829
===> Patching for fortune-19970829
=> Applying pkgsrc patches for fortune-19970829
===> Creating toolchain wrappers for fortune-19970829
===> Configuring for fortune-19970829
===> Building for fortune-19970829
cd fortune && /opt/pkg/bin/bmake CC='clang'  CFLAGS='-O2 -DFORTDIR="\"/opt/pkg/share/games/fortune\"" -DOFFDIR="\"/opt/pkg/share/games/fortune/off\"" -DHAVE_REGEX_H -DPOSIX_REGEX -I../util'	 LDFLAGS='-L/opt/pkg/lib' LIBS=''
clang -O2 -DFORTDIR="\"/opt/pkg/share/games/fortune\"" -DOFFDIR="\"/opt/pkg/share/games/fortune/off\"" -DHAVE_REGEX_H -DPOSIX_REGEX -I../util  -c fortune.c
fortune.c:542:6: warning: add explicit braces to avoid dangling else [-Wdangling-else]
> Generating post-install file lists
=> Checking file-check results for fortune-19970829
=> Creating binary package /Users/carlosneira/Projects/OSS/pkgsrc/games/fortune/work/.packages/fortune-19970829.tgz
===> Building binary package for fortune-19970829
=> Creating binary package /Users/carlosneira/Projects/OSS/pkgsrc/packages/All/fortune-19970829.tgz
=> Becoming ``root'' to make su-real-package-install (/usr/bin/sudo)
===> Installing binary package of fortune-19970829
pkg_add: package `fortune-19970829' already recorded as installed
=> Dropping ``root'' privileges.

Now the package has been build and installed to /opt/pkg/bin/fortune

$ fortune
A mighty creature is the germ,
Though smaller than the pachyderm.
His customary dwelling place
Is deep within the human race.
His childish pride he often pleases
By giving people strange diseases.
Do you, my poppet, feel infirm?
You probably contain a germ.
                -- Ogden Nash

Now is just a matter to search for packages available in pkgsrc to replace the ones in homebrew (except propietary applications). To find which package provides a binary, for example, I want to know if there is a pkgsrc package that provides the pdflatex binary, that I used to generate my documents, the easiest way to do it should be, to go into the pkgsrc folder and just run:

git grep bin/pdflatex -- '*/PLIST*'

That results in print/tex-latex-bin/PLIST:bin/pdflatex, so now typing

pkgin in tex-latex-bin

Should get us the needed package, if not, we need to build it ourselves as done with the fortune package. For latex,the package that I needed was texlive-collection-latex, the reason is that org-mode uses to export to latex then convert to pdf requires more than one package, so this one has them all.

KalundborgChurch (1837).png

Figure 1: Kalundborg Church (1837)