at 23.11-beta 62 lines 2.1 kB view raw
1{ lib, google-cloud-sdk, runCommand, components }: 2 3comps_: 4 5let 6 # Remove components which are already installed by default 7 filterPreInstalled = 8 let 9 preInstalledComponents = with components; [ bq bq-nix core core-nix gcloud-deps gcloud gsutil gsutil-nix ]; 10 in 11 builtins.filter (drv: !(builtins.elem drv preInstalledComponents)); 12 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))); 17 18 # Components to install by default 19 defaultComponents = with components; [ alpha beta ]; 20 21 comps = [ google-cloud-sdk ] ++ filterPreInstalled (findDepsRecursive (defaultComponents ++ comps_)); 22in 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. 28runCommand "google-cloud-sdk-${google-cloud-sdk.version}" 29{ 30 inherit (google-cloud-sdk) meta; 31 inherit comps; 32 passAsFile = [ "comps" ]; 33 34 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 44 echo "Failed to install component '$comp'" 45 exit 1 46 fi 47 done 48 ''; 49} 50 '' 51 mkdir -p $out 52 53 # 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 59 60 # 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 ''