A small program to do nix deployments & provisioning into digitalocean.
This has a small subset of the features in nixops.
$ nix-env -i -f .- You must set:
DIGITALOCEAN_ACCESS_TOKENto do anything involving digitaloceanDIGITALOCEAN_SPACES_ACCESS_KEYandDIGITALOCEAN_SPACES_SECRET_KEYto upload images.
- You can set:
DEPLOY_NETWORK,DEPLOY_REGION,DEPLOY_TAG,DEPLOY_SPACES_REGION,DEPLOY_SPACES_BUCKETThese will stand in for arguments like
--network,--tagetc.
You need a network file, which should look mostly like what nixops wants.
The network file should have an attribute set in it containing a thing called network, and then other things which are the machines.
{
network = {
name = "my network";
defaults = {
deployment.sshKey = "ssh-rsa AAA ...";
deployment.digitalOcean.region = "lon1";
};
};
machine1 = {config, pkgs, ...} : {
deployment.digitalOcean.size = "c-32";
...
services.nginx.enable = true;
};
machine2 = ...;
}Extra things you can put in machine config or default are:
- deployment.digitalOcean.size
- a digitalocean size slug
- deployment.digitalOcean.region
- a digitalocean region slug
- deployment.digitalOcean.image
- either the numeric ID of an image, or the name of an image.
You can make an image using
oceanix imageoroceanix base-image. - deployment.digitalOcean.tag
- This isn’t something you can change, but you can refer to it elsewhere in the config; for example if you have tags
liveandstagingand you want those to go into the hostname you could saynetworking.hostName = "my-thing-${deployment.digitalOcean.tag}";
Note that you can get hold of a lot of this kind of information dynamically as well using the digitalocean metadata service, but this is a little easier and more nixy.
- deployment.sshKey
- an ssh public key; this will be enabled for root ssh login on the machine, and also added to digitalocean’s cloud-init setup.
- deployment.copies
- an integer; if > 1, this machine will be replaced with machine-1 machine-2 … machine-n.
- deployment.addHost
- true/false, if true this machine’s ip address will be baked into /etc/hosts on all the machines against its name. For copies > 1 the addresses of every copy will be baked in.
- deployment.keys
- A set of keys, like in nixops; you can write things like
deployment.keys.smtp = { keyFile = /path/to/secret.key; user = "root"; group = "root"; permissions = "0600"; transient = false; }; deployment.keys.fromPass.keyCommand = ["pass" "show" "secret-thing"];
If you set
transient = truethe key is copied into/run/keysand will be lost on reboot. If you settransient = falsethe key is copied into/var/keysand symlinked into/run/keys. The symlinks are restored on reboot.A bit like nixops there is a service you can depend on; it is called
keys@keynameso you could sayafter = [ "keys@smtp.service" ];andwants = [ "keys@smtp.service" ];to wait for that key.
oceanix depends on having a nixos image to start from (unlike nixops, which uses a fearsome script to brain-wipe an existing install).
It can create you an image with
$ oceanix base-image -k "SOME SSH PUBLIC KEY" -u base-image --spaces-bucket my-imagesThis will upload the image to lon1 under the name base-image, by transferring it via an S3 bucket called my-images in ams3.
Alternatively you can create images for a specific deployment with
$ oceanix image -n network.nix -u --spaces-bucket my-imagesThis will create images for each machine and upload them under the name given in deployment.digitalOcean.image.
If base-image fails with error
qemu-kvm: Invalid SMP CPUs 256. The max CPUs supported by machine 'pc-i440fx-8.1' is 255
- Turn off a CPU temporarily using:
sudo chcpu -d 255 - Create the image
- Then turn CPU back on:
sudo chcpu -e 255
(May also be possible to correct using the “-smp” option to qemu-kvm)
Deployments to go a digitalocean tag; if you run
$ oceanix deploy -n network.nix -t deployment-tagthis will
- List the machines on digitalocean tagged with
deployment-tag - List the machines defined in
network.nix - Create / destroy droplets so that there is exactly one droplet with
deployment-tagfor each machine innetwork.nix, whose name will be the name used innetwork.nixThis stage is where
oceanix provisionstops. - Build system root for these machines
- Deploy system root to the machines
- If you change a machine’s size or region, this is not aligned later, or reported on.
Management of regions in general is fairly poor.
- Some default configuration is baked into
digitalocean.nix, which you can’t replace right now. - The nix evaluation is done for every machine in the whole system in one go, which uses up a lot of memory if you have a lot of machines.
If you have a lot of identical machines you can say
deployment.copies = Non them though. - Host key checking is off, which is clearly not what anyone wants