https://github.com/kaiju/nixos-image-gcloud-example
NixOS Image Building for Google Cloud Compute Engine
https://github.com/kaiju/nixos-image-gcloud-example
cloud-infrastructure configuration-management devops google-cloud nixos
Last synced: about 14 hours ago
JSON representation
NixOS Image Building for Google Cloud Compute Engine
- Host: GitHub
- URL: https://github.com/kaiju/nixos-image-gcloud-example
- Owner: kaiju
- Created: 2025-10-24T02:54:01.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-10-25T00:05:07.000Z (9 months ago)
- Last Synced: 2025-11-01T15:07:36.705Z (8 months ago)
- Topics: cloud-infrastructure, configuration-management, devops, google-cloud, nixos
- Language: Nix
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NixOS Image Building for Google Cloud Compute Engine
The only thing better than having declarative configuration management as a first class feature of your OS is leveraging it to build deployable images from your system configuration. No more hacking together Ansible and Packer or shoving overwrought shell scripts into cloud-init!
NixOS provides [modules](https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/image/images.nix) that can be used to build a variety of images. In this example we'll use the [`google-compute`](https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/google-compute-image.nix) module to build an image suitable for deploying on Google Cloud.
## Building
On NixOS:
```
# nixos-rebuild build-image --flake '.#example' --image-variant google-compute
```
Alternatively with Nix on other Linux environments:
```
# nix build '.#nixosConfigurations.example.config.system.build.images.google-compute'
```
Upload image result to GCS:
```
# gcloud storage cp result/image.raw.tar.gz gs:///
```
Create new Compute Engine image:
```
# gcloud compute images create nixos-example-image --source-uri gs:///image.raw.tar.gz
```
## Cloud Build
The image build & publish process can also be automated with Cloud Build. `cloudbuild.yaml` is a pipeline that creates a Nix builder, builds the system image, uploads it to GCS, and creates a new image in Compute Engine.
```
# gcloud builds submit . --substitutions="_BUCKET=,SHORT_SHA=$(git rev-parse --short HEAD)"
```