{ lib , stdenv , fetchFromGitHub , runtimeShell , cacert , cmake , cmakerc , curl , fmt , git , gzip , meson , ninja , openssh , python3 , unzip , zip , zstd , extraRuntimeDeps ? [] , doWrap ? true }: stdenv.mkDerivation (finalAttrs: { pname = "vcpkg-tool"; version = "2024-06-10"; src = fetchFromGitHub { owner = "microsoft"; repo = "vcpkg-tool"; rev = finalAttrs.version; hash = "sha256-TGRTzUd1FtErD+h/ksUsUm1Rhank9/yVy06JbAgEEw0="; }; nativeBuildInputs = [ cmake ninja ]; buildInputs = [ cmakerc fmt ]; patches = [ ./change-lock-location.patch ]; cmakeFlags = [ "-DVCPKG_DEPENDENCY_EXTERNAL_FMT=ON" "-DVCPKG_DEPENDENCY_CMAKERC=ON" ]; passAsFile = [ "vcpkgWrapper" ]; vcpkgWrapper = let # These are the most common binaries used by vcpkg # Extra binaries can be added through override when needed runtimeDeps = [ cacert cmake curl git gzip meson ninja openssh python3 unzip zip zstd ] ++ extraRuntimeDeps; # Apart from adding the runtime dependencies to $PATH, # the wrapper will also override these arguments by default. # This is to ensure that the executable does not try to # write to the nix store. If the user tries to set any of the # arguments themself, the wrapper will detect that the # arguments are present, and prefer the user-provided value. # # It is also possible to override the cli arguments by # settings either of the nix-specific environment variables. argsWithDefault = [ { arg = "--downloads-root"; env = "NIX_VCPKG_DOWNLOADS_ROOT"; default = "$NIX_VCPKG_WRITABLE_PATH/downloads"; } { arg = "--x-buildtrees-root"; env = "NIX_VCPKG_BUILDTREES_ROOT"; default = "$NIX_VCPKG_WRITABLE_PATH/buildtrees"; } { arg = "--x-packages-root"; env = "NIX_VCPKG_PACKAGES_ROOT"; default = "$NIX_VCPKG_WRITABLE_PATH/packages"; } { arg = "--x-install-root"; env = "NIX_VCPKG_INSTALL_ROOT"; default = "$NIX_VCPKG_WRITABLE_PATH/installed"; } ]; in '' #!${runtimeShell} NIX_VCPKG_WRITABLE_PATH=''${NIX_VCPKG_WRITABLE_PATH:-''${XDG_CACHE_HOME+"$XDG_CACHE_HOME/vcpkg"}} NIX_VCPKG_WRITABLE_PATH=''${NIX_VCPKG_WRITABLE_PATH:-''${HOME+"$HOME/.vcpkg/root"}} NIX_VCPKG_WRITABLE_PATH=''${NIX_VCPKG_WRITABLE_PATH:-''${TMP}} NIX_VCPKG_WRITABLE_PATH=''${NIX_VCPKG_WRITABLE_PATH:-'/tmp'} ${lib.concatMapStringsSep "\n" ({ env, default, ... }: ''${env}=''${${env}-"${default}"}'') argsWithDefault} export PATH="${lib.makeBinPath runtimeDeps}''${PATH:+":$PATH"}" ARGS=( "$@" ) FINAL_NONMODIFIED_ARGS=() for (( i=0; i<''${#ARGS[@]}; i++ )); do case "''${ARGS[i]%%=*}" in ${let f = { arg, env, ... }: '' '${arg}') ${env}="''${ARGS[i]#*=}" if [ "''$${env}" = '${arg}' ]; then ${env}="''${ARGS[i+1]}" ((i++)) fi ;; ''; in lib.concatMapStringsSep "\n" f argsWithDefault} *) FINAL_NONMODIFIED_ARGS+=(''${ARGS[i]}) ;; esac done exec -a "$0" "${placeholder "out"}/bin/.vcpkg-wrapped" \ ${lib.concatMapStringsSep "\n" ({ arg, env, ... }: " " + ''${arg}="''$${env}" \'') argsWithDefault} "''${FINAL_NONMODIFIED_ARGS[@]}" ''; postFixup = lib.optionalString doWrap '' mv "$out/bin/vcpkg" "$out/bin/.vcpkg-wrapped" install -Dm555 "$vcpkgWrapperPath" "$out/bin/vcpkg" ''; meta = { description = "Components of microsoft/vcpkg's binary"; mainProgram = "vcpkg"; homepage = "https://github.com/microsoft/vcpkg-tool"; license = lib.licenses.mit; maintainers = with lib.maintainers; [ guekka gracicot ]; platforms = lib.platforms.all; }; })