Skip to content

Commit

Permalink
Linode support for NixOps.
Browse files Browse the repository at this point in the history
  • Loading branch information
GlennS committed Aug 23, 2017
1 parent c06c0e7 commit 42c1076
Show file tree
Hide file tree
Showing 10 changed files with 607 additions and 2 deletions.
56 changes: 55 additions & 1 deletion doc/manual/overview.xml
Expand Up @@ -1476,8 +1476,62 @@ xlink:href="https://github.com/elitak/nixos-infect">nixos-infect</link>
</para>
</section>

<section><title>Deploying to Libvirtd (Qemu)</title>
<section><title>Deploying to Linode</title>

<para>First you will need to create an account with <link
xlink:href="https://www.linode.com/">Linode</link>.</para>

<para>Next, you need to visit <link
xlink:href="https://cloud.linode.com/">Linode's new manager
interface</link>, then navigate to profile and then <link
xlink_href="https://cloud.linode.com/profile/tokens">API
tokens</link>. From here click 'Create a Personal Access Token'. You
should now be asked which permissions you want the API token to
have. NixOps requires Delete access in the 'Linodes' category. Make
sure to keep a note down the long code which appears when you confirm
- there is no way to see it again.</para>

<para>NixOps needs to know your personal API key. You can tell it by
setting the <literal>deployment.linode.personalAPIKey</literal>
property, or the <envvar>LINODE_PERSONAL_API_KEY</envvar> environment
variable.</para>

<para>The personal API key will be stored in the NixOps state file (an
SQLite database), so you should make sure that this file is
secure.</para>

<para><xref linkend="ex-trivial-linode.nix" /> shows how to run +a
<literal>Linode 2048</literal> instance in the <literal>Frankfurt,
Germany</literal> region.</para>

<example xml:id="ex-trivial-linode.nix">
<title><filename>trivial-linode.nix</filename>: A trivial Linode setup</title>
<programlisting>
{
machine = { config, pkgs, ... }: {
deployment.targetEnv = "linode";
deployment.linode = {
## This is not a real API key, but it is in the correct format.
personalAPIKey = "2f99e7484232eh7dg8780ak41d371a945d4092150be5d36aee19d352df31a45f";
## Default region is London, but we are using Frankfurt in this example.
region = "eu-central-1a";
## Default type is a Linode 1024, but we are using a Linode 2048 in this example.
type = "g5-standard-1";
};
}
}
</programlisting>
</example>

<para>Installation works in a similar fashion to the Digital Ocean
install. We create a Debian 8 (Jessie) instance, then use <link
xlink:href="https://github.com/elitak/nixos-infect">nixos-infect</link>
(modified to fit Linode's settings) to replace it with Nixos.
</para>

</section>

<section><title>Deploying to Libvirtd (Qemu)</title>

<para>In order to use libvirtd backend, a couple of manual steps need to be
taken. Libvirtd backend is currently supported only on NixOS.
Expand Down
1 change: 1 addition & 0 deletions nix/eval-machine-info.nix
Expand Up @@ -287,6 +287,7 @@ rec {
digitalOcean = optionalAttrs (v.config.deployment.targetEnv == "digitalOcean") v.config.deployment.digitalOcean;
gce = optionalAttrs (v.config.deployment.targetEnv == "gce") v.config.deployment.gce;
hetzner = optionalAttrs (v.config.deployment.targetEnv == "hetzner") v.config.deployment.hetzner;
linode = optionalAttrs (v.config.deployment.targetEnv == "linode") v.config.deployment.linode;
container = optionalAttrs (v.config.deployment.targetEnv == "container") v.config.deployment.container;
route53 = v.config.deployment.route53;
virtualbox =
Expand Down
57 changes: 57 additions & 0 deletions nix/linode.nix
@@ -0,0 +1,57 @@
{ config, pkgs, lib, utils, ... }:

with lib;

let
cfg = config.deployment.linode;
in
{
###### interface
options = {
deployment.linode.personalAPIKey = mkOption {
default = "";
example = "2f99e7484232eh7dg8780ak41d371a945d4092150be5d36aee19d352df31a45f";
type = types.str;
description = ''
Your personal API key. Create this from https://cloud.linode.com/profile/integrations/tokens
Needs 'Delete' privilege for Linodes.
We check for this value in <envar>LINODE_PERSONAL_API_KEY</envar> before looking here.
'';
};

deployment.linode.region = mkOption {
default = "eu-west-1a";
example = "eu-west-1a";
type = types.str;
description = ''
The id of the region to deploy the VM into.
See https://api.linode.com/v4/regions for available regions (use the id field).
Alternatively, run `curl https://api.linode.com/v4/regions | jq ".regions[].id"`
'';
};

deployment.linode.type = mkOption {
default = "g5-nanode-1";
example = "g5-nanode-1";
type = types.str;
description = ''
The id of the type of VM to deploy. This determines the amount
of storage, memory, virtual CPUs, price, and network
bandwidth.
See https://api.linode.com/v4/linode/types for available types.
Alternatively, run `curl https://api.linode.com/v4/types | jq ".types[].id"`
'';
};
};

config = mkIf (config.deployment.targetEnv == "linode") {
nixpkgs.system = mkOverride 900 "x86_64-linux";
services.openssh.enable = true; # We need an SSH server in order to deploy our configuration.

## TODO: do we need to muck around with Grub?
};
}
1 change: 1 addition & 0 deletions nix/options.nix
Expand Up @@ -22,6 +22,7 @@ in
./keys.nix
./gce.nix
./hetzner.nix
./linode.nix
./container.nix
./libvirtd.nix
];
Expand Down

0 comments on commit 42c1076

Please sign in to comment.