Trying to package a monorepo Cpp/Rust

Hello,

I am trying to package a monorepo that contains C++ code that binds to some rust libraries, and other rust crates.

Note that the old Cpp-only version is already packaged in nixpkgs, and this is an attempt to package a newer version that integrates with Rust.

The monorepo structure:

taskwarrior/
|__ src/: taskwarrior main C++ code
|__ taskchampion/lib : taskchampion-lib crate
|__ taskchampion/taskchampion: taskchampion crate
|__ taskchampion/sync-server: taskchampion-sync-server crate
|__ taskchampion/xtask: xtask crate
|__  taskchampion/integration-tests: integration-tests crate

sync-server, xtask and integration-tests are not really important for the binary and core functionality, so they may be disregarded if needed

taskchampion-lib is the library that binds C++ to the Rust taskchampion crate.

My try at packaging

{
  lib,
  stdenv,
  fetchFromGitHub,
  cmake,
  libuuid,
  gnutls,
  python3,
  xdg-utils,
  installShellFiles,
  rustc,
  cargo,
  rustPlatform,
  git,
}:
stdenv.mkDerivation rec {
  pname = "taskwarrior";
  version = "develop";

  src = fetchFromGitHub {
    owner = "GothenburgBitFactory";
    repo = "taskwarrior";
    rev = "6d23497d6f55c8e89ccbf0c9358dc383bd12723a";
    hash = "sha256-hsIkoYTkDgW6UhN0pvCYGGSxUj3GBjz+6n5qUHWwXbY=";
    fetchSubmodules = true;
  };

  postPatch = ''
    substituteInPlace src/commands/CmdNews.cpp \
      --replace "xdg-open" "${lib.getBin xdg-utils}/bin/xdg-open"
  '';

  nativeBuildInputs = [cmake libuuid gnutls python3 installShellFiles rustc cargo];

  cargoDeps = rustPlatform.fetchCargoTarball {
    inherit src;
    name = "taskchampion-${version}";
    hash = "sha256-On4PzRQaQBUZXcje9a91Zh68BhWIQvnkDFxY3k4PVvw=";
  };


  buildPhase = ''
    cmake -DCMAKE_BUILD_TYPE=debug .
    make
  '';

  postInstall = ''
    # ZSH is installed automatically from some reason, only bash and fish need
    # manual installation
    installShellCompletion --cmd task \
      --bash $out/share/doc/task/scripts/bash/task.sh \
      --fish $out/share/doc/task/scripts/fish/task.fish
    rm -r $out/share/doc/task/scripts/bash
    rm -r $out/share/doc/task/scripts/fish
    # Install vim and neovim plugin
    mkdir -p $out/share/vim-plugins
    mv $out/share/doc/task/scripts/vim $out/share/vim-plugins/task
    mkdir -p $out/share/nvim
    ln -s $out/share/vim-plugins/task $out/share/nvim/site
  '';

}

Results

The builds starts and everything seems fine … until cargo seems to try to access network for a second (?) time and fails to fetch from crates.io

[ 94%] Building CXX object src/tc/CMakeFiles/tc.dir/Task.cpp.o
[ 96%] Linking CXX static library libtc.a
[ 96%] Built target tc
[ 96%] running cargo
    Updating crates.io index
warning: spurious network error (3 tries remaining): [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
error: failed to get `anyhow` as a dependency of package `taskchampion-lib v0.1.0 (/build/source/taskchampion/lib)`
    ... which satisfies path dependency `taskchampion-lib` (locked to 0.1.0) of package `tc-rust v0.1.0 (/build/source/src/tc/rust)`

Caused by:
  failed to query replaced source registry `crates-io`

Caused by:
  download of config.json failed

Caused by:
  failed to download from `https://index.crates.io/config.json`

Caused by:
  [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
make[2]: *** [src/tc/rust/CMakeFiles/tc-rust_target.dir/build.make:73: src/tc/rust/x86_64-unknown-linux-gnu/debug/libtc_rust.a] Error 101
make[1]: *** [CMakeFiles/Makefile2:570: src/tc/rust/CMakeFiles/tc-rust_target.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
error: builder for '/nix/store/fqdh7ic68rvy4c5s4whssk8nrjj9i6hr-taskwarrior-develop.drv' failed with exit code 2;
       last 10 log lines:
       >   download of config.json failed
       >
       > Caused by:
       >   failed to download from `https://index.crates.io/config.json`
       >
       > Caused by:
       >   [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
       > make[2]: *** [src/tc/rust/CMakeFiles/tc-rust_target.dir/build.make:73: src/tc/rust/x86_64-unknown-linux-gnu/debug/libtc_rust.a] Error 101
       > make[1]: *** [CMakeFiles/Makefile2:570: src/tc/rust/CMakeFiles/tc-rust_target.dir/all] Error 2
       > make: *** [Makefile:156: all] Error 2
       For full logs, run 'nix log /nix/store/fqdh7ic68rvy4c5s4whssk8nrjj9i6hr-taskwarrior-develop.drv'.

CMake instructions seem to run cargo, I probably need to patch the cmake build, but I am not knowledgeable with Cmake to understand what is happening.

Any help would be appreciated :slight_smile: