Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions nixops_aws/nix/ec2.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Configuration specific to the EC2 backend.

{ config, pkgs, lib, utils, ... }:
{ config, pkgs, lib, options, utils, ... }:

with utils;
with lib;
with import ./lib.nix lib;

let
throwIf = lib.throwIf or (cond: msg: if cond then throw msg else x: x);

types =
if lib.types ? either then
Expand Down Expand Up @@ -165,7 +166,21 @@ let

nixosVersion = builtins.substring 0 5 (config.system.nixos.version or config.system.nixosVersion);

amis = import <nixpkgs/nixos/modules/virtualisation/ec2-amis.nix>;
amisLegacy = import (pkgs.path + "/nixos/modules/virtualisation/ec2-amis.nix");

amisPath = pkgs.path + "/nixos/modules/virtualisation/amazon-ec2-amis.nix";
amis = import amisPath;

lookupAMI = { nixosVersion, region, system, virtType }:
assert builtins.trace "Looking up AMI for ${nixosVersion} in ${region} for ${system} with ${virtType}..." true;
if builtins.pathExists amisPath
then
(((amis.${nixosVersion} or amis.latest)
.${region} or (throw "No AMIs for region ${region}"))
.${system} or (throw "No AMIs for instance type ${system} in region ${region}"))
.${virtType} or (throw "No AMI for virtualisation type ${virtType} on instance type ${system} in region ${region}")
else
(amisLegacy.${nixosVersion} or amisLegacy.latest).${region}.${virtType};

in

Expand Down Expand Up @@ -484,7 +499,7 @@ in

config = mkIf (config.deployment.targetEnv == "ec2") {

nixpkgs.hostPlatform =
nixpkgs.${if options?nixpkgs.hostPlatform then "hostPlatform" else "system"} =
let
checked =
throwIf (config.deployment.ec2.physicalProperties.platforms or [] == [])
Expand All @@ -507,7 +522,7 @@ in
< ranking.${b.cpu} or unrankedRank;

systemString =
lib.throwIf (plat.os or "linux" != "linux")
throwIf (plat.os or "linux" != "linux")
"Instance does not seem to be intended for running Linux. Please set nixpkgs.hostPlatform manually."
plat.cpu + "-linux";
in
Expand All @@ -516,20 +531,18 @@ in
deployment.ec2.ami = mkDefault (
let
# FIXME: select hvm-s3 AMIs if appropriate.
type =
virtType =
if isEc2Hvm then
if cfg.ebsBoot then "hvm-ebs" else "hvm-s3"
else
if cfg.ebsBoot then "pv-ebs" else "pv-s3";
amis' = amis."${nixosVersion}" or amis.latest;
in
with builtins;
if hasAttr cfg.region amis' then
let r = amis'."${cfg.region}";
in if hasAttr type r then r."${type}" else
throw "I don't know an AMI for virtualisation type ${type} with instance type ${cfg.instanceType}"
else
throw "I don't know an AMI for region ‘${cfg.region}’ and platform type ‘${config.nixpkgs.hostPlatform.system}’"
lookupAMI {
inherit virtType;
inherit nixosVersion;
inherit (cfg) region;
system = config.nixpkgs.hostPlatform.system or config.nixpkgs.system;
}
);

# Workaround: the evaluation of blockDeviceMapping requires fileSystems to be defined.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ python = "^3.7"
boto = "^2.49.0"
boto3 = "^1.13.7"
nixops = {git = "https://github.com/NixOS/nixops.git", rev = "master"}
typing-extensions = "^3.7.4"
typing-extensions = ">=3.7 <=5"
nixos-modules-contrib = {git = "https://github.com/nix-community/nixos-modules-contrib.git", rev = "master"}

[tool.poetry.dev-dependencies]
Expand Down