Installing vcpkg on macos using nix

Hi all, I want to start using nix so I can make my development environment reproducible across my machines and different setups.

One of the packages I need is vcpkg. It is not available in the nix repo and I’ve been told in a github issue that vcpkg should not be package in nix, so I’m trying to do it myself.

I’m only at the beginning and I encountered an issue while trying to build it.

You see, vcpkg has a bootstrap-vcpkg.sh file in their repo. This is the file that should be used for building vcpkg.

Here’s the file I started with:

{ gcc11Stdenv, fetchFromGitHub, ninja, cmake, bash }:

gcc11Stdenv.mkDerivation {
  name = "vcpkg-2021.05.12";

  src = fetchFromGitHub {
    owner = "microsoft";
    repo = "vcpkg";
    rev = "2021.05.12";
    sha256 = "0290fp9nvmbqpgr33rnchn5ngsq4fdll2psvh0bqf0324w2qpsjw";
  };

  buildPhase = ''
    ./bootstrap-vcpkg.sh -useSystemBinaries
  '';
}

I’m running this file using this command: nix-shell -p 'with (import <nixpkgs> {}); callPackage ./vcpkg.nix {}'

This file produce an error:

configuring
no configure script, doing nothing
building
Could not find cmake. Please install it (and other dependencies) with:
sudo apt-get install cmake ninja-build
error: builder for '/nix/store/riq6vjdhv4z3xvzp8g597xjgwf2rvm03-vcpkg-2021.05.12.drv' failed with exit code 1;
       last 9 log lines:
       > unpacking sources
       > unpacking source archive /nix/store/ycfd6vbgh3s1vy11hfb17b8x33rqj7aw-source
       > source root is source
       > patching sources
       > configuring
       > no configure script, doing nothing
       > building
       > Could not find cmake. Please install it (and other dependencies) with:
       > sudo apt-get install cmake ninja-build
       For full logs, run 'nix log /nix/store/riq6vjdhv4z3xvzp8g597xjgwf2rvm03-vcpkg-2021.05.12.drv'.

The no configure script, doing nothing is expected, since vcpkg don’t have a configure file nor they have a CMakeLists.txt file. Their bootstrap-vcpkg.sh do use cmake and ninja internally though, and check for the presence of git too.

Now I tried to change the script so cmake and ninja are available by adding buildInputs = [cmake ninja];, but when doing so nix tries to run the cmake command itself, but it fails since they don’t have a CMakeLists.txt file directly in their repo:

configuring
fixing cmake files...
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 -DCMAKE_SKIP_BUILD_RPATH=ON -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/share/doc/vcpkg -DCMAKE_INSTALL_INFODIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/include -DCMAKE_INSTALL_SBINDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/854jyvxrvpdpbfn2zaba1v2qgqkxipyh-cctools-binutils-darwin-949.0.1/bin/strip -DCMAKE_RANLIB=/nix/store/854jyvxrvpdpbfn2zaba1v2qgqkxipyh-cctools-binutils-darwin-949.0.1/bin/ranlib -DCMAKE_AR=/nix/store/854jyvxrvpdpbfn2zaba1v2qgqkxipyh-cctools-binutils-darwin-949.0.1/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12  
CMake Error: The source directory "/tmp/nix-build-vcpkg-2021.05.12.drv-0/source" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
error: builder for '/nix/store/76djky7f3xy6ym6v3qlmy941z0bjb8xw-vcpkg-2021.05.12.drv' failed with exit code 1;
       last 9 log lines:
       > unpacking sources
       > unpacking source archive /nix/store/ycfd6vbgh3s1vy11hfb17b8x33rqj7aw-source
       > source root is source
       > patching sources
       > configuring
       > fixing cmake files...
       > 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 -DCMAKE_SKIP_BUILD_RPATH=ON -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/share/doc/vcpkg -DCMAKE_INSTALL_INFODIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/include -DCMAKE_INSTALL_SBINDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/854jyvxrvpdpbfn2zaba1v2qgqkxipyh-cctools-binutils-darwin-949.0.1/bin/strip -DCMAKE_RANLIB=/nix/store/854jyvxrvpdpbfn2zaba1v2qgqkxipyh-cctools-binutils-darwin-949.0.1/bin/ranlib -DCMAKE_AR=/nix/store/854jyvxrvpdpbfn2zaba1v2qgqkxipyh-cctools-binutils-darwin-949.0.1/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/mp38jl4fkv0gqnqhz7a3agx4flwda59n-vcpkg-2021.05.12
       > CMake Error: The source directory "/tmp/nix-build-vcpkg-2021.05.12.drv-0/source" does not appear to contain CMakeLists.txt.
       > Specify --help for usage, or press the help button on the CMake GUI.
       For full logs, run 'nix log /nix/store/76djky7f3xy6ym6v3qlmy941z0bjb8xw-vcpkg-2021.05.12.drv'.

Now I’m a bit stuck packaging vcpkg. This is my first nix package I’m doing and I hoped to get some help here, as my stack overflow question has been quite silent.

Thank you all!

Let’s start with this :slight_smile: So the difference between a derivation (read: package) and a module is that the former is a collection of files that can be “installed”, whereas the latter is a set of configuration options that you can set inside configuration.nix.

The reason that this is significant here is that, while you can write a package for vcpkg (and will need to as a prerequisite of writing a module anyway), it is necessary to configure it in a specific way for it to work under NixOS in the opinion of your reviewer - this is likely because of all the references to vcpkg root dirs and whatnot. I don’t know how flexible vcpkg is myself, but given it’s a package manager and from a Microsoft upstream it seems reasonable to expect it needs to adhere to exactly that structure and will be a bit hard to get to run in a satisfactory way without a module.

Anyway, this is just a wordy way to say: Here be dragons.

This is the correct thing to do, however you’re using the default “builder”, which will indeed just try to invoke cmake if it’s present and thinks it’s necessary. The docs for the stdenv which explain what nix does and expect you to provide are here.

There’s a lot to take in and learn there, and you’ll likely need to understand most of it to package this particular package.

To get over this initial hump, though, this should do the trick (by disabling the configurePhase, and not implicitly invoking cmake, instead just using your buildPhase immediately after the empty patchPhase):

{ gcc11Stdenv, fetchFromGitHub, ninja, cmake, bash }:

gcc11Stdenv.mkDerivation {
  name = "vcpkg-2021.05.12";

  src = fetchFromGitHub {
    owner = "microsoft";
    repo = "vcpkg";
    rev = "2021.05.12";
    sha256 = "0290fp9nvmbqpgr33rnchn5ngsq4fdll2psvh0bqf0324w2qpsjw";
  };

  dontConfigure = true;

  buildPhase = ''
    ./bootstrap-vcpkg.sh -useSystemBinaries
  '';
}

You can tell which phase is causing issues by looking at the build log, in your case the error happens after the log mentions configuring, which apparently does “fixing cmake files”.

Note that the bootstrap script you’re using will not work as-is under NixOS, and will require heavy patching to fix. Within the first couple of lines it tries to download an older version of itself to build itself: vcpkg/bootstrap.sh at 05c411da6619971fd033c8a9d20c8cce07d5e42a · microsoft/vcpkg · GitHub

This will fail because 1. downloads are impure and prohibited during the build and 2. the binary isn’t built for NixOS and will not run without at the very least using patchElf. You might fare better by reverse engineering their script and just fixing up the environment yourself, perhaps resolving the dependencies using a little python script like the bazel package, instead of using the bootstrap script.

Given this isn’t even starting the build yet, there will likely be a bunch of other impure things this attempts to do, and it will generally be quite hard to get to run. Good luck, and remember fhsUserEnv and VMs always exist if you don’t get there.

1 Like

Thank you for your response! This is much clearer now. I might take two routes: either using vcpkg as a git submodule in my repo (which is possible!) or I’ll configure the dependencies of my project with nix. There’s a few properties that I like with vcpkg, like a lot of C++ specific libraries and even hard to package libraries are simply available there, but we’ll see. I like what I see with nix and the possibility of a truly portable and reproducible setup.

I totally agree about the script, it looks way too complicated and hard to produce reproducible results and it’s actually one of my pain point right now. I would love to be able to make a replacement one that works on nix one day.

1 Like

Yeah, it’s the unfortunate trade-off - upfront learning and lack of library support with nix or long-term maintenance, lack of trust of your inputs and the general mess that is the software supply chain with everything else :wink:

I’d still say it’s worth trying to see how flexible vcpkg is, it’s nice to have the easy-but-impure route available occasionally in the nix ecosystem, as long as it can be made to work transparently for end users. Someone else might pick up the issue at some point.

Searching around on github for a bit can sometimes turn up existing efforts/info and people who may know more. In this case, I stumbled into Add shell.nix for building on NixOS by poelzi · Pull Request #15906 · microsoft/vcpkg · GitHub

I have progressed!

I created this nix file:

{ gcc11Stdenv, fetchFromGitHub, ninja, cmake, bash, curl, zip, unzip, cacert }:

gcc11Stdenv.mkDerivation {
  name = "vcpkg-2021.05.12";

  src = fetchFromGitHub {
    owner = "microsoft";
    repo = "vcpkg";
    rev = "2021.05.12";
    sha256 = "0290fp9nvmbqpgr33rnchn5ngsq4fdll2psvh0bqf0324w2qpsjw";
  };

  dontConfigure = true;
  buildInputs = [cmake ninja curl zip unzip cacert];

  buildPhase = ''
    ./bootstrap-vcpkg.sh -useSystemBinaries -disableMetrics
  '';

  installPhase = ''
    mkdir -p $out/bin/
    cp ./buildtrees/_vcpkg/build/vcpkg $out/bin/vcpkg
  '';
}

Running nix-shell -p 'with (import <nixpkgs> {}); callPackage ./vcpkg.nix {}' will prompt a shell that has a working vcpkg executable!

It’s far from done since there’s a lot more in vcpkg than only its executable. I will continue on this. I’m still using their bootstrap-vcpkg.sh file for now, and I need to package all of their script file it needs for running.

Okay, some progress again :slight_smile:

I’ve ditched the bootstrap-vcpkg.sh script. I instead do what this script is doing, and it was much simpler than anticipated.

I have those two files:

# vcpkg-tool.nix
{ gcc11Stdenv, fetchFromGitHub, ninja, cmake, git, cacert }:

gcc11Stdenv.mkDerivation {
  name = "vcpkg-tool-2021-12-09";

  src = fetchFromGitHub {
    owner = "microsoft";
    repo = "vcpkg-tool";
    rev = "2021-12-09";
    sha256 = "0027fbm6vd82qiddg92wslabsi2dvpfxgyin67fna97xz2hnzr9l";
  };

  buildInputs = [cmake ninja git cacert];
}

And this one:

# vcpkg.nix
{ gcc11Stdenv, fetchFromGitHub, ninja, cmake, bash, curl, zip, unzip, git, cacert }:

gcc11Stdenv.mkDerivation {
  name = "vcpkg-abf52dd1adb482e21fb89d1125d4fed6b79dfc07";

  src = fetchFromGitHub {
    owner = "microsoft";
    repo = "vcpkg";
    rev = "abf52dd1adb482e21fb89d1125d4fed6b79dfc07";
    sha256 = "0lgrgmc2nyf5qqp542zsyqphghx17sg26fiaywb13mq36hgrdld5";
  };

  dontConfigure = true;
  buildPhase = "";

  installPhase = ''
    mkdir -p $out/share/vcpkg
    cp --preserve=mode -r ./{docs,ports,scripts,triplets,.vcpkg-root} $out/share/vcpkg
  '';
  buildInputs = [];
}

One install the actual binary, the other is installing all the required files vcpkg needs to run.

To actually use vcpkg I have this default.nix file:

{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell rec {
  # buildInputs is for dependencies you'd need "at run time",
  # were you to to use nix-build not nix-shell and build whatever you were working o
  vcpkg_tool = pkgs.callPackage ./nix-modules/vcpkg-tool.nix {};
  vcpkg = pkgs.callPackage ./nix-modules/vcpkg.nix {};
  buildInputs = with pkgs; [
    gdb
    ninja
    cmake
    vcpkg_tool
    vcpkg
    
    # vcpkg
    curl
    zip
    unzip
  ];

  VCPKG_ROOT = "${builtins.getEnv "PWD"}/.vcpkg";
  VCPKG_DOWNLOADS = "${builtins.getEnv "PWD"}/.vcpkg/downloads";

shellHook =
  ''
    if [ ! -d "${VCPKG_ROOT}" ]; then
      mkdir -p ${VCPKG_ROOT}
      mkdir -p ${VCPKG_ROOT}/downloads
      ln -s ${vcpkg_tool}/bin/vcpkg ${VCPKG_ROOT}/
      ln -s ${vcpkg}/share/vcpkg/{docs,ports,scripts,triplets,.vcpkg-root} ${VCPKG_ROOT}/
    fi
  '';
}

Unfortunately, vcpkg assumes it can write directly into the store, so I had to put VCPKG_ROOT in a local directory that has everything linked there. I still don’t know how to fix this but at least vcpkg is actually capable of installing packages with that setup! :confetti_ball:

2 Likes

Update again:

I have a single nix file that installs vcpkg and also make it useable using a wrapper script.

It creates a vcpkg root inside home directory by doing simlinks to the actual vcpkg root.

This workaround the problem where vcpkg assumes that the installation directory is mutable.

It also support different version by doing a hash of the installation path as prefix to the vcpkg root. Please tell me if there’s a better way.

{
  stdenv,
  fetchFromGitHub,
  gcc,
  ninja,
  cmake,
  lib,
  git,
  cacert,
  runtimeShell
}:

stdenv.mkDerivation rec {
  pname = "vcpkg";
  version = "b18b17865cfb6bd24620a00f30691be6775abb96";

  src = fetchFromGitHub {
    owner = "microsoft";
    repo = "vcpkg-tool";
    rev = "2021-12-09";
    sha256 = "0027fbm6vd82qiddg92wslabsi2dvpfxgyin67fna97xz2hnzr9l";
  };

  vcpkg_src = fetchFromGitHub {
    owner = "microsoft";
    repo = "vcpkg";
    rev = "b18b17865cfb6bd24620a00f30691be6775abb96";
    sha256 = "1yfb1vhfgz7mgl6iwvq6qyrpzc1m95jr821pk1d36j5bj1n31qhh";
  };

  buildInputs = [cmake ninja git cacert];

  vcpkgScript = ''
    #!${runtimeShell}
    vcpkg_hash=$(echo -n "${placeholder "out"}" | sha256sum | cut -f1 -d ' ')
    vcpkg_root_path="$HOME/.vcpkg/roots/$vcpkg_hash"
    if [[ ! -d $vcpkg_root_path ]]; then
      mkdir -p $vcpkg_root_path
      ln -s ${placeholder "out"}/share/vcpkg/{docs,ports,scripts,triplets,versions} $vcpkg_root_path/
    fi
    VCPKG_DOWNLOADS=$vcpkg_root_path/downloads VCPKG_ROOT=$vcpkg_root_path ${placeholder "out"}/share/vcpkg/vcpkg "$@"
  '';
  
  passAsFile = [ "vcpkgScript" ];
  installPhase = ''
    cmake --build . --target=install --config=Release
    mkdir -p $out/share/vcpkg
    cp --preserve=mode -r ${vcpkg_src}/{docs,ports,scripts,triplets,.vcpkg-root,versions} $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
  '';
  enableParallelBuilding = true;
}

I actually like that solution, assuming upstream is unresponsive. But the “correct” solution may be to raise an issue upstream and see if that can be changed - sometimes they’re more willing to help than you’d think, even with large corporate projects :slight_smile:

If they don’t respond, that looks ready to be included in nixpkgs proper.

1 Like

@TLATER Already did! :grin: Support immutable vcpkg root and standard unix filesystem structure · Issue #22790 · microsoft/vcpkg · GitHub

2 Likes

It’s been a year and the vcpkg team did not add that feature. I think it still could be worth it to add your package into nixpkgs
Do you intend to upstream it @gracicot?

2 Likes

So, I played a bit with your package but could not yet get it to work. Here’s what I have so far:

Code
{
  autoconf,
  automake,
  cacert,
  cmake,
  cmrc,
  fetchFromGitHub,
  fmt_9,
  gcc,
  git,
  glibc,
  gperf,
  lib,
  libtool,
  libxkbcommon,
  m4,
  ninja,
  pkg-config,
  runtimeShell,
  stdenv,
  writeText,
  zip,
  zstd,
}:
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=";
  };

  buildInputs = [
    autoconf
    automake
    cacert
    cmake
    cmrc
    fmt_9
    gcc
    git
    m4
    ninja
    pkg-config
    zip
    zstd
  ];

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

  vcpkgScript = ''
    #!${runtimeShell}
    vcpkg_hash=$(echo -n "${placeholder "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 ${placeholder "out"}/share/vcpkg/{docs,ports,scripts,triplets,versions} $vcpkg_root_path/
    fi
    VCPKG_FORCE_SYSTEM_BINARIES=1 ${placeholder "out"}/share/vcpkg/vcpkg --vcpkg-root "$vcpkg_root_path" --downloads-root "$vcpkg_root_path/downloads" "$@"
  '';

  passAsFile = ["vcpkgScript"];

  installPhase = ''
    cmake --build . --target=install --config=Release
    mkdir -p $out/share/vcpkg
    cp --preserve=mode -r ${vcpkg_src}/{docs,ports,scripts,triplets,.vcpkg-root,versions} $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
  '';
}

We also need the cmrc package:

{
  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; [];
  };
}

My current issue comes from vcpkg not finding the system cmake. It should be able to find it, so I don’t know if the issue comes from the derivation or vcpkg itself

I actually found a proper way to make vcpkg behave. I never found time to actually implement it. Basically, the vcpkg toolchain just calls the vcpkg executable. You can replace the executable with a wrapper scripts that sets where to download, install and unpack libraires with command line options.