23 extraRuntimeDeps ? [ ],
26 stdenv.mkDerivation (finalAttrs: {
28 version = "2024-07-10";
30 src = fetchFromGitHub {
33 rev = finalAttrs.version;
34 hash = "sha256-P/ARKMfZdrfO+24rBrRm9k8tkBPSJJBqH509+iarNkw=";
45 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ apple-sdk_11 ];
48 ./change-lock-location.patch
49 ./read-bundle-info-from-root.patch
53 "-DVCPKG_DEPENDENCY_EXTERNAL_FMT=ON"
54 "-DVCPKG_DEPENDENCY_CMAKERC=ON"
57 passAsFile = [ "vcpkgWrapper" ];
60 # These are the most common binaries used by vcpkg
61 # Extra binaries can be added through override when needed
75 ] ++ extraRuntimeDeps;
77 # Apart from adding the runtime dependencies to $PATH,
78 # the wrapper will also override these arguments by default.
79 # This is to ensure that the executable does not try to
80 # write to the nix store. If the user tries to set any of the
81 # arguments themself, the wrapper will detect that the
82 # arguments are present, and prefer the user-provided value.
84 # It is also possible to override the cli arguments by
85 # settings either of the nix-specific environment variables.
88 arg = "--downloads-root";
89 env = "NIX_VCPKG_DOWNLOADS_ROOT";
90 default = "$NIX_VCPKG_WRITABLE_PATH/downloads";
93 arg = "--x-buildtrees-root";
94 env = "NIX_VCPKG_BUILDTREES_ROOT";
95 default = "$NIX_VCPKG_WRITABLE_PATH/buildtrees";
98 arg = "--x-packages-root";
99 env = "NIX_VCPKG_PACKAGES_ROOT";
100 default = "$NIX_VCPKG_WRITABLE_PATH/packages";
103 arg = "--x-install-root";
104 env = "NIX_VCPKG_INSTALL_ROOT";
105 default = "$NIX_VCPKG_WRITABLE_PATH/installed";
113 if [[ -n $NIX_VCPKG_WRITABLE_PATH ]]; then
114 echo "$NIX_VCPKG_WRITABLE_PATH"
115 elif [[ -n $XDG_CACHE_HOME ]]; then
116 echo "$XDG_CACHE_HOME/vcpkg"
117 elif [[ -n $HOME ]]; then
118 echo "$HOME/.vcpkg/root"
119 elif [[ -n $TMP ]]; then
126 NIX_VCPKG_WRITABLE_PATH=$(get_vcpkg_path)
128 ${lib.concatMapStringsSep "\n" (
129 { env, default, ... }: ''${env}=''${${env}-"${default}"}''
132 export PATH="${lib.makeBinPath runtimeDeps}''${PATH:+":$PATH"}"
135 FINAL_NONMODIFIED_ARGS=()
137 for (( i=0; i<''${#ARGS[@]}; i++ ));
139 case "''${ARGS[i]%%=*}" in
146 ${env}="''${ARGS[i]#*=}"
147 if [ "''$${env}" = '${arg}' ]; then
148 ${env}="''${ARGS[i+1]}"
154 lib.concatMapStringsSep "\n" f argsWithDefault
157 FINAL_NONMODIFIED_ARGS+=(''${ARGS[i]})
162 if [ "''${NIX_VCPKG_DEBUG_PRINT_ENVVARS-'false'}" = 'true' ]; then
163 ${lib.concatMapStringsSep "\n" (
164 { env, ... }: " " + ''echo "${env} = ''$${env}"''
169 exec -a "$0" "${placeholder "out"}/bin/.vcpkg-wrapped" \
170 ${lib.concatMapStringsSep "\n" ({ arg, env, ... }: " " + ''${arg}="''$${env}" \'') argsWithDefault}
171 "''${FINAL_NONMODIFIED_ARGS[@]}"
174 postFixup = lib.optionalString doWrap ''
175 mv "$out/bin/vcpkg" "$out/bin/.vcpkg-wrapped"
176 install -Dm555 "$vcpkgWrapperPath" "$out/bin/vcpkg"
180 testWrapper = runCommand "vcpkg-tool-test-wrapper" { buildInputs = [ finalAttrs.finalPackage ]; } ''
181 export NIX_VCPKG_DEBUG_PRINT_ENVVARS=true
182 vcpkg --x-packages-root="test" --x-install-root="test2" contact > "$out"
184 cat "$out" | head -n 4 | diff - ${writeText "vcpkg-tool-test-wrapper-expected" ''
185 NIX_VCPKG_DOWNLOADS_ROOT = /homeless-shelter/.vcpkg/root/downloads
186 NIX_VCPKG_BUILDTREES_ROOT = /homeless-shelter/.vcpkg/root/buildtrees
187 NIX_VCPKG_PACKAGES_ROOT = test
188 NIX_VCPKG_INSTALL_ROOT = test2
194 description = "Components of microsoft/vcpkg's binary";
195 mainProgram = "vcpkg";
196 homepage = "https://github.com/microsoft/vcpkg-tool";
197 changelog = "https://github.com/microsoft/vcpkg-tool/releases/tag/${finalAttrs.src.rev}";
198 license = lib.licenses.mit;
199 maintainers = with lib.maintainers; [
204 platforms = lib.platforms.all;