nixos-generators icon indicating copy to clipboard operation
nixos-generators copied to clipboard

AMI target

Open vaibhavsagar opened this issue 6 years ago • 7 comments

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.

vaibhavsagar avatar Feb 07 '19 22:02 vaibhavsagar

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!

Lassulus avatar Feb 09 '19 14:02 Lassulus

Why does the image have to be build offline?

Maybe using packer would work?

mrVanDalo avatar Apr 02 '19 09:04 mrVanDalo

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

Lassulus avatar Apr 02 '19 09:04 Lassulus

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

Lassulus avatar Apr 02 '19 09:04 Lassulus

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.

vaibhavsagar avatar Apr 02 '19 14:04 vaibhavsagar

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

mrVanDalo avatar Apr 25 '19 08:04 mrVanDalo

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.

zimbatm avatar Apr 25 '19 13:04 zimbatm