nixpkgs/pkgs/by-name/vc/vcpkg-tool/package.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

157 lines
3.9 KiB
Nix
Raw Normal View History

2023-10-10 20:10:23 +00:00
{ lib
, stdenv
, fetchFromGitHub
, runtimeShell
2023-10-10 20:10:23 +00:00
, cacert
, cmake
, cmakerc
2024-07-01 18:11:46 +00:00
, curl
2023-10-10 20:10:23 +00:00
, fmt
, git
, gzip
, meson
, ninja
, openssh
, python3
2024-07-01 18:11:46 +00:00
, unzip
2023-10-10 20:10:23 +00:00
, zip
, zstd
, extraRuntimeDeps ? []
, doWrap ? true
2023-10-10 20:10:23 +00:00
}:
stdenv.mkDerivation (finalAttrs: {
pname = "vcpkg-tool";
2024-06-13 03:02:28 +00:00
version = "2024-06-10";
2023-10-10 20:10:23 +00:00
src = fetchFromGitHub {
owner = "microsoft";
repo = "vcpkg-tool";
rev = finalAttrs.version;
2024-06-13 03:02:28 +00:00
hash = "sha256-TGRTzUd1FtErD+h/ksUsUm1Rhank9/yVy06JbAgEEw0=";
2023-10-10 20:10:23 +00:00
};
nativeBuildInputs = [
cmake
ninja
];
buildInputs = [
cmakerc
fmt
];
2023-10-10 20:10:23 +00:00
patches = [
./change-lock-location.patch
];
cmakeFlags = [
"-DVCPKG_DEPENDENCY_EXTERNAL_FMT=ON"
"-DVCPKG_DEPENDENCY_CMAKERC=ON"
];
passAsFile = [ "vcpkgWrapper" ];
vcpkgWrapper = let
2023-10-10 20:10:23 +00:00
# These are the most common binaries used by vcpkg
# Extra binaries can be added through override when needed
2023-10-10 20:10:23 +00:00
runtimeDeps = [
cacert
cmake
2024-07-01 18:11:46 +00:00
curl
2023-10-10 20:10:23 +00:00
git
gzip
meson
ninja
openssh
python3
2024-07-01 18:11:46 +00:00
unzip
2023-10-10 20:10:23 +00:00
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";
}
];
2023-10-10 20:10:23 +00:00
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"
2023-10-10 20:10:23 +00:00
'';
meta = {
description = "Components of microsoft/vcpkg's binary";
mainProgram = "vcpkg";
2023-10-10 20:10:23 +00:00
homepage = "https://github.com/microsoft/vcpkg-tool";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ guekka gracicot ];
platforms = lib.platforms.all;
};
})