Install NixOS on GCE: Difference between revisions
imported>Tubro Alternative Nix on GCP instructions |
update example to 24.11 |
||
(5 intermediate revisions by 4 users not shown) | |||
Line 5: | Line 5: | ||
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 | 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 with a [https://cloud.google.com/compute/docs/instances/startup-scripts/linux startup script]. Debian 12 startup script example: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
Line 13: | Line 13: | ||
nix-env -i cowsay | nix-env -i cowsay | ||
cowsay 'nix is fully operational' | cowsay 'nix is fully operational' | ||
<syntaxhighlight | </syntaxhighlight> | ||
== Bootstrapping a NixOS image from the build of your choice == | == Bootstrapping a NixOS image from the build of your choice == | ||
This assumes you have created a Google Cloud project and a Google Cloud Storage bucket in that project. Set them as variables: | This assumes you have created a Google Cloud project and a Google Cloud Storage bucket that allows public access and uses Fine-grained access control (as opposed to Uniform) in that project. Set them as variables: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
Line 36: | Line 36: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
$ git clone --depth=1 --branch | $ git clone --depth=1 --branch nixos-24.11 https://github.com/NixOS/nixpkgs.git | ||
$ BUCKET_NAME=my_bucket_name nixpkgs/nixos/maintainers/scripts/gce/create-gce.sh | $ BUCKET_NAME=my_bucket_name nixpkgs/nixos/maintainers/scripts/gce/create-gce.sh | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 54: | Line 54: | ||
## <b>Metadata</b> | ## <b>Metadata</b> | ||
### <b>key</b> : <i>enable-oslogin</i> | ### <b>key</b> : <i>enable-oslogin</i> | ||
### <b>value</b> : <i>TRUE</i> | ### <b>value</b> : <i>"TRUE"</i> | ||
# Click <b>Create</b> | # Click <b>Create</b> | ||
# Wait until your VM instance is ready | # Wait until your VM instance is ready | ||
Line 89: | Line 89: | ||
At this point you may want to snapshot this image and use this snapshot to make future VMs. | At this point you may want to snapshot this image and use this snapshot to make future VMs. | ||
[[Category:Server]] | [[Category:Server]][[Category:Cookbook]] | ||
[[Category:Deployment]] |