January 16, 2023

Kyu networking -- a diversion - how to install and use NetBSD pkgsrc

I have NetBSD running now on my Orange Pi board and almost the first things I want to know how to do is to install some missing packages. As this post suggests, this is less than obvious to a new user: Somewhere there is a thing called "The NetBSD Guide" with a section (5.15) entitled "installing additional software". I scan section 5.15 and do as they prescribe:
PKG_PATH="https://cdn.NetBSD.org/pub/pkgsrc/packages/NetBSD/$(uname -p)/$(uname -r | cut -d_ -f1)/All"
echo $PKG_PATH
https://cdn.NetBSD.org/pub/pkgsrc/packages/NetBSD/earmv7hf/9.3/All
export PKG_PATH
Then I try one:
pkg_add -v ruby
pkg_add -v python
pkg_add: no pkg found for 'python', sorry.
Now this:
armv7# pkg_add ruby
pkg_add: Can't process https://cdn.NetBSD.org:443/pub/pkgsrc/packages/NetBSD/earmv7hf/9.3/All/ruby*: Unknown HTTP error
pkg_add: no pkg found for 'ruby', sorry.
pkg_add: 1 package addition failed
armv7# pkg_add ruby31
pkg_add: Can't process https://cdn.NetBSD.org:443/pub/pkgsrc/packages/NetBSD/earmv7hf/9.3/All/ruby31*: Unknown HTTP error
pkg_add: no pkg found for 'ruby31', sorry.
pkg_add: 1 package addition failed
armv7# pkg_add ruby31_3.1.3
pkg_add: Can't process https://cdn.NetBSD.org:443/pub/pkgsrc/packages/NetBSD/earmv7hf/9.3/All/ruby31*: Unknown HTTP error
pkg_add: no pkg found for 'ruby31_3.1.3', sorry.
pkg_add: 1 package addition failed
Not very gratifying. I try this:
pkg_add pkgin
pkg_add: no pkg found for 'pkgin', sorry.
This seems completely and utterly broken.

I use my browser to navigate to:

I see a myriad of .tgz files, including "ruby31-3.1.2.tgz"

But note the error message above. It gives a string ending in "*" and indeed when I feed a URL like this to my browser It gives me a 404 error. No web server is going to accept a URL like that.

How to make this work

I posted to the netbsd "pkgsrc" list and got a bunch of information. One guy explained the problem in this way:
libfetch in base doesn't support SNI (virtual host selection with TLS).

This is the result of an unhandled `421 Misdirected Request' error.
These days, most HTTP servers are hosted by CDNs and they expect
an HTTP SNI (Server Name Indication) to be sent by the client when
negotiating HTTPS requests.
I have no idea what this means or why I should care or who should take care of this. The suggestion is to us http: and not https: OK, so I do this:
PKG_PATH=http://cdn.NetBSD.org/pub/pkgsrc/packages/NetBSD/earmv7hf/9.3/All
export PKG_PATH
Now, just as a quick experiment, I try:
pkg_add ruby
pkg_add: Warning: package `ruby-3.1.2' was built for a platform:
pkg_add: NetBSD/earmv7hf 9.0 (pkg) vs. NetBSD/earmv7hf 9.3 (this host)
That is progress of a sort. I seem to be getting this same warning for a bunch of ruby related packages. And it does take a long time. But it seems to work.

Whatever shell they ship with NetBSD is a piece of crap, so:

pkg_add bash
This is quick and easy. Now I have bash -- hooray!

I am also instructed:

Ideally, you install pkgin over http, then use pkgin for installing the rest from binary packages. It does proper HTTPS, better dependency resolution and more.
So I do "pkg_add pkgin". And after that I do:
pkgin install python
But this works:
pkgin install python39
installing python39-3.9.13...
installing libuuid-2.32.1nb1...
pkg_install warnings: 0, errors: 0
pkgin avail >pkg.list
This seems to work, but typing python or python3 or python39 afterwards does not work. So, if it is installed, it is no good to me, or so it seems. No, wait -- I found it in /usr/pkg/bin as "python3.9"

Some of the list replies instruct me to file a PR (whatever that is) about my initial problems using pkgsrc and pkg_add.


Have any comments? Questions? Drop me a line!

Kyu / [email protected]