Skip to content

Instantly share code, notes, and snippets.

@fadenb
Created March 21, 2021 09:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fadenb/4267f71b858e590a789a1dbaad7b1d09 to your computer and use it in GitHub Desktop.
Save fadenb/4267f71b858e590a789a1dbaad7b1d09 to your computer and use it in GitHub Desktop.
Spin up a Genesis Cloud CPU instance and transform it with nixos-infect into a NixOS system. (example for nixos.wiki)
#!/usr/bin/env nix-shell
#! nix-shell -p jq -p bash -i bash
# Notes:
# Replace <MY TOKEN> with your API token
# Replace <NICKNAME> with the nickname of your instance
# Replace <HOSTNAME> with the hostname of your instance
# `vcpu-8_memory-16g_disk-80g` indicates the instance type; See https://developers.genesiscloud.com/instances#instance-types for details
# `6d5c3613-f6cb-48e1-8711-14f084060209` is the ID for the current default Ubuntu 16.04 image. Image IDs can be queried via the API: https://developers.genesiscloud.com/images#list-images
# `2b7ab082-e9f2-40f0-a410-a6337b6a6d42` is the ID for my previosly configured SSH pubkey. Key IDs can be queried via the API: https://developers.genesiscloud.com/ssh-keys#list-ssh-keys
# Create a new instance, unmount /boot to avoid issues with nixos-infect, run nixos-infect and reboot into the new system if successful
# During the nixos-infect process, you can SSH to the instance using the username `ubuntu` and the selected SSH key.
# After a successful nixos-infect run, the instance will reboot and you can log on via SSH using the username `root` and the same SSH key as before.
curl --request POST 'https://api.genesiscloud.com/compute/v1/instances' \
-H 'X-Auth-Token: <MY TOKEN>' \
-H 'Content-Type: application/json' \
--data-raw '
{
"name": "<NICKNAME>",
"hostname": "<HOSTNAME>",
"type": "vcpu-8_memory-16g_disk-80g",
"image": "6d5c3613-f6cb-48e1-8711-14f084060209",
"ssh_keys": ["2b7ab082-e9f2-40f0-a410-a6337b6a6d42"],
"metadata":{
"startup_script":"#!/bin/bash\numount -l /boot & curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | NIX_CHANNEL=nixos-unstable bash 2>&1 | tee /tmp/infect.log\n"
}
}' | jq '.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment