nix-community / nixos-generators

Collection of image builders [maintainer=@Lassulus]
MIT License
1.83k stars 145 forks source link

AMI target #20

Open vaibhavsagar opened 5 years ago

vaibhavsagar commented 5 years ago

It looks like there's already support for this at https://github.com/NixOS/nixpkgs/blob/master/nixos/maintainers/scripts/ec2/create-amis.sh, and it would be nice to expose this as a target.

Lassulus commented 5 years ago

it seems like this script uses ec2-bundle-image which needs a connection to amazon and an actual working account. So this seems not to be possible from inside a builder. I can expose the amazonImage though, which is currently a qcow2 image.

If you know a way to generate an ami image offline, I could implement it!

mrVanDalo commented 5 years ago

Why does the image have to be build offline?

Maybe using packer would work?

Lassulus commented 5 years ago

the nix-sandbox doesn't allow internet connections (also this wouldn't be very reproducible then).

Lassulus commented 5 years ago

packer needs, according to the documentation, aws_access_key and aws_secret_key. So it seems it would need to connect to some AWS servers to create the AMI

vaibhavsagar commented 5 years ago

Building the image offline is vastly preferable to using Packer, which does connect to an EC2 instance to create an AMI. This can be quite slow and requires an internet connection and AWS credentials.

mrVanDalo commented 5 years ago

https://github.com/localstack/localstack < maybe this helps, to build AMIs local.

zimbatm commented 5 years ago

A better route would be to generate an image that can be consumed by the import-snapshot API: https://docs.aws.amazon.com/vm-import/latest/userguide/vmimport-import-snapshot.html

  1. Tweak nixos-generators to output a EC2-optimised vmdk
  2. Upload the image to a S3 bucket
  3. Use the above import-snapshot API to create a EBS volume
  4. Test the VM

If the importer is dump and doesn't do anything fancy with the disk image it should work.