Add packages to the nerves firmware

Hello,

I have a project with a Phoenix based UI, and one of the requirements is to get a PDF report.

I’m using Raspberry Pi 3, and I’ve read https://hexdocs.pm/nerves/systems.html#customizing-your-own-nerves-system

when running make menuconfig I see some packages that can be installed.

In the case I need wkhtmltopdf (required for many elixir libraries), which is not in the list, do I have to create it somehow for buildroot?

using ssh nerves.local I can get into Elixir session, but is it possible to ssh into a shell?

I’m very confused with this part of Nerves System, buildroot, busybox…

Thanks!

I’ve never looked for this package, but you may have to add it manually. Nerves supports this and there is a great talk from last year’s ElixirConf about it. I’ll try to find it if you would like.

We had a sort of shell a while back. You can add the dep from here but it isn’t your normal shell. It is usually easier to do cmd("echo hello world") but sometimes you need a bit more control in which case i do usually: _ = Nerves.Runtime.cmd("echo", ["hello", "world"], :return). The only issue with those two approaches is when you need something that does fancy stuff to the terminal such as top. (which is disabled in the default systems iirc). What are you trying to do in a regular shell? maybe i can recommend an approach.

1 Like

I just had a look at the wkhtmltopdf repo
It looks like it require QT + webkit for some reason. While you can enable both of those thing in buildroot, it seems a little strange to me…

This is one of those things that is surprisingly hard and a reason to seriously thank package maintainers. There are several issues: Qt and Webkit have a lot of dependencies, Qt switched to Chromium for their web engine a while back so there’s more effort to get their Webkit integration, and the main one is that wkhtmltopdf hasn’t already been ported to Buildroot. If the last one weren’t the case, then this would be soooo much easier.

Here’s what I’d try:

  1. See if someone has built a static linked binary of wkhtmltopdf for ARM. If yes, then try including that in a priv directory or a rootfs_overlay. If you can run it and it doesn’t crash immediately, you’re probably good.
  2. See if you can upload the data to a server for pdf conversion.
  3. Port wkhtmltopdf to plain-vanilla Buildroot (no Nerves). Try setting the “all static libraries” option and see if you can generate a static wkhtmltopdf binary. I.e. make option #1.
  4. If there are issues making a static version of wkhtmltopdf, then try making one that uses dynamic libraries in plain-vanilla Buildroot. I’m certain this will work. Once you do this, the path to integrating it with Nerves will make a lot more sense.

I’m not going to lie, there’s some work here if #1 or #2 don’t pan out. I recently had to deal with this and ended up using a Qt PDF report generator (NCReport). That solution has some different challenges, but is much faster than wkhtmltopdf if you are running on a slow processor.

Good luck, and please let us know how you end up.

4 Likes

Thanks a lot for your answer @fhunleth!

Hello Frank @fhunleth, I am starting to build a nerves project where I want to generate PDFs and then print them. Building my own buildroot with CUPS enabled.
I have no idea how to include NCReport. It is not in buildroot. Do you have any further information you can point me to?
Thank you very much

I’m not sure how well this will work on nerves, but I found https://weasyprint.org/ to be a good way of converting html to pdfs compared to wkhtmltopdf. Not sure how many native dependencies it has, but python should be easier than QT or webkit.

@cokron It has been a LONG time since I’ve used NCReport.

You’ll have to fork whatever Nerves system that you’re using and create a package/ncreport directory where you’ll put the Buildroot recipe files for building NCReport. You’ll also need to add a Config.in with the contents source "$NERVES_DEFCONFIG_DIR/package/ncreport/Config.in"

The Buildroot docs describe what to put in the Config.in and ncreport.mk files that you’ll need in the package/ncreport directory.

Here’s what I had from an old project that used NCReport. The project is OLD, so please, please refer to the Buildroot docs to double check it. I don’t remember why I didn’t use Buildroot’s QMake infrastructure, but maybe it didn’t exist back then. If I were to do this today, I’d use it .

Config.in

config BR2_PACKAGE_NCREPORT
        depends on BR2_PACKAGE_QT
        select BR2_PACKAGE_QT_SCRIPT
        select BR2_PACKAGE_QT_XML
        bool "ncreport"
        help
          NCReport is a lightweight, fast, multi-platform and easy
          to use report generator tool written in C++ based on the
          Qt Application framework

ncreport.mk

################################################################################
#
# ncreport
#
################################################################################

NCREPORT_VERSION = <fill in>
NCREPORT_SITE = git@github.com:fork/NCReport.git
NCREPORT_SITE_METHOD = git
NCREPORT_DEPENDENCIES = qt

NCREPORT_INSTALL_STAGING = YES

define NCREPORT_CONFIGURE_CMDS
        cd $(@D)/src/ncreport && $(QT_QMAKE) -r "DEFINES += LABEL_QT_TRANSLATOR_INTEGRATION" "DISABLED_FEATURES = SVG SQL PREVIEW_WINDOW PRINT_DIALOG CURSOR EMAIL TABLE_VIEW" -after "target.path=$(STAGING_DIR)/usr/lib" -after "headers.path=$(STAGING_DIR)/usr/include/NCReport" -after "documentation.path=$(STAGING_DIR)/usr/doc/NCReport" -after "reports.path=$(STAGING_DIR)/usr/reports"  ncreport.pro
endef

define NCREPORT_BUILD_CMDS
        $(MAKE) -C $(@D)/src/ncreport
endef

define NCREPORT_INSTALL_STAGING_CMDS
        $(MAKE) -C $(@D)/src/ncreport install
endef

define NCREPORT_INSTALL_TARGET_CMDS
        cp -dpf $(STAGING_DIR)/usr/lib/libNCReport.so.* $(TARGET_DIR)/usr/lib
endef

$(eval $(generic-package))

I can’t help with CUPS. I don’t often have to interface with printers and when I do, it seems like there’s some easier non-generic interface that I can use.

1 Like