fluffychat: 1.22.1 -> 1.23.0 (#364091)
[NixPkgs.git] / pkgs / by-name / vc / vcpkg-tool / package.nix
blob2f776cb3c3af09252c3447d2fd064bad53a8b05d
2   lib,
3   stdenv,
4   fetchFromGitHub,
5   runtimeShell,
6   apple-sdk_11,
7   cacert,
8   cmake,
9   cmakerc,
10   curl,
11   fmt,
12   git,
13   gzip,
14   meson,
15   ninja,
16   openssh,
17   python3,
18   unzip,
19   zip,
20   zstd,
21   runCommand,
22   writeText,
23   extraRuntimeDeps ? [ ],
24   doWrap ? true,
26 stdenv.mkDerivation (finalAttrs: {
27   pname = "vcpkg-tool";
28   version = "2024-07-10";
30   src = fetchFromGitHub {
31     owner = "microsoft";
32     repo = "vcpkg-tool";
33     rev = finalAttrs.version;
34     hash = "sha256-P/ARKMfZdrfO+24rBrRm9k8tkBPSJJBqH509+iarNkw=";
35   };
37   nativeBuildInputs = [
38     cmake
39     ninja
40   ];
42   buildInputs = [
43     cmakerc
44     fmt
45   ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ apple-sdk_11 ];
47   patches = [
48     ./change-lock-location.patch
49     ./read-bundle-info-from-root.patch
50   ];
52   cmakeFlags = [
53     "-DVCPKG_DEPENDENCY_EXTERNAL_FMT=ON"
54     "-DVCPKG_DEPENDENCY_CMAKERC=ON"
55   ];
57   passAsFile = [ "vcpkgWrapper" ];
58   vcpkgWrapper =
59     let
60       # These are the most common binaries used by vcpkg
61       # Extra binaries can be added through override when needed
62       runtimeDeps = [
63         cacert
64         cmake
65         curl
66         git
67         gzip
68         meson
69         ninja
70         openssh
71         python3
72         unzip
73         zip
74         zstd
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.
83       #
84       # It is also possible to override the cli arguments by
85       # settings either of the nix-specific environment variables.
86       argsWithDefault = [
87         {
88           arg = "--downloads-root";
89           env = "NIX_VCPKG_DOWNLOADS_ROOT";
90           default = "$NIX_VCPKG_WRITABLE_PATH/downloads";
91         }
92         {
93           arg = "--x-buildtrees-root";
94           env = "NIX_VCPKG_BUILDTREES_ROOT";
95           default = "$NIX_VCPKG_WRITABLE_PATH/buildtrees";
96         }
97         {
98           arg = "--x-packages-root";
99           env = "NIX_VCPKG_PACKAGES_ROOT";
100           default = "$NIX_VCPKG_WRITABLE_PATH/packages";
101         }
102         {
103           arg = "--x-install-root";
104           env = "NIX_VCPKG_INSTALL_ROOT";
105           default = "$NIX_VCPKG_WRITABLE_PATH/installed";
106         }
107       ];
108     in
109     ''
110       #!${runtimeShell}
112       get_vcpkg_path() {
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
120             echo "$TMP"
121         else
122             echo "/tmp"
123         fi
124       }
126       NIX_VCPKG_WRITABLE_PATH=$(get_vcpkg_path)
128       ${lib.concatMapStringsSep "\n" (
129         { env, default, ... }: ''${env}=''${${env}-"${default}"}''
130       ) argsWithDefault}
132       export PATH="${lib.makeBinPath runtimeDeps}''${PATH:+":$PATH"}"
134       ARGS=( "$@" )
135       FINAL_NONMODIFIED_ARGS=()
137       for (( i=0; i<''${#ARGS[@]}; i++ ));
138       do
139         case "''${ARGS[i]%%=*}" in
140           ${
141             let
142               f =
143                 { arg, env, ... }:
144                 ''
145                   '${arg}')
146                     ${env}="''${ARGS[i]#*=}"
147                     if [ "''$${env}" = '${arg}' ]; then
148                       ${env}="''${ARGS[i+1]}"
149                       ((i++))
150                     fi
151                     ;;
152                 '';
153             in
154             lib.concatMapStringsSep "\n" f argsWithDefault
155           }
156           *)
157             FINAL_NONMODIFIED_ARGS+=(''${ARGS[i]})
158             ;;
159         esac
160       done
162       if [ "''${NIX_VCPKG_DEBUG_PRINT_ENVVARS-'false'}" = 'true' ]; then
163         ${lib.concatMapStringsSep "\n" (
164           { env, ... }: "  " + ''echo "${env} = ''$${env}"''
165         ) argsWithDefault}
166         echo ""
167       fi
169       exec -a "$0" "${placeholder "out"}/bin/.vcpkg-wrapped" \
170       ${lib.concatMapStringsSep "\n" ({ arg, env, ... }: "  " + ''${arg}="''$${env}" \'') argsWithDefault}
171         "''${FINAL_NONMODIFIED_ARGS[@]}"
172     '';
174   postFixup = lib.optionalString doWrap ''
175     mv "$out/bin/vcpkg" "$out/bin/.vcpkg-wrapped"
176     install -Dm555 "$vcpkgWrapperPath" "$out/bin/vcpkg"
177   '';
179   passthru.tests = {
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
189       ''}
190     '';
191   };
193   meta = {
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; [
200       guekka
201       gracicot
202       h7x4
203     ];
204     platforms = lib.platforms.all;
205   };