Install NixOS on GCE: Difference between revisions

imported>Tubro
m Additional pre-requisites listed
imported>Tubro
Alternative Nix on GCP instructions
Line 1: Line 1:
This is a recipe for creating a NixOS machine on Google Compute Engine (GCE) which is part of [https://cloud.google.com/ Google Cloud Platform].
This is a recipe for creating a NixOS machine on Google Compute Engine (GCE) which is part of [https://cloud.google.com/ Google Cloud Platform].


This tutorial assumes you have already set up and account and project under Google Cloud Platform. We also assume that you have [https://nixos.org/download nix-shell] and KVM virtualization support, the latter is not available in Google Cloud Shell.  
This tutorial assumes you have already set up and account and project under Google Cloud Platform. We also assume that you have [https://nixos.org/download nix-shell] and KVM virtualization support, the latter is not available in Google Cloud Shell.


There are no publicly provided images of recent releases of NixOS. There are some old releases at [https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/gce-images.nix <nixpkgs/nixos/modules/virtualisation/gce-images.nix>] and in the <code>gs://nixos-images</code> and <code>gs://nixos-cloud-images</code> public buckets, but these have not been updated in years. Instead, it is recommended you build your own image.
There are no publicly provided images of recent releases of NixOS. There are some old releases at [https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/gce-images.nix <nixpkgs/nixos/modules/virtualisation/gce-images.nix>] and in the <code>gs://nixos-images</code> and <code>gs://nixos-cloud-images</code> public buckets, but these have not been updated in years. Instead, it is recommended you build your own image.
This guide is for people who really need NixOS... not just the Nix package manager. If Nix is all you need, you can install it automatically in with a [https://cloud.google.com/compute/docs/instances/startup-scripts/linux startup script]. Debian 12 startup script example:
<syntaxhighlight lang="bash">
#!/bin/bash
HOME="/root" sh <(curl -L https://nixos.org/nix/install) --daemon --yes
source /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
nix-env -i cowsay
cowsay 'nix is fully operational'
<syntaxhighlight lang="bash">


== Bootstrapping a NixOS image from the build of your choice ==
== Bootstrapping a NixOS image from the build of your choice ==