cmakeFlags aren't picked up by the library

Hello. I’m trying to build jeremy-rifkin/libassert using Nix. The library depends on jeremy-rifkin/cpptrace which in turn depends on davea42/libdwarf-code.

I successfully build libdwarf and cpptrace, but I cannot build libassert.

The reason being, when I set -DLIBASSERT_USE_EXTERNAL_CPPTRACE=ON, even tho I see it being added to cmakeFlags in the nix log, the build process doesn’t pick this up, and I get an error that it cannot find git for cpptrace-populate:


error: builder for '/nix/store/rv0k2rs1mgaj3vdzzlyspmi07whmbpxp-libassert-2.0.2.drv' failed with exit code 1;
       last 20 log lines:
-- Detecting CXX compile features - done
CMake Error at /nix/store/0xpv46mb188z226j7cs211zmmi5xw9nj-cmake-3.29.1/share/cmake-3.29/Modules/ExternalProject.cmake:2945 (message):
  error: could not find git for clone of cpptrace-populate
Call Stack (most recent call first):
  /nix/store/0xpv46mb188z226j7cs211zmmi5xw9nj-cmake-3.29.1/share/cmake-3.29/Modules/ExternalProject.cmake:4456 (_ep_add_download_command)
  CMakeLists.txt:29 (ExternalProject_Add)

Which is due to this code path:

if(LIBASSERT_USE_EXTERNAL_CPPTRACE)
  find_package(cpptrace REQUIRED)
else()
  include(FetchContent)
  FetchContent_Declare(
    cpptrace
    GIT_REPOSITORY "${LIBASSERT_CPPTRACE_REPO}"
    GIT_TAG        "${LIBASSERT_CPPTRACE_TAG}"
  )
  FetchContent_MakeAvailable(cpptrace)
endif()

If it picked up the flag, it should use find_package, which then should work (or at least produce a completely different error).

Here’s the repro which fails: https://github.com/dich0tomy/repro. A simple nix build will fail.

I also tried doing

preConfigure = ''
  cmakeFlagsArray+=(
    "-D....."
  )
'';

And using configureFlags instead, but nothing works.

If I go into a shell with cmake and add cpptrace to packages, then clone the libassert repo and build it manually, everything works fine:

nix develop
git clone git@github.com:jeremy-rifkin/libassert/
cd libassert
cmake -S . -B build -DLIBASSERT_USE_EXTERNAL_CPPTRACE=ON
cmake --build build --parallel 16

Welcome :slight_smile:

First of all:

$ nix build github:dich0tomy/repro
error: hash mismatch in fixed-output derivation '/nix/store/v2ahk1dbf85dplvicbm08xg5nmh643f5-source.drv':
         specified: sha256-0Hq6RRw9l/kNfgo97ijsDEm680A/zF/WNmkaARm5BfY=
            got:    sha256-N/msn2nNg6vWon/zEHaZqBiYFam2NM+LV8Ax/g0ObZo=
error: 1 dependencies of derivation '/nix/store/wm4jik57ddvbbmv83j304h7fxqz904yi-libassert-2.0.2.drv' failed to build

So I guess you forgot to update hashes, which is a very common mistake. To be sure, I suggest starting from hash = lib.fakeHash;

So I did the same mistake… Anyways :sweat_smile:

diff --git a/flake.nix b/flake.nix
index 38bdc99..101a2b1 100644
--- a/flake.nix
+++ b/flake.nix
@@ -73,7 +73,7 @@
               owner = "jeremy-rifkin";
               repo = "libassert";
               rev = "v${version}";
-              sha256 = "sha256-0Hq6RRw9l/kNfgo97ijsDEm680A/zF/WNmkaARm5BfY=";
+              sha256 = "sha256-N/msn2nNg6vWon/zEHaZqBiYFam2NM+LV8Ax/g0ObZo=";
             };
 
             cmakeFlags = [

lead to:

$ nix build -L
[…]
libassert> cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/wvpmb6vysiq1iswqgsrffrvkk9j1ws34-libassert-2.0.2/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/wvpmb6vysiq1iswqgsrffrvkk9j1ws34-libassert-2.0.2/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/wvpmb6vysiq1iswqgsrffrvkk9j1ws34-libassert-2.0.2/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/wvpmb6vysiq1iswqgsrffrvkk9j1ws34-libassert-2.0.2/share/doc/libassert -DCMAKE_INSTALL_INFODIR=/nix/store/wvpmb6vysiq1iswqgsrffrvkk9j1ws34-libassert-2.0.2/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/wvpmb6vysiq1iswqgsrffrvkk9j1ws34-libassert-2.0.2/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/wvpmb6vysiq1iswqgsrffrvkk9j1ws34-libassert-2.0.2/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/wvpmb6vysiq1iswqgsrffrvkk9j1ws34-libassert-2.0.2/include -DCMAKE_INSTALL_SBINDIR=/nix/store/wvpmb6vysiq1iswqgsrffrvkk9j1ws34-libassert-2.0.2/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/wvpmb6vysiq1iswqgsrffrvkk9j1ws34-libassert-2.0.2/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/wvpmb6vysiq1iswqgsrffrvkk9j1ws34-libassert-2.0.2/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/cb4mxc1mnl97590zbbhclgvqn4iqqap7-gcc-wrapper-12.3.0/bin/strip -DCMAKE_RANLIB=/nix/store/cb4mxc1mnl97590zbbhclgvqn4iqqap7-gcc-wrapper-12.3.0/bin/ranlib -DCMAKE_AR=/nix/store/cb4mxc1mnl97590zbbhclgvqn4iqqap7-gcc-wrapper-12.3.0/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/wvpmb6vysiq1iswqgsrffrvkk9j1ws34-libassert-2.0.2 -DLIBASSERT_USE_EXTERNAL_CPPTRACE=ON
libassert> -- The CXX compiler identification is GNU 12.3.0
libassert> -- Detecting CXX compiler ABI info
libassert> -- Detecting CXX compiler ABI info - done
libassert> -- Check for working CXX compiler: /nix/store/cb4mxc1mnl97590zbbhclgvqn4iqqap7-gcc-wrapper-12.3.0/bin/g++ - skipped
libassert> -- Detecting CXX compile features
libassert> -- Detecting CXX compile features - done
libassert> -- Found zstd: /nix/store/8hycw2kcf0vwprjv4vnp486yxk71yaw3-zstd-1.5.5/lib/libzstd.so
libassert> -- Found Zstd: /nix/store/8hycw2kcf0vwprjv4vnp486yxk71yaw3-zstd-1.5.5/lib/libzstd.so
libassert> CMake Error at /nix/store/jlxdary64rcxfncszasvfmzrywalsp7y-cmake-3.27.7/share/cmake-3.27/Modules/CMakeFindDependencyMacro.cmake:76 (find_package):
libassert>   By not providing "Findlibdwarf.cmake" in CMAKE_MODULE_PATH this project has
libassert>   asked CMake to find a package configuration file provided by "libdwarf",
libassert>   but CMake did not find one.
libassert>   Could not find a package configuration file provided by "libdwarf" with any
libassert>   of the following names:
libassert>     libdwarfConfig.cmake
libassert>     libdwarf-config.cmake
libassert>   Add the installation prefix of "libdwarf" to CMAKE_PREFIX_PATH or set
libassert>   "libdwarf_DIR" to a directory containing one of the above files.  If
libassert>   "libdwarf" provides a separate development package or SDK, be sure it has
libassert>   been installed.
libassert> Call Stack (most recent call first):
libassert>   /nix/store/r3ck4wnx13a095qnhhahiv5kklpj378z-cpptrace-0.5.4/lib/cmake/cpptrace/cpptrace-config.cmake:17 (find_dependency)
libassert>   CMakeLists.txt:57 (find_package)
libassert> 
libassert> -- Configuring incomplete, errors occurred!

So I guess the flag is here, at the end of the command line. But there are other errors :slight_smile:

That’s interesting. I wasn’t getting that error… Anyway, I changed the hash and added libdwarf to buildInptus, but Im still getting the same exact error as before.

Ive updated the repo. Doing nix build github:dich0tomy/repro yields the same error as locally.

When I do nix build github:dich0tomy/repro -L I dont see the flag anywhere

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Ok, scratch all of that. Updating hashes helped, I just left out a goofy mistake I made earlier, chaning cmakeFlags to cmakeConfigureFlags… It works now ;D

Thanks a lot for the help! Im only wondering why it didnt notify me about the hash earlier.

When you tell nix that this source has this hash, and this hash is already in your store, it doesn’t try to download the source, and directly use what you already have in your store corresponding to this hash. So you can’t get a notification about this wrong hash.

So here, you were trying to build libassert, but not using libassert source. As I said, this is a common mistake, and it is even harder to detect when you are only updating the version of a package, as everything seems to build fine, but you don’t end up with the version you expect.

1 Like