21 , extraRuntimeDeps ? []
24 stdenv.mkDerivation (finalAttrs: {
26 version = "2024-07-10";
28 src = fetchFromGitHub {
31 rev = finalAttrs.version;
32 hash = "sha256-P/ARKMfZdrfO+24rBrRm9k8tkBPSJJBqH509+iarNkw=";
46 ./change-lock-location.patch
47 ./read-bundle-info-from-root.patch
51 "-DVCPKG_DEPENDENCY_EXTERNAL_FMT=ON"
52 "-DVCPKG_DEPENDENCY_CMAKERC=ON"
56 passAsFile = [ "vcpkgWrapper" ];
58 # These are the most common binaries used by vcpkg
59 # Extra binaries can be added through override when needed
73 ] ++ extraRuntimeDeps;
75 # Apart from adding the runtime dependencies to $PATH,
76 # the wrapper will also override these arguments by default.
77 # This is to ensure that the executable does not try to
78 # write to the nix store. If the user tries to set any of the
79 # arguments themself, the wrapper will detect that the
80 # arguments are present, and prefer the user-provided value.
82 # It is also possible to override the cli arguments by
83 # settings either of the nix-specific environment variables.
86 arg = "--downloads-root";
87 env = "NIX_VCPKG_DOWNLOADS_ROOT";
88 default = "$NIX_VCPKG_WRITABLE_PATH/downloads";
91 arg = "--x-buildtrees-root";
92 env = "NIX_VCPKG_BUILDTREES_ROOT";
93 default = "$NIX_VCPKG_WRITABLE_PATH/buildtrees";
96 arg = "--x-packages-root";
97 env = "NIX_VCPKG_PACKAGES_ROOT";
98 default = "$NIX_VCPKG_WRITABLE_PATH/packages";
101 arg = "--x-install-root";
102 env = "NIX_VCPKG_INSTALL_ROOT";
103 default = "$NIX_VCPKG_WRITABLE_PATH/installed";
110 if [[ -n $NIX_VCPKG_WRITABLE_PATH ]]; then
111 echo "$NIX_VCPKG_WRITABLE_PATH"
112 elif [[ -n $XDG_CACHE_HOME ]]; then
113 echo "$XDG_CACHE_HOME/vcpkg"
114 elif [[ -n $HOME ]]; then
115 echo "$HOME/.vcpkg/root"
116 elif [[ -n $TMP ]]; then
123 NIX_VCPKG_WRITABLE_PATH=$(get_vcpkg_path)
125 ${lib.concatMapStringsSep "\n" ({ env, default, ... }: ''${env}=''${${env}-"${default}"}'') argsWithDefault}
127 export PATH="${lib.makeBinPath runtimeDeps}''${PATH:+":$PATH"}"
130 FINAL_NONMODIFIED_ARGS=()
132 for (( i=0; i<''${#ARGS[@]}; i++ ));
134 case "''${ARGS[i]%%=*}" in
136 f = { arg, env, ... }: ''
138 ${env}="''${ARGS[i]#*=}"
139 if [ "''$${env}" = '${arg}' ]; then
140 ${env}="''${ARGS[i+1]}"
145 in lib.concatMapStringsSep "\n" f argsWithDefault}
147 FINAL_NONMODIFIED_ARGS+=(''${ARGS[i]})
152 if [ "''${NIX_VCPKG_DEBUG_PRINT_ENVVARS-'false'}" = 'true' ]; then
153 ${lib.concatMapStringsSep "\n" ({ env, ... }: " " + ''echo "${env} = ''$${env}"'') argsWithDefault}
157 exec -a "$0" "${placeholder "out"}/bin/.vcpkg-wrapped" \
158 ${lib.concatMapStringsSep "\n" ({ arg, env, ... }: " " + ''${arg}="''$${env}" \'') argsWithDefault}
159 "''${FINAL_NONMODIFIED_ARGS[@]}"
162 postFixup = lib.optionalString doWrap ''
163 mv "$out/bin/vcpkg" "$out/bin/.vcpkg-wrapped"
164 install -Dm555 "$vcpkgWrapperPath" "$out/bin/vcpkg"
168 testWrapper = runCommand "vcpkg-tool-test-wrapper" { buildInputs = [ finalAttrs.finalPackage ]; } ''
169 export NIX_VCPKG_DEBUG_PRINT_ENVVARS=true
170 vcpkg --x-packages-root="test" --x-install-root="test2" contact > "$out"
172 cat "$out" | head -n 4 | diff - ${writeText "vcpkg-tool-test-wrapper-expected" ''
173 NIX_VCPKG_DOWNLOADS_ROOT = /homeless-shelter/.vcpkg/root/downloads
174 NIX_VCPKG_BUILDTREES_ROOT = /homeless-shelter/.vcpkg/root/buildtrees
175 NIX_VCPKG_PACKAGES_ROOT = test
176 NIX_VCPKG_INSTALL_ROOT = test2
182 description = "Components of microsoft/vcpkg's binary";
183 mainProgram = "vcpkg";
184 homepage = "https://github.com/microsoft/vcpkg-tool";
185 changelog = "https://github.com/microsoft/vcpkg-tool/releases/tag/${finalAttrs.src.rev}";
186 license = lib.licenses.mit;
187 maintainers = with lib.maintainers; [ guekka gracicot h7x4 ];
188 platforms = lib.platforms.all;