2017-04-13 13:42:28 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#!/usr/bin/env nix-shell
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#! nix-shell -i bash -p google-cloud-sdk
							 | 
						
					
						
							
								
									
										
										
										
											2014-04-14 14:38:44 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-13 13:42:28 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								set -euo pipefail
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-06 10:56:56 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								BUCKET_NAME="${BUCKET_NAME:-nixos-cloud-images}"
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-13 13:42:28 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								TIMESTAMP="$(date +%Y%m%d%H%M)"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								export TIMESTAMP
							 | 
						
					
						
							
								
									
										
										
										
											2014-04-14 14:38:44 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-26 22:51:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								nix-build '<nixpkgs/nixos/lib/eval-config.nix>' \
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-13 13:42:28 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								   -A config.system.build.googleComputeImage \
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-26 22:51:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								   --arg modules "[ <nixpkgs/nixos/modules/virtualisation/google-compute-image.nix> ]" \
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-13 13:42:28 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								   --argstr system x86_64-linux \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								   -o gce \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								   -j 10
							 | 
						
					
						
							
								
									
										
										
										
											2014-04-14 14:38:44 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-13 13:42:28 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								img_path=$(echo gce/*.tar.gz)
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-24 10:53:12 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								img_name=${IMAGE_NAME:-$(basename "$img_path")}
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-13 13:42:28 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								img_id=$(echo "$img_name" | sed 's|.raw.tar.gz$||;s|\.|-|g;s|_|-|g')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								if ! gsutil ls "gs://${BUCKET_NAME}/$img_name"; then
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  gsutil cp "$img_path" "gs://${BUCKET_NAME}/$img_name"
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-06 10:56:56 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  gsutil acl ch -u AllUsers:R "gs://${BUCKET_NAME}/$img_name"
							 | 
						
					
						
							
								
									
										
										
										
											2014-04-14 14:38:44 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fi
							 |