···1-{ lib, google-cloud-sdk, runCommand, components }:
23comps_:
4···19 defaultComponents = with components; [ alpha beta ];
2021 comps = [ google-cloud-sdk ] ++ filterPreInstalled (findDepsRecursive (defaultComponents ++ comps_));
22-in
23-# Components are installed by copying the `google-cloud-sdk` package, along
24-# with each component, over to a new location, and then patching that location
25-# with `sed` to ensure the proper paths are used.
26-# For some reason, this does not work properly with a `symlinkJoin`: the
27-# `gcloud` binary doesn't seem able to find the installed components.
28-runCommand "google-cloud-sdk-${google-cloud-sdk.version}"
29-{
30- inherit (google-cloud-sdk) meta;
31- inherit comps;
32- passAsFile = [ "comps" ];
3334- doInstallCheck = true;
35- disallowedRequisites = [ google-cloud-sdk ];
36- installCheckPhase =
37 let
38- compNames = builtins.map (drv: drv.name) comps_;
39 in
40 ''
41- $out/bin/gcloud components list > component_list.txt
42 for comp in ${builtins.toString compNames}; do
43- if [ ! grep ... component_list.txt | grep "Not Installed" ]; then
0000000000044 echo "Failed to install component '$comp'"
45 exit 1
46 fi
47 done
48 '';
49-}
50- ''
51- mkdir -p $out
00005253- # Install each component
54- for comp in $(cat $compsPath); do
55- echo "installing component $comp"
56- cp -dRf $comp/. $out
57- find $out -type d -exec chmod 744 {} +
58- done
5960- # Replace references to the original google-cloud-sdk with this one
61- find $out/google-cloud-sdk -type f -exec sed -i -e "s#${google-cloud-sdk}#$out#" {} \;
62- ''
000
···1+{ lib, google-cloud-sdk, symlinkJoin, components }:
23comps_:
4···19 defaultComponents = with components; [ alpha beta ];
2021 comps = [ google-cloud-sdk ] ++ filterPreInstalled (findDepsRecursive (defaultComponents ++ comps_));
000000000002223+ installCheck =
0024 let
25+ compNames = builtins.map lib.getName comps_;
26 in
27 ''
28+ $out/bin/gcloud components list --only-local-state --format 'value(id)' > component_list.txt
29 for comp in ${builtins.toString compNames}; do
30+ snapshot_file="$out/google-cloud-sdk/.install/$comp.snapshot.json"
31+32+ if ! [ -f "$snapshot_file" ]; then
33+ echo "Failed to install component '$comp'"
34+ exit 1
35+ fi
36+37+ if grep --quiet '"is_hidden":true' "$snapshot_file"; then
38+ continue
39+ fi
40+41+ if ! grep --quiet "^$comp$" component_list.txt; then
42 echo "Failed to install component '$comp'"
43 exit 1
44 fi
45 done
46 '';
47+in
48+# The `gcloud` entrypoint script has some custom logic to determine the "real" cloud sdk
49+# root. In order to not trip up this logic and still have the symlink joined root we copy
50+# over this file. Since this file also has a Python wrapper, we need to copy that as well.
51+symlinkJoin {
52+ name = "google-cloud-sdk-${google-cloud-sdk.version}";
53+ inherit (google-cloud-sdk) meta;
5455+ paths = [
56+ google-cloud-sdk
57+ ] ++ comps;
0005859+ postBuild = ''
60+ sed -i ';' $out/google-cloud-sdk/bin/.gcloud-wrapped
61+ sed -i -e "s#${google-cloud-sdk}#$out#" "$out/google-cloud-sdk/bin/gcloud"
62+ ${installCheck}
63+ '';
64+}