Issues compiling a nerves custom system with v1.29.1 (buildroot 2024.08.3)

Hello everyone, I believe this issue is more related to Buildroot version (2024.08.3) than to Nerves itself, but I would still like to hear your thoughts.

I am trying to upgrade my custom_system based on rpi4 from version 1.27 to 1.29.1. However, when I try to compile, I get the following error:

** (Mix) Nerves encountered an error while constructing the artifact
/home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/packages/cloudflared/cloudflared.mk:19: *** Package 'cloudflared' defined a second time in '/home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/packages/cloudflared'; previous definition was in 'package/cloudflared'.  Stop.
make: *** [Makefile:23: _all] Error 2

It seems that in this new Buildroot version, the package I had manually added was included by default, causing a conflict. To resolve this, I had to rename the package (cloudflared → cloudflared-bin, since Buildroot does not have the latest version available). Everything seemed to work fine until another error appeared with the mosquitto package:

>>> mosquitto 2.0.19 Extracting
gzip -d -c /home/alde/.nerves/dl/mosquitto/mosquitto-2.0.19.tar.gz | /home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/.nerves/artifacts/valiot_system_rpi4-portable-1.29.1-valiot.16/host/bin/tar --strip-components=1 -C /home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/.nerves/artifacts/valiot_system_rpi4-portable-1.29.1-valiot.16/build/mosquitto-2.0.19  --no-same-owner -xf -
>>> mosquitto 2.0.19 Patching

Applying 0001-Revert-Fix-NetBSD-build.patch using patch: 
The next patch would create the file lib/dummypthread.h,
which already exists!  Skipping patch.
1 out of 1 hunk ignored
patching file lib/handle_pubackcomp.c
Reversed (or previously applied) patch detected!  Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file lib/handle_pubackcomp.c.rej
patching file lib/mosquitto_internal.h
Reversed (or previously applied) patch detected!  Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file lib/mosquitto_internal.h.rej
patching file lib/packet_mosq.c
Reversed (or previously applied) patch detected!  Skipping patch.
15 out of 15 hunks ignored -- saving rejects to file lib/packet_mosq.c.rej
The next patch would delete the file lib/pthread_compat.h,
which does not exist!  Skipping patch.
1 out of 1 hunk ignored
patching file lib/util_mosq.c
Reversed (or previously applied) patch detected!  Skipping patch.
8 out of 8 hunks ignored -- saving rejects to file lib/util_mosq.c.rej
make[1]: *** [package/pkg-generic.mk:247: /home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/.nerves/artifacts/valiot_system_rpi4-portable-1.29.1-valiot.16/build/mosquitto-2.0.19/.stamp_patched] Error 1
make: *** [Makefile:23: _all] Error 2

It seems that in this Buildroot version, the patch doesn’t works. My question is: what would be the best way to handle this situation?

I could do the same as with the cloudflared package—create an external package for Buildroot (mosquitto-2), disable mosquitto (from Buildroot), and enable mosquitto-2. However, I’m not sure if that is the best approach. What do you think?

P.S. To check if there were other problematic packages, I removed mosquitto from the system, and the compilation completed successfully :slight_smile: .

Is it a patch you made for mosquitto?

Is it still needed (if so you should be able to fix it probably) or if not, then remove it?

Or I am misunderstanding something:)

Thanks for the reply :slight_smile:, and no, I didn’t do the patch, it came from the new Buildroot version (2024.08.3) that nerves supports.

Does this happen after a clean build of mosquitto? This looks like mosquitto is being patched a second time which I wouldn’t expect to happen. Maybe a build was interrupted during the patch phase and restarted?

Thanks for the reply :slight_smile:, and yes (I think), the messages that I shared was from the moment cloudflared package starts working, however I can try to rebuild the system with mosquitto with a clean build, I will erase .nerves, _build directories, clean and reinstall dependencies

Looks like you copied the package, renamed it to cloudflared-bin, and updated the package version. You’ll also need to review whether the old patches are still necessary, as the patch tool seems to be skipping them—likely because the new version already includes those changes.

TL;DR: rm the old patches and try rebuilding!

If some patches are still needed (e.g., the first two) and they applied fine, but you didn’t run make cloudflared-bin-dirclean cloudflared-bin to clean out the source directory, you might see the same error, making it look like the patches didn’t apply properly when they actually did. So, it’s a good idea to check the source code you’re compiling, see which patches are actually needed, and remove the ones that aren’t.

Patches might also fail if offsets have changed—if that happens, you’ll need to update the patch accordingly. Hope that helps!

Yes, a clean build gives me the output that I previously shared, however, if I try to rerun the compilation process it gives me a different message, as trying to retry the patch:

â–¶ mix ns.build
==> nerves
==> valiot_system_rpi4
Generated valiot_system_rpi4 app
make: Entering directory '/home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/deps/nerves_system_br/buildroot-2024.08.3'
  GEN     /home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/.nerves/artifacts/valiot_system_rpi4-portable-1.29.1-valiot.16/Makefile
#
# configuration written to /home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/.nerves/artifacts/valiot_system_rpi4-portable-1.29.1-valiot.16/.config
#
make: Leaving directory '/home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/deps/nerves_system_br/buildroot-2024.08.3'
------------

Build directory successfully created.

Configuration: /home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/nerves_defconfig

Next, do the following:
   1. cd /home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/.nerves/artifacts/valiot_system_rpi4-portable-1.29.1-valiot.16
   2. make

For additional options, run 'make help' in the build directory.

IMPORTANT: If you update nerves_system_br, you should rerun this script.

>>> mosquitto 2.0.19 Patching** (Mix) Nerves encountered an error while constructing the artifact
/usr/bin/make -j1  O=/home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/.nerves/artifacts/valiot_system_rpi4-portable-1.29.1-valiot.16 HOSTCC="/usr/bin/gcc" HOSTCXX="/usr/bin/g++" syncconfig
  GEN     /home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/.nerves/artifacts/valiot_system_rpi4-portable-1.29.1-valiot.16/Makefile
>>> mosquitto 2.0.19 Patching

Applying 0001-Revert-Fix-NetBSD-build.patch using patch: 
Error: duplicate filename '0001-Revert-Fix-NetBSD-build.patch'
Conflicting files are:
  already applied: /home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/deps/nerves_system_br/buildroot-2024.08.3/package/mosquitto/0001-Revert-Fix-NetBSD-build.patch
  to be applied  : /home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/deps/nerves_system_br/buildroot-2024.08.3/package/mosquitto/0001-Revert-Fix-NetBSD-build.patch
make[1]: *** [package/pkg-generic.mk:247: /home/alde/Documents/Elixir/Nerves/repos/valiot_system_rpi4/.nerves/artifacts/valiot_system_rpi4-portable-1.29.1-valiot.16/build/mosquitto-2.0.19/.stamp_patched] Error 1
make: *** [Makefile:23: _all] Error 2

Thanks for the reply! :slightly_smiling_face:

Just to give more context, I added the cloudflared package as an external Buildroot package a long time ago, before it was officially included in Buildroot (now added with 2024.08.3 release, cloudflared 2024.6.1). This caused the conflict error, so I renamed my old external Buildroot package to cloudflared-bin to be able to use the latest version (cloudflared 2025.2.1) and fix the issue. So, problem solved (AFAICT).

The other issue is with the mosquitto package. I had been using the official Buildroot package (mosquitto 2.0.18) since it had been supported by Buildroot for a long time. However, with the Buildroot 2024.08.3 release, it seems to be broken, AFAICT, and I would like to know the best approach to handle cases where an official Buildroot package is broken or needs to be downgraded.

FWIW, both cloudflared and mosquito provide prebuilt binaries and I’ve used them with previous firmwares just downloading the version I need. It doesn’t answer the original question, but my preference is always prebuilt binaries over buildroot unless it’s absolutely required to use and compile myself

1 Like

You can take a similar approach to what you did with cloudflared-bin by creating a new mosquitto package in your Nerves system under a different name. Thanks to Git history, you can easily retrieve a previous working version [0].

Alternatively, if you’re able to debug and fix the issue in the latest Mosquitto version, you could create a patch for it. Since Buildroot tends to lag behind on package versions, someone else might have already addressed the problem. The key is to find the relevant patch in the upstream project repo and incorporate it into your Nerves system.

[0] buildroot/package/mosquitto at 236dc1015cbda9b0c3479e2f37cb09c507da04dc · buildroot/buildroot · GitHub

1 Like

Just to wrap up the topic, I created a mosquitto-external package as an external Buildroot package. I copied the mosquitto package from the Buildroot 2024.11.2 release (which appears to have been updated to mosquitto 2.0.20), adjusted some environment variables to match the new package name, and it compiled successfully. :slightly_smiling_face:

Thanks, everyone!

4 Likes