1 { lib, google-cloud-sdk, callPackage, runCommand, components }:
6 # Remove components which are already installed by default
9 preInstalledComponents = with components; [ bq bq-nix core core-nix gcloud-deps gcloud gsutil gsutil-nix ];
11 builtins.filter (drv: !(builtins.elem drv preInstalledComponents));
13 # Recursively build a list of components with their dependencies
14 # TODO this could be made faster, it checks the dependencies too many times
15 findDepsRecursive = lib.converge
16 (drvs: lib.unique (drvs ++ (builtins.concatMap (drv: drv.dependencies) drvs)));
18 # Components to install by default
19 defaultComponents = with components; [ alpha beta ];
21 comps = [ google-cloud-sdk ] ++ filterPreInstalled (findDepsRecursive (defaultComponents ++ comps_));
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}"
30 inherit (google-cloud-sdk) meta;
32 passAsFile = [ "comps" ];
34 doInstallCheck = true;
37 compNames = builtins.map (drv: drv.name) comps_;
40 $out/bin/gcloud components list > component_list.txt
41 for comp in ${builtins.toString compNames}; do
42 if [ ! grep ... component_list.txt | grep "Not Installed" ]; then
43 echo "Failed to install component '$comp'"
52 # Install each component
53 for comp in $(cat $compsPath); do
54 echo "installing component $comp"
56 find $out -type d -exec chmod 744 {} +
59 # Replace references to the original google-cloud-sdk with this one
60 find $out/google-cloud-sdk/bin/ -type f -exec sed -i -e "s#${google-cloud-sdk}#$out#" {} \;