Hello im kinda new to Nix and I have following question/problem:
Suppose I have a Package A
from the nixpkgs repo. Now I have written myself a package B
which depends on A
. System B
and A
define both a C
-library.
The library B
reference to the library of A
via an #include <...>
-statement. So far so good.
The problem is now that the maintainer of library of B
references the package of A
via smth like
#include <library_A/foo>
. But the include
-folder struture of package A
is smth like this
package_A/include/additional_folder/library_A/foo
So I want to manage the build process for package B
so that not only the path package_A/include
is added but also the path package_A/include/additional_folder
.
How can I do this?
Usually, the package A would contain a pkg-config
file that would contain something like the following:
$ cat /nix/store/i6i4h7xkygh0ylvn9jwdlji8q82xf907-glib-2.72.1-dev/lib/pkgconfig/glib-2.0.pc | rg includedir
includedir=/nix/store/i6i4h7xkygh0ylvn9jwdlji8q82xf907-glib-2.72.1-dev/include
Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib-2.0/include
Then the package B would be expected to use pkg-config --cflags glib-2.0
to get the compiler flags.
Additionally, package A can install CMake config files and then CMake projects will be able to get the correct flags when finding the dependency using find_package
function. And if the package A is very old, it may ship a config-tool script (called something like a-config
) that can again be executed to get the compiler flags.
It might be the case that project B actually uses the dependency correctly but project A’s build system makes incorrect assumption resulting in a wrong path being hardcoded in the pkg-config file, see https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files. Then you might need to patch the project A source code to fix it – ideally working with upstream, see https://github.com/NixOS/nixpkgs/pull/172150 for an example, or just sed
the file in postInstall
.
And, as last resort, you can pass NIX_CFLAGS_COMPILE = "-I${a}/include/additional_folder";
to package B’s mkDerivation
to have the build pass an extra flag to the C compiler. But fixing either package A or package B upstream is preferred, since it reduces the amount of code in Nixpkgs and resolves the issue for other distros as well.
1 Like