pkgsrc on SmartOS - zone creation and basic builds
Our goal at Joyent is that our binary packages for SmartOS fulfill all of our users’ needs. This isn’t always possible, however - users may want packages we do not yet provide, or build with different options.
To satisfy those demands, it should instead be reasonably straight-forward for users to build their own packages, and this guide hopefully provides all the information for them to do just that.
This is the first in a series of posts, and will focus on getting pkgsrc set up in a clean SmartOS zone and then building some packages. Other posts currently available in the series are:
Create a build machine
For this guide I use a
base:1.8.1 SmartMachine, but any recent dataset should
be fine, and it shouldn’t matter whether it’s 32-bit or 64-bit.
If you are a Joyent customer:
If you are using SmartOS:
Put the above json into a file, you may want to tweak some values, then
Finally, log into the freshly-created zone.
First thing you’ll need in the zone are build tools, so:
We maintain a fork of pkgsrc on github, which includes some additional SmartOS fixes and improvements, so we recommend using that rather than upstream.
I put everything under
/content, adjust to your own tastes.
Next, check out the latest stable branch. Our naming scheme is
joyent/release/YYYYQQ, and the latest branch at time of writing is
If you want to be particularly adventurous, you could checkout
trunk and get
the very latest pkgsrc code, however pkgsrc is a very fast-moving target and
you may run into unexpected breakages, and you will certainly end up rebuilding
packages very often.
pkgsrc-wip is a set of additional
work-in-progress packages for pkgsrc, and can be useful for trying out the
latest packages. It is designed to be extracted directly into pkgsrc, and
we maintain a git submodule of it in our release trees, so all you need to
do, assuming you are using a
joyent/release/* tree, is:
This will also get you a
joyent/ directory which is a module of our
pkgsrc-joyent tree of additional
If you are on
trunk or another tree which does not have the
you can fetch it manually with:
The primary method of configuring pkgsrc is through the
/opt/local/etc/mk.conf file. The base image comes with one populated to
handle the basic layout, but there are some additional basic variables you may
want to set prior to building your first package:
DISTDIRdetermines where source tarballs are stored, default
PACKAGESis where pkgsrc will store binary packages it has built, default
WRKOBJDIRis where pkgsrc performs the builds, default
SKIP_LICENSE_CHECKshould both be set to
yesif you just want the package to be built, and don’t care whether it is currently vulnerable to security issues or is released under a specific license.
MAKE_JOBSdetermines the argument to
make -j, i.e. the number of concurrent make threads, default 1.
FETCH_USINGsets the default program to use for fetching source code, defaulting to an in-tree version of NetBSD’s ftp program. Setting this to
curlon SmartOS, which is included in the base platform, will avoid any dependencies.
BINPKG_SITESis a URL pointing to binary packages which can be used by this tree rather than building everything from source, and settings
bin-installenables using these binary packages as dependencies.
Thus, this is how I would configure
Building a package
Ok, let’s get started and build a package. pkgsrc is organised into
categories, with all packages following the
layout, and everything is driven with
bmake, the BSD implementation of
make(1). I’m going to choose
nmap as an example, as it will show a couple
of things I want to cover.
First, finding it. I tend to just do a simple:
If you want a more featured search, you can do:
though the first time you run this it creates the
INDEX file it requires, and
that can take a long time. Another option is to use the
pkgsrc.se web interface.
Once you have found the package,
cd into the package directory.
Next, let’s look at any options the package supports.
If the package supports build options, as
net/nmap does, you’ll see
The place to configure these options is again in
if you want to enable ndiff support for example, then you’d add this to
show-options command should now print:
And finally, we can go ahead and build the package. The output from this will
be long, so you may want to
tee it to a file for reviewing:
Assuming this completes ok, you should note the main stages that make up a package build:
bootstrap-dependscomes first, and installs all the dependencies required for pkgsrc to get started.
pkgtools/digestis required to calculate the
RMD160checksums of the source tarball. If we hadn’t specified
mk.confthen it’s likely that
net/tnftpwould have been pulled in during this stage too and used to fetch the source.
checksumthen run to download the source tarball for this particular package, and then verify the checksum matches that stored by pkgsrc, to ensure it was downloaded from a good source:
dependsthen installs all packages required for both build and runtime for the package in question:
patchthen unpack the source and apply any pkgsrc patches to the package. The patches are located in the
patches/sub-directory for each package:
- The bulk of the build is performed by
buildwhich for most software will consist of
./configure && make.
- The final steps are
packagedoes a fake install of the package to a temporary install directory and creates a binary package from that, and then
installinstalls that binary package into place:
You can now verify it is installed, and start using your new software:
Once everything is working, you may want to clean up the build areas. The pkgsrc way of doing this is:
However, if you just want to blow everything away without prejudice, you can
simply remove everything under
WRKOBJDIR, so in my case:
This should hopefully be enough to get you started. Over the next few posts we’ll investigate some more advanced topics. Stay tuned!
- 16 Jul 2015 » Reducing RAM usage in pkgin
- 03 Mar 2015 » pkgsrc-2014Q4: LTS, signed packages, and more
- 06 Oct 2014 » Building packages at scale
- 04 Dec 2013 » A node.js-powered 8-bit CPU - part four
- 03 Dec 2013 » A node.js-powered 8-bit CPU - part three
- 02 Dec 2013 » A node.js-powered 8-bit CPU - part two
- 01 Dec 2013 » A node.js-powered 8-bit CPU - part one
- 21 Nov 2013 » MDB support for Go
- 30 Jul 2013 » What's new in pkgsrc-2013Q2
- 24 Jul 2013 » Distributed chrooted pkgsrc bulk builds
- 07 Jun 2013 » pkgsrc on SmartOS - creating new packages
- 15 Apr 2013 » What's new in pkgsrc-2013Q1
- 19 Mar 2013 » Installing SVR4 packages on SmartOS
- 27 Feb 2013 » SmartOS is Not GNU/Linux
- 18 Feb 2013 » SmartOS development preview dataset
- 17 Jan 2013 » pkgsrc on SmartOS - fixing broken builds
- 15 Jan 2013 » pkgsrc on SmartOS - zone creation and basic builds
- 10 Jan 2013 » Multi-architecture package support in SmartOS
- 09 Jan 2013 » Solaris portability - cfmakeraw()
- 08 Jan 2013 » Solaris portability - flock()
- 06 Jan 2013 » pkgsrc-2012Q4 illumos packages now available
- 23 Nov 2012 » SmartOS and the global zone
- 24 Oct 2012 » Setting up Samba on SmartOS
- 10 Oct 2012 » pkgsrc-2012Q3 packages for illumos
- 23 Aug 2012 » Creating local SmartOS packages
- 10 Jul 2012 » 7,000 binary packages for OSX Lion
- 09 Jul 2012 » 9,000 packages for SmartOS and illumos
- 07 May 2012 » Goodbye Oracle, Hello Joyent!
- 13 Apr 2012 » SmartOS global zone tweaks
- 12 Apr 2012 » Automated VirtualBox SmartOS installs
- 30 Mar 2012 » iptables script for Debian / Ubuntu
- 20 Feb 2012 » New site design
- 11 Jan 2012 » Set up anonymous FTP upload on Oracle Linux
- 09 Jan 2012 » Kickstart Oracle Linux in VirtualBox
- 09 Jan 2012 » Kickstart Oracle Linux from Ubuntu
- 22 Dec 2011 » Last day at MySQL
- 15 Dec 2011 » Installing OpenBSD with softraid
- 21 Sep 2011 » Create VirtualBox VM from the command line
- 14 Sep 2011 » Creating chroots for fun and MySQL testing
- 30 Jun 2011 » Graphing memory usage during an MTR run
- 29 Jun 2011 » Fix input box keybindings in Firefox
- 24 Jun 2011 » How to lose weight
- 23 Jun 2011 » How to fix stdio buffering
- 13 Jun 2011 » Serving multiple DNS search domains in IOS DHCP
- 13 Jun 2011 » Fix Firefox URL double click behaviour
- 20 Apr 2011 » SSH via HTTP proxy in OSX
- 09 Nov 2010 » How to build MySQL releases
- 29 Apr 2010 » 'apt-get' and 5,000 packages for Solaris10/x86
- 16 Sep 2009 » ZFS and NFS vs OSX
- 12 Sep 2009 » pkgsrc on Solaris
- 09 Dec 2008 » Jumpstart from OSX
- 31 Dec 2007 » Set up local caching DNS server on OSX 10.4