Runtime dependency on libintl.h

Hey. I’m trying to get vcpkg to work under NixOS. It has required some workarounds, but it’s currently working fine.
However, when compiling the vcpkg port gettext-libintl, I get the following error:

CMake Error at ports/gettext-libintl/portfile.cmake:4 (message):
  When targeting Linux, `libintl.h` is expected to come from the C Runtime
  Library (glibc).  Please use "sudo apt-get install libc-dev" or the
  equivalent to install development files.

Adding libintl and libiconv to buildInputs does not work.

I tried to add glibc.dev to buildInputs, but this causes another error (see this post)

I cannot patch the #include, as it’s a runtime dependency.

Full derivation
{
  autoconf,
  automake,
  bash,
  cacert,
  cmake,
  cmrc,
  coreutils,
  curl,
  fetchFromGitHub,
  fmt_9,
  gcc,
  git,
  glibc,
  gnumake,
  gperf,
  lib,
  libtool,
  libiconv,
  libintl,
  makeWrapper,
  meson,
  m4,
  ninja,
  perl,
  pkg-config,
  python3,
  runtimeShell,
  stdenv,
  zip,
  zstd,
}
: let
  runtimeDeps = [
    autoconf
    automake
    bash
    cacert
    coreutils
    curl
    cmake
    gcc
    git
    gnumake
    libiconv
    libintl
    meson
    ninja
    perl
    pkg-config
    python3
    zip
    zstd
  ];
in
  stdenv.mkDerivation rec {
    pname = "vcpkg";
    version = "b18b17865cfb6bd24620a00f30691be6775abb96";

    src = fetchFromGitHub {
      owner = "microsoft";
      repo = "vcpkg-tool";
      rev = "bedcba5172f5e4b91caac660ab7afe92c27a9895";
      hash = "sha256-XgYCa9aiG8lOraClfsFCk7U1qxvsfsIKbcBd2xBcNSw=";
    };

    vcpkg_src = fetchFromGitHub {
      owner = "microsoft";
      repo = "vcpkg";
      rev = "5d2a0a9814db499f6ba2e847ca7ab5912badcdbf";
      hash = "sha256-UPThRUq8N2nmUoFMUgfLqu1JM3pjCz6mVdR11Iig4kE=";
    };

    nativeBuildInputs = [
      cmake
      cmrc
      fmt_9
      makeWrapper
    ];

    buildInputs = [
      libiconv
      libintl
    ];

    cmakeFlags = [
      "-DVCPKG_DEPENDENCY_EXTERNAL_FMT=ON"
      "-DVCPKG_DEPENDENCY_CMAKERC=ON"
    ];

    vcpkgScript = let
      out = placeholder "out";
    in ''
      #!${runtimeShell}
      vcpkg_hash=$(echo -n "${out}" | sha256sum | cut -f1 -d ' ')
      vcpkg_root_path="$HOME/.local/vcpkg/roots/$vcpkg_hash"
      if [[ ! -d $vcpkg_root_path ]]; then
        mkdir -p $vcpkg_root_path
        ln -s ${out}/share/vcpkg/{docs,ports,scripts,triplets,versions,LICENSE.txt} $vcpkg_root_path/
        ln -s ${out}/bin/vcpkg $vcpkg_root_path/
        touch $vcpkg_root_path/.vcpkg-root # need write access
      fi

      if [[ "$1" == "--root-for-nix-usage" ]]; then
        echo "$vcpkg_root_path"
        exit 0
      fi

      # Remove --vcpkg-root and --downloads-root from the command-line arguments
      args=()
      skip_next=false

      for arg in "$@"; do
        if [[ "$skip_next" == true ]]; then
          skip_next=false
          continue
        fi

        if [[ "$arg" == "--vcpkg-root" || "$arg" == "--downloads-root" ]]; then
          skip_next=true
          continue
        fi

        args+=("$arg")
      done

     echo "hello, i was called with $PATH"

      export VCPKG_FORCE_SYSTEM_BINARIES=1
      exec ${out}/share/vcpkg/vcpkg \
        --vcpkg-root "$vcpkg_root_path" \
        --downloads-root "$vcpkg_root_path/downloads" \
        "''${args[@]}"
    '';

    passAsFile = ["vcpkgScript"];

    installPhase = ''
      cmake --build . --target=install --config=Release
      mkdir -p $out/share/vcpkg

      cp --preserve=mode -r ${vcpkg_src}/{docs,ports,scripts,triplets,versions,LICENSE.txt} $out/share/vcpkg
      mv $out/bin/vcpkg $out/share/vcpkg/vcpkg
      cp $vcpkgScriptPath $out/bin/vcpkg
      chmod +x $out/bin/vcpkg
      touch $out/share/vcpkg/vcpkg.disable-metrics
    '';

    postFixup = ''
      wrapProgram $out/share/vcpkg/vcpkg --set PATH ${lib.makeBinPath runtimeDeps}
      echo
    '';
  }

And its dependency:

{
  lib,
  stdenv,
  fetchFromGitHub,
  cmake,
}:
stdenv.mkDerivation rec {
  pname = "cmrc";
  version = "2.0.1";

  src = fetchFromGitHub {
    owner = "vector-of-bool";
    repo = "cmrc";
    rev = version;
    hash = "sha256-++16WAs2K9BKk8384yaSI/YD1CdtdyXVBIjGhqi4JIk=";
  };

  cmakeFlags = [
    "-DBUILD_TESTS=OFF"
  ];

  installPhase = ''
    dir=$out/share/cmakerc
    mkdir -p $dir
    mv CMakeRC.cmake $dir/cmakerc-config.cmake
  '';

  meta = with lib; {
    description = "A Resource Compiler in a Single CMake Script";
    homepage = "https://github.com/vector-of-bool/cmrc";
    license = licenses.mit;
    maintainers = with maintainers; [];
  };
}

Is there something I’m missing?
Thanks

The project assumes FHS, which obviously will not work on Nix:

The solution is to patch that out.

Rather than call the install target manually, it is usually cleaner to let the generic builder invoke it for you and do extra installations in postInstall.

1 Like

Good catch. I thought this message came from the compiler, not from vcpkg itself. Thanks!

Now I’m stuck building Qt, which refers to /bin/pwd in its configure script
I guess I have to patch the vcpkg portfile, so that it patches Qt? sigh

But that’s another thing. Thanks for the help already