From a82bfec343c0521147b67fb92766574fa0ef0c4c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 25 Oct 2011 01:59:39 +0000 Subject: [PATCH] =?UTF-8?q?*=20Add=20an=20option=20=E2=80=98deployment.ec2?= =?UTF-8?q?.zone=E2=80=99.=20=20For=20EC2=20deployments,=20this=20=20=20au?= =?UTF-8?q?tomatically=20sets=20=E2=80=98deployment.ec2.controller?= =?UTF-8?q?=E2=80=99=20and=20=20=20=E2=80=98deployment.ec2.ami=E2=80=99=20?= =?UTF-8?q?to=20sensible=20values.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit svn path=/nixos/trunk/; revision=30005 --- modules/misc/deployment.nix | 44 +++++++++++++++++++++++++++++++++++-- modules/misc/nixpkgs.nix | 2 +- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/modules/misc/deployment.nix b/modules/misc/deployment.nix index fa78de49d39f..373a1a0fbd80 100644 --- a/modules/misc/deployment.nix +++ b/modules/misc/deployment.nix @@ -2,6 +2,8 @@ with pkgs.lib; +let cfg = config.deployment; in + { options = { @@ -49,15 +51,31 @@ with pkgs.lib; }; deployment.ec2.controller = mkOption { - example = https://ec2.eu-west-1.amazonaws.com:443/; + example = https://ec2.eu-west-1.amazonaws.com/; + type = types.uniq types.string; description = '' URI of an Amazon EC2-compatible cloud controller web service, - used to create and manage virtual machines. + used to create and manage virtual machines. If you're using + EC2, it's more convenient to set + . + ''; + }; + + deployment.ec2.zone = mkOption { + default = ""; + example = "us-east-1"; + type = types.uniq types.string; + description = '' + Amazon EC2 zone in which the instance is to be deployed. This + option only applies when using EC2. It implicitly sets + and + . ''; }; deployment.ec2.ami = mkOption { example = "ami-ecb49e98"; + type = types.uniq types.string; description = '' EC2 identifier of the AMI disk image used in the virtual machine. This must be a NixOS image providing SSH access. @@ -67,6 +85,7 @@ with pkgs.lib; deployment.ec2.instanceType = mkOption { default = "m1.small"; example = "m1.large"; + type = types.uniq types.string; description = '' EC2 instance type. See for a @@ -128,4 +147,25 @@ with pkgs.lib; }; }; + + + config = { + + deployment.ec2 = mkIf (cfg.ec2.zone != "") { + + controller = mkDefault "https://ec2.${cfg.ec2.zone}.amazonaws.com/"; + + ami = mkDefault ( + if cfg.ec2.zone == "eu-west-1" && config.nixpkgs.system == "i686-linux" then "ami-c9f2d8bd" else + if cfg.ec2.zone == "eu-west-1" && config.nixpkgs.system == "x86_64-linux" then "ami-ecb49e98" else + if cfg.ec2.zone == "us-east-1" && config.nixpkgs.system == "x86_64-linux" then "ami-d93bf4b0" else + # !!! Doesn't work, not lazy enough. + # throw "I don't know an AMI for zone ‘${cfg.ec2.zone}’ and platform type ‘${config.nixpkgs.system}’" + ""); + + + }; + + }; + } diff --git a/modules/misc/nixpkgs.nix b/modules/misc/nixpkgs.nix index 2530b5af3e54..3154c3dd1e7d 100644 --- a/modules/misc/nixpkgs.nix +++ b/modules/misc/nixpkgs.nix @@ -59,7 +59,7 @@ in }; nixpkgs.system = mkOption { - default = ""; + default = pkgs.stdenv.system; description = '' Specifies the Nix platform type for which NixOS should be built. If unset, it defaults to the platform type of your host system