diff --git a/README.adoc b/README.adoc index cd5cba94..5b6a1090 100644 --- a/README.adoc +++ b/README.adoc @@ -161,6 +161,7 @@ nixos-config ├── lib/ ├── modules/ ├── pkgs/ +├── scripts/ ├── secrets/ ├── shells/ ├── templates/ @@ -183,6 +184,9 @@ For more information, see the link:./modules/README.adoc[related documentation]. * link:./pkgs/[`./pkgs/`] contains my custom packages. It is exported in the flakes at `outputs.packages` compiled through various systems. +* link:./scripts/[./scripts/] contains various scripts for various purposes. +Should be self-explanatory. + * link:./secrets/[`./secrets/`] contains my secrets managed with link:https://github.com/mozilla/sops[sops] and link:https://github.com/Mic92/sops-nix[sops-nix]. * link:./shells/[`./shells/`] contains my development shells for interacting with the usual type of projects. diff --git a/scripts/generate-and-upload-gce-image b/scripts/generate-and-upload-gce-image new file mode 100755 index 00000000..8d6a5f11 --- /dev/null +++ b/scripts/generate-and-upload-gce-image @@ -0,0 +1,58 @@ +#!/usr/bin/env nix-shell +#! nix-shell -i bash -p google-cloud-sdk +# +# This is a modified script `nixos/maintainers/scripts/gce/create-gce.sh' from +# `nixpkgs'. +# +# Licensed under MIT license +# Copyright (c) 2003-2022 Eelco Dolstra and the Nixpkgs/NixOS contributors +# 2022 Gabriel Arazas +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +BUCKET_NAME="${BUCKET_NAME:-foodogsquared-operating-system-images-dumping-ground}" +TIMESTAMP="$(date +%Y%m%d%H%M)" +PACKAGE=plover-gce +DIRECTORY=gce-image +export TIMESTAMP + +nix build ".#$PACKAGE" -o "$DIRECTORY" + +img_path=$(echo "$DIRECTORY"/*.tar.gz) +img_name=${IMAGE_NAME:-$(basename "$img_path")} +img_id=$(echo "$img_name" | sed 's|.raw.tar.gz$||;s|\.|-|g;s|_|-|g') +img_family=$(echo "$img_id" | cut -d - -f1-4) + +if ! gsutil ls "gs://${BUCKET_NAME}/$img_name"; then + gsutil cp "$img_path" "gs://${BUCKET_NAME}/$img_name" + + gcloud compute images create \ + "$img_id" \ + --source-uri "gs://${BUCKET_NAME}/$img_name" \ + --family="$img_family" + + gcloud compute images add-iam-policy-binding \ + "$img_id" \ + --member='allAuthenticatedUsers' \ + --role='roles/compute.imageUser' +fi + +# vi:ft=bash