Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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 installCheckPhase = 36 let 37 compNames = builtins.map (drv: drv.name) comps_; 38 in 39 '' 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'" 44 exit 1 45 fi 46 done 47 ''; 48} 49 '' 50 mkdir -p $out 51 52 # Install each component 53 for comp in $(cat $compsPath); do 54 echo "installing component $comp" 55 cp -dRf $comp/. $out 56 find $out -type d -exec chmod 744 {} + 57 done 58 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#" {} \; 61 ''