Skip to content

Make proprietary drivers optional (1/2): pmbootstrap changes

Created by: ollieparanoid

Here are the changes necessary in pmbootstrap to make proprietary software installed onto the device (firmware and userspace drivers) optional (#756 (closed)). To full close the issue, we need to apply this concept to all device packages we already have in a follow-up PR.

Example

$ pmbootstrap init ... Device [qemu-amd64]: example-example This device has proprietary components, which trade some of your freedom with making more peripherals work. We would like to offer full functionality without hurting your freedom, but this is currently not possible for your device. device-example-example-nonfree-firmware: Modem, Wifi, accelerated GPU Enable this package? (y/n) [y]: device-example-example-nonfree-userland: accelerated GPU Enable this package? (y/n) [n]:

The example-example device package would look like this:

# Reference: <https://postmarketos.org/devicepkg>
pkgname="device-example-example"
...
subpackages="$pkgname-nonfree-firmware:nonfree_firmware $pkgname-nonfree-userland:nonfree_userland"

build() {
	devicepkg_build $startdir $pkgname
}

package() {
	devicepkg_package $startdir $pkgname
}

nonfree_firmware() {
	depends="linux-firmware-brcm ..."
	pkgdesc="Modem, Wifi, accelerated GPU"
	mkdir "$subpkgdir"
}

nonfree_userland() {
	depends="..."
	pkgdesc="accelerated GPU"
	mkdir "$subpkgdir"
}

Note on building dependencies

This was a bit unexpected for me, but this is how Alpine's abuild works: We can override the depends in the subpackages, and abuild does not try to install them as dependencies before building the package/subpackage (even in pmbootstrap build --strict mode where we let abuild install the dependencies). In other words, it is possible to specify dependencies on non-free programs without requiring them at build time to build the device package. So when someone chooses the libre way, the non-free packages will not only be out of the installed system, they will not even get built. The same goes for the binary repository (where we don't host proprietary packages (see #797 (closed)): When compiling the device packages, the firmware packages don't get dragged in.

Changes

  • New config file options nonfree_firmware and nonfree_userland, which we ask for during "pmbootstrap init" if there are non-free components for the selected device.
  • We find that out by checking the APKBUILD's subpakages: The non-free packages are called $pkgname-nonfree-firmware and $pkgname-nonfree-userland.
  • During "pmbootstrap init" we also show the pkgdesc of these subpackages. Parsing that is implemented in pmb.parse._apkbuild.subpkgdesc(). It was not implemented as part of the regular APKBUILD parsing, as this would need a change in the output format, and it is a lot less code if done like in this commit.
  • pmb/parse/apkbuild.py was renamed to _apkbuild.py, and pmb/install/install.py to _install.py: needed to call the function in the usual way (e.g. pmb.parse.apkbuild()) but still being able to test the individual functions from these files in the test suite. We did the same thing for pmb/build/_package.py already.
  • Install: New function get_nonfree_packages() returns the non-free packages that will be installed, based on the user's choice in "pmbootstrap init" and on the subpackages the device has.
  • Added test cases and test data (APKBUILDs) for all new code, refactored test/test_questions.py to have multiple functions for testing the various questions / question types from "pmbootstrap init" instead of having it all in one big function. This allows to use another aport folder for testing the new non-free related questions in init.

Testing

Preparation

$ pmbootstrap init
...
Device [qemu-amd64]: nonfree-firmware-and-userland
You are about to do a new device port for 'nonfree-firmware-and-userland'
Continue? (y/n) [y]:
...
$ cp test/testdata/init_questions_device/aports/device/device-nonfree-firmware-and-userland/APKBUILD aports/device/device-nonfree-firmware-and-userland/APKBUILD
$ pmbootstrap checksum device-nonfree-firmware-and-userland

Actual testing

During install it should only try to install the non-free packages you've chosen in init:

$ pmbootstrap init
$ pmbootstrap install

Merge request reports