gce/create-gce.sh: rewrite using nix-shell shebang and bash (#24869)

* google-cloud-sdk: 150.0.0 -> 151.0.0

- gce/create-gce.sh: rewrite using nix-shell shebang and bash
- allows to run the script without being the same directory
- nix-shell install google-cloud-sdk
- some shellcheck cleanups and scripting best practice
- gce/create-gce.sh: do not clobber NIX_PATH: this allows NIX_PATH to be overwritten to build a different release
- gce/create-gce.sh: remove legacy hydra option

authored by

Jörg Thalheim and committed by
GitHub
73c8797d d3c737a0

+22 -14
+18 -10
nixos/maintainers/scripts/gce/create-gce.sh
··· 1 - #! /bin/sh -e 2 3 - BUCKET_NAME=${BUCKET_NAME:-nixos-images} 4 - export NIX_PATH=nixpkgs=../../../.. 5 - export NIXOS_CONFIG=$(dirname $(readlink -f $0))/../../../modules/virtualisation/google-compute-image.nix 6 - export TIMESTAMP=$(date +%Y%m%d%H%M) 7 8 nix-build '<nixpkgs/nixos>' \ 9 - -A config.system.build.googleComputeImage --argstr system x86_64-linux -o gce --option extra-binary-caches http://hydra.nixos.org -j 10 10 11 - img=$(echo gce/*.tar.gz) 12 - if ! gsutil ls gs://${BUCKET_NAME}/$(basename $img); then 13 - gsutil cp $img gs://${BUCKET_NAME}/$(basename $img) 14 fi 15 - gcloud compute images create $(basename $img .raw.tar.gz | sed 's|\.|-|' | sed 's|_|-|') --source-uri gs://${BUCKET_NAME}/$(basename $img)
··· 1 + #!/usr/bin/env nix-shell 2 + #! nix-shell -i bash -p google-cloud-sdk 3 4 + set -euo pipefail 5 + 6 + BUCKET_NAME="${BUCKET_NAME:-nixos-images}" 7 + TIMESTAMP="$(date +%Y%m%d%H%M)" 8 + export TIMESTAMP 9 10 nix-build '<nixpkgs/nixos>' \ 11 + -A config.system.build.googleComputeImage \ 12 + --arg configuration "{ imports = [ <nixpkgs/nixos/modules/virtualisation/google-compute-image.nix> ]; }" \ 13 + --argstr system x86_64-linux \ 14 + -o gce \ 15 + -j 10 16 17 + img_path=$(echo gce/*.tar.gz) 18 + img_name=$(basename "$img_path") 19 + img_id=$(echo "$img_name" | sed 's|.raw.tar.gz$||;s|\.|-|g;s|_|-|g') 20 + if ! gsutil ls "gs://${BUCKET_NAME}/$img_name"; then 21 + gsutil cp "$img_path" "gs://${BUCKET_NAME}/$img_name" 22 fi 23 + gcloud compute images create "$img_id" --source-uri "gs://${BUCKET_NAME}/$img_name"
+4 -4
pkgs/tools/admin/google-cloud-sdk/default.nix
··· 7 8 stdenv.mkDerivation rec { 9 name = "google-cloud-sdk-${version}"; 10 - version = "150.0.0"; 11 12 src = 13 if stdenv.system == "i686-linux" then 14 fetchurl { 15 url = "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${name}-linux-x86.tar.gz"; 16 - sha256 = "0zg6jnn93dq53glds4cghksyghb4d4z0i2h38na0r88mr8hzmx1l"; 17 } 18 else if stdenv.system == "x86_64-darwin" then 19 fetchurl { 20 url = "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${name}-darwin-x86_64.tar.gz"; 21 - sha256 = "1vbc360z2da3blwx51asw7jh0v0v6wsrv20z36yq0hccmljlh24w"; 22 } 23 else 24 fetchurl { 25 url = "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${name}-linux-x86_64.tar.gz"; 26 - sha256 = "1q66aap3qidfsa8gm13jff3dprx8qarhjkx5ib65439fy4zj0bca"; 27 }; 28 29 buildInputs = [python27 makeWrapper];
··· 7 8 stdenv.mkDerivation rec { 9 name = "google-cloud-sdk-${version}"; 10 + version = "151.0.0"; 11 12 src = 13 if stdenv.system == "i686-linux" then 14 fetchurl { 15 url = "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${name}-linux-x86.tar.gz"; 16 + sha256 = "1d1h6jiqs3grsb6c61v6dkb4l2qv6v8g7wbzgaqkmn09xdbaq40l"; 17 } 18 else if stdenv.system == "x86_64-darwin" then 19 fetchurl { 20 url = "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${name}-darwin-x86_64.tar.gz"; 21 + sha256 = "05idf0g505s8diaz28ij9yqig2wwn43lyppfs483m7vnx5hk62j5"; 22 } 23 else 24 fetchurl { 25 url = "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${name}-linux-x86_64.tar.gz"; 26 + sha256 = "01hf7pp1v57dxx6f2pz7j13fjdnrfp7gjmzjdlhlx4rnvxrd6i3f"; 27 }; 28 29 buildInputs = [python27 makeWrapper];