Pkgsrc - Packaging blogc
As mentioned in my previous post, I am trying to get back into packaging and back to some BSD roots. One package I meant to try to package a long time ago for pkgsrc is blogc. It is a nice little static site generator I found awhile ago that this blog has uses on and off over the years. Every year, I end up redoing my blog and just recently I re-did it with blogc.
Nothing too fancy with blogc. It is written in C, and uses make to generate the site. Pretty easy to compile and pretty fast. I also liked the idea of it being in C in case I ever wanted to extend or modify it. Which I may here soon. Otherwise, its a no thrills static site generator.
So, on to trying to package it. I will be referencing the Pkgsrc documentation as I do that.
First step is findind a home for the package. If you look at pkgsrc, and other trees, packages are organized in a hierarchy of directories. Each has their own way of doing it, however NetBSD and FreeBSD are very similar where they use categories. Ravenports is probably one of the more interesting ones where packages are split in directories names 00 to FF to represent 0-256 and it does it by hasing the name of the package. In order to find blogc's home, it might be best to see where other static site generators are.
~/sources/pkgsrc/ [pkgsrc] ./pkglocate jekyll
www/ruby-jekyll-minima/DESCR:(and first) theme. It's what you get when you run `jekyll new`.
Jekyll being a static site generator and present in the tree, I can see that it lives in the www/ directory, so this is where blogc should run.
NetBSD also has an interesting tool to help get started called url2pkg. However, it is not included with the bootsrap. So I need to build it and installed.
./pkglocate url2pkg
That above will tell me that it is located in pkgtools/, so now a quick (well outside of compile times)
cd pkgtools/url2pkg
sudo bmake install
Although, I should probably install the pkg_developer meta package. As these will include some other handy tools like pkglint which can help identify issues before trying to contribute upstream.
cd meta-pkgs/pkg_developer
sudo bmake install
Before I go any further though, here are the sites for blogc.
Now with that out of the way, I will go into www/ and utilize the url2pkg program to get started as that is what it mentions in the documentation.
~/sources/pkgsrc/www/ [www] url2pkg https://github.com/blogc/blogc/releases/download/v0.20.1/blogc-0.20.1.tar.gz
===> Cleaning for blogc-0.20.1
=> Bootstrap dependency digest>=20211023: found digest-20220214
=> Fetching blogc-0.20.1.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 494k 100 494k 0 0 428k 0 0:00:01 0:00:01 --:--:-- 676k
=> Checksum BLAKE2s OK for blogc-0.20.1.tar.gz
=> Checksum SHA512 OK for blogc-0.20.1.tar.gz
===> Installing dependencies for blogc-0.20.1
=> Tool dependency mktools-[0-9]*: found mktools-20250213
=> Tool dependency cwrappers>=20150314: found cwrappers-20220403
===> 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 blogc-0.20.1
===> Extracting for blogc-0.20.1
===> Cleaning for blogc-0.20.1
=> Bootstrap dependency digest>=20211023: found digest-20220214
=> Checksum BLAKE2s OK for blogc-0.20.1.tar.gz
=> Checksum SHA512 OK for blogc-0.20.1.tar.gz
===> Installing dependencies for blogc-0.20.1
=> Tool dependency mktools-[0-9]*: found mktools-20250213
=> Tool dependency cwrappers>=20150314: found cwrappers-20220403
===> 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 blogc-0.20.1
===> Extracting for blogc-0.20.1
Remember to run pkglint when you're done.
See ../../doc/pkgsrc.txt to get some help.
Now there should be a www/blogc directory.
cd blogc
~/sources/pkgsrc/www/blogc/ ls
DESCR distinfo Makefile PLIST work
This provides the basic skeleton of a package for me to then work on. Howver, blogc is a fairly simple package. I won't use ninja to build it since it isn't necessary. Instead, I will just build it without touching anything yet.
~/sources/pkgsrc/www/blogc/ bmake
And the package builds. It doesn't really require any dependencies other than make and a good old C make compiler and things that are pretty standard on a UNIX system. One of the reasons I like this static site generator. So from here, it should mostly be filling in the information.
Below is the Makefile after changes, removing the contact information for the package.
# $NetBSD$
DISTNAME= blogc-0.20.1
CATEGORIES= www
MASTER_SITES= ${MASTER_SITE_GITHUB:=blogc/}
GITHUB_PROJECT= blogc
GITHUB_RELEASE= v0.20.1
MAINTAINER=
HOMEPAGE= https://blogc.rgm.io/
COMMENT= Blog compiler
LICENSE= modified-bsd
GNU_CONFIGURE= yes
.include "../../mk/bsd.pkg.mk"
Following along with the documentation, I should check with pkglint to see if there are any errors, warnings or hints.
I now have really two steps. Pkglint highlights one and that is the DESCR file. This file is the long description of the package. url2pkg appears to have dumped the readme contents into the file and that isn't gonna do. First, it has a bunch of irrelavent stuff about building the package, the port is gonna do that for users. Pkgsrc is also picky about line sizes, the file needs to be work wrapped to 80 characters per line.
After giving an appropriate description in the description file the pkglint is happy with, I need to take care of the PLIST file. This is a file that contains all the files that the package should contain. This usually at the least consists of the binary, but it can have much more. If there are man pages and I want those man pages installed, they should be listed in the PLIST. Any other resource files like a default configuration. Luckily, pkgsrc has some tools to help get started.
Following the guide, I can run the bmake print-PLIST and this will give an idea of what should be in there. Then going off the guide, we can use as a starting point but running bmake print-PLIST > PLIST to take the contents of the bmake command and output them to the PLIST file.
Afterwards, check pkglint and follow the instructions to bmake install, bmake deinstall, and bmake install again. Afterwards it says to run bmake clean update and then to check pkglint again.
After all of that, I can finally see the following
~/sources/pkgsrc/www/blogc/ whereis blogc
blogc: /opt/pkg/bin/blogc /opt/pkg/man/man1/blogc.1
The package was installed. I can now run it from the command line and verify the binary works.o
Finally, I can now look at upstreaming this package.
This is where I hit a bit of a bump. At first, my though was that maybe I can just generate a diff and email into the mailing list with the patch and ask for a review. However, I hadn't seen any examples of anyone doing that. Granted, I only looked at messages on the mailing list going back a few days. So hardly conclusion. Instead, I looked at pkgsrc-wip and decided to go that route. I cloned the pkgsrc-wip repository with git in the pkgsrc directory I cloned with cvs. Moved the package from www/ into pkgsrc-wip and went through the process to have commit access to pkgsrc-wip. If you ask and provide a public key, they give it to you. Got it committed and pushed it.
Following that, sent an email to the tech-pkg mailing list asking for a code review and there is where I am.