Nanobsd and packages

From: Stefan Hegnauer <>
Date: Sat, 29 Jul 2023 18:24:14 UTC
Up to stable/13 of about March this year - and for the last two decades
or so - using packages in nanobsd(8) was pretty straight forward: you
needed a directory with packages to install using the included
'cust_pkgng' helper function, and one of the packages had to be the
'pkg-x.y.z' package to bootstrap the package system during the nanobsd
creation stage.

Not anymore with stable/13.2 of about July 24 or later. I did not try to
bisect to find out when and what changed. This is rather outside of my
comfort zone so there may be a better way / better explanation, but
these are my findings so far:
- to bootstrap pkg(8) without resorting to the internet (which fails for
me in  a chroot environment) the associated package *must* be named
'pkg.txz'. Nothing else will do.
- there cannot be a path in front of the package name, i.e.
'/_.p/pkg.txz' as used by nanobsd(8) does not work anymore.
- alas, nanobsd(8) cannot install packages in the old way as the
bootstrapping fails.

To get around this the following patch seems to work for me:

    diff --git a/tools/tools/nanobsd/
    index 45d9fe44c650..9a654e6d9d5b 100755
    --- a/tools/tools/nanobsd/
    +++ b/tools/tools/nanobsd/
    @@ -774,6 +774,7 @@ cust_pkgng ( ) (
                     echo "FAILED: need a pkg/ package for bootstrapping"
                     exit 2
    +        mv ${NANO_PACKAGE_DIR}/${_NANO_PKG_PACKAGE}

             # Mount packages into chroot
             mkdir -p ${NANO_WORLDDIR}/_.p
    @@ -783,7 +784,7 @@ cust_pkgng ( ) (
             trap "umount ${NANO_WORLDDIR}/dev; umount
    ${NANO_WORLDDIR}/_.p ; rm -xrf ${NANO_WORLDDIR}/_.p" 1 2 15 EXIT

             # Install pkg-* package
    -       CR "${PKGCMD} add /_.p/${_NANO_PKG_PACKAGE}"
    +       CR "cd /_.p ; ${PKGCMD} add pkg.txz"

                     # Expand any glob characters in pacakge list

-- stefan