Install NixOS on GCE: Difference between revisions

imported>Fadenb
Created page with "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..."
 
imported>Mic92
Line 113: Line 113:
You normally can use a preexisting NixOS image, such as the ones found in gs://nixos-images. Sometimes the images there haven't been updated in a long time, or you need a newer one to work around a bug. If you need to make a new one, here's how. Perform these steps from any Linux machine.
You normally can use a preexisting NixOS image, such as the ones found in gs://nixos-images. Sometimes the images there haven't been updated in a long time, or you need a newer one to work around a bug. If you need to make a new one, here's how. Perform these steps from any Linux machine.


You'll need a working copy of the Google Cloud SDK, with the Cloud Storage and Compute Engine APIs enabled. You'll also need a Storage bucket. These steps will assume you've already made a bucket and it's named <code>gs://example</code>.
You'll need setup the credentials for Google Cloud, with the Cloud Storage and Compute Engine APIs enabled. You'll also need a Storage bucket. These steps will assume you've already made a bucket and it's named <code>gs://example</code>.
Prepare a local copy of the nixpkgs repository in the state you want to build from. If you want to build a released version, this means checking out one of the release branches from the nixpkgs-channels repository. Make sure you haven't left any unwanted local changes in it. These examples assume you've checked it out at <code>/home/example/nixpkgs-clean</code>.
Prepare a local copy of the nixpkgs repository in the state you want to build from. If you want to build a released version, this means checking out one of the release branches from the nixpkgs-channels repository. Make sure you haven't left any unwanted local changes in it. These examples assume you've checked it out at <code>/home/example/nixpkgs-clean</code>.


  $ NIXPKGS=/home/example/nixpkgs-clean NIXOS_CONFIG=/home/example/nixpkgs-clean/nixos/modules/virtualisation/google-compute-image.nix \
  $ BUCKET_NAME=example /home/example/nixpkgs-clean/maintainers/create-gce.sh
    nix-build /home/example/nixpkgs-clean/nixos -A config.system.build.googleComputeImage \
    --argstr system x86_64-linux


After a long build, this will leave a file in your current directory named something like <code>nixos-15.09pre-git-x86_64-linux.raw.tar.gz</code>. If you like to keep the names tidy and you were building from a stable release, feel free to delete "pre-git" from the filename.
This will create an image and upload it to the bucket <code>example</code>
 
Now go ahead and:
 
$ gsutil cp nixos-15.09-x86_64-linux.raw.tar.gz gs://example
 
The upload will take a little while.
 
If you're doing this as a maintainer of the official <code>gs://nixos-images</code> bucket, don't forget to verify that the permissions allow others to read the tar file.
When you want to instantiate this image, you can follow the normal preparation steps, replacing the value of <code>--source-uri with gs://example/nixos-15.09.x86_64-linux.tar.tar.gz</code>.
Note that you don't need to keep the tar file in your bucket after you've done the <code>gcloud compute images create step</code>, unless you want it to be available to others.