Configure other required sources when packaging C programs

I am trying to package GitHub - philippe44/AirConnect: Use AirPlay to stream to UPnP/Sonos & Chromecast devices .

It seems to contain the source to build two binaries, both written in C: aircast and airupnp.
I am expecting to build both as part of the buildPhase, and I had to start somewhere: I am trying to build aircast.

Dependencies

As per its Makefile, it needs the sources of its dependencies to be located at ../.. .
That’s okay, I added the following attrset to the derivation:

  requirements = {
    jansson = fetchFromGitHub {                                                                                                                           
      repo = "jansson";                                                                                                                                   
      owner = "akheron";                                                                                                                                  
      rev = "v2.13.1";                                                                                                                                    
      sha256 = "sha256-41QQ3PxNnvQQmX2cLBZgAVCJVZofDb6a/i5WpsG6lHo=";                                                                                     
    };
    ... # rest omitted for brevity
  };

and I use it to replace parts of the Makefile content to point the right place leveraging the patchPhase.

Some dependencies need extra elbow grease

That’s where things get complicated: some dependencies do not have the libraries to be included directly available in their source!

For example GitHub - akheron/jansson: C library for encoding, decoding and manipulating JSON data requires to perform:

autoreconf -i
./configure

to create jansson_config.h (which is included by aircast).

My effort

I tried to use autoconf and automake “manually” on jansson as part of the buildPhase, but autom4te fails to create its necessary autom4te.cache.

I stumbled upon autoreconHook in the nixpkgs documentation, and naively tried to add runHook autoreconf in the buildPhase, but nothing happened (I suspect this automagically works on the derivation’s source, not the folder I was in - ${requirements.jansson}/).

My questions

If I am on the right path, how can I ./configure on sources that are not the main sources of my derivation (jansson and not aircast) to create the necessary ${requirements.jansson}/src/jansson_config.h}?

Am I going too hard agains’t the flow, and there is a nix way to handle these cases (other sources required with different configuration systems) elegantly?

That project is a mess – looks like there are no compilation instructions other than links to required libraries. And as you noticed, it requires you to configure or maybe even build them after download.

If I wanted to use the project, I would probably just rewrite the Makefiles to use libraries from Nix (using pkg-config, example), or even port it to Meson, which is much cleaner than Makefiles and supports downloading and building dependencies automatically for platforms without package managers.

If you do not want to dig so deep, you could try to copy all the third-party sources into thirdparty directory and then pass BASE=thirdparty to makeFlags. Make sure to chmod -R +w the third party sources, as copying will likely preserve the read-only permissions from the source trees in the Nix store.

I would not bother with modifying setup hooks for the third-party libraries as that will likely be more effort than running the necessary commands manually.

1 Like

Did you ever end up finishing this? I’d like this software as well, and the Makefiles are giving me nightmares.

No: to be honest, I completely gave up on that.