pkgsrc survival guide
Contents
pkgsrc is NetBSD's ports system. But it's also cross-platform, available on Mac and Linux. It also support unprivileged use. This is a quick reference for it.
First let's make a few decisions about the installation locations:
1 | # Location of the pkgsrc |
BOOTSTRAPPING
First download pkgsrc - it's a collection of configurations instructing how to download and build different packages.
1 | wget https://ftp.netbsd.org/pub/pkgsrc/stable/pkgsrc.tar.gz |
pkgsrc needs to be bootstrapped on the target machine where packages are to be built. The bootstrapping process builds the necessary tools pkgsrc will be using later on. We will focus on unprivileged use, since that's more fun and less covered by documents everywhere else:
1 | cd $PKGSRC_DIR/bootstrap |
Finally we need to export PATH and MANPATH to include $PKG_DIR.
PARALLEL BUILD
1 | MAKE_JOBS=<num_cpus> bmake |
USEFUL TARGETS, GETTING HELP
1 | bmake help |
See pkgsrc targets The following targets may be useful to invoke from keyboard:
dependsto build and install dependenciesfetchto fetch distribution file(s)checksumto fetch and check distribution file(s)extractto look at unmodified sourcepatchto look at initial sourceconfigureto stop after configure stageallor build to stop after build stagestage-install to install under stage directorytestto run package's self-tests, if any exist and supportedpackageto create binary package before installing itreplaceto change (upgrade, downgrade, or just replace) installed package in-placedeinstallto deinstall previous packagepackage-install to install package and build binary packageinstallto install packagebin-installto attempt to skip building from source and use pre-built binary packageshow-dependsprint dependencies for buildingshow-optionsprint available options from options.mk
Cleanup targets (in separate section because of importance):
clean-depends to remove work directories for dependenciescleanto remove work directorydistcleanto remove distribution file(s)package-cleanto remove binary package
The following targets are useful in development and thus may be useful for an advanced user:
makesumto fetch and generate checksum for distributed file(s)makepatchsumto (re)generate checksum for patchesmakedistinfoto (re)generate distinfo file (creating checksums for distributed file and patches)mpsshort for makepatchsummdishort for makedistinfoprint-PLISTto attempt to generate correct packaging list (NB! It helps, but it doesn't eliminate manual work.)
USEFUL PKG TOOLS
1 | (cd pkgtools && bmake install) |
DISTFILES, FETCHING ETC
1 | # generate sh script which downloads distfiles when run |
BUILD OPTIONS
$PKG_DIR/etc/mk.conf is where to set build options. For specific package, add line:
1 | PKG_OPTIONS.<pkg_name>+= <option> |
bmake show-all is helpful in discovering available build options, and what are enabled/disabled.
USEFUL ENVIRONMENT VARS
These can be specified in mk.conf, or on each build instance:
1 | DISTDIR=... bmake |
DISTDIR: directory where to look for distfilesFETCH_USING: the program for fetching (can set to wget)
TROUBLESHOOTING
1 | # Prints detailed build command |
BUILD PHASES
https://www.netbsd.org/docs/pkgsrc/build.html
- The fetch phase
- The checksum phase
- The extract phase
- The patch phase
- The tools phase
- The wrapper phase
- The configure phase
- The build phase
- The test phase
- The install phase
- The package phase
Use pkgsrc along side Joyent pkgsrc binary distribution
Sat May 28 14:58:51 PDT 2022
- Install Joyent's pkgsrc binary distribution (this must be installed at the pre-determined location. E.g., for MacOS, at
/opt/pkg) - At any location, git clone pkgsrc source repo (e.g., clone into
~/work/pkgsrc) - To build from source, just
cd ~/work/pkgsrc/net/sshping && bmake installbmakeis from/opt/pkg/bin. Installed package will also go there.
Since this installs to system location, there maybe frequent prompt for root
password. Use this patch can fix it. Note that it assumes you have sudo
already installed at /usr/bin/sudo. Otherwise, follow the pkgsrc
FAQ (use pkgsrc to install
sudo first):
1 | --- /tmp/mk.conf 2022-05-28 15:03:49.000000000 -0700 |
Rebuild only changed files
There's the $WRKDIR/.build_done cookie that skips build. So:
1 | bmake rebuild |