Fstab error while creating a custom Amazon EC2 AMI

Hello,

I’m currently trying to build a customized version of an EC2 AMI for NixOS, and I’m facing an issue while importing the AMI.

Here is how I build the AMI:

{
  myImage = ((import <nixpkgs/nixos/lib/eval-config.nix> {
    modules = [
      <nixpkgs/nixos/maintainers/scripts/ec2/amazon-image.nix>
      ./initial.nix
    ];
  }).config.system.build.amazonImage);
}

initial.nix sets some environement and a shell for a default used (it’s just a try).

I then build the image the following way:

nix-build ./image.nix \
  -A myImage \
  -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/66d8a2bda511e1fc46725322f94261c8a4083757.tar.gz

The image seems to build correctly, but then, when I do an aws ec2 import-image I get the error message around 26%:

"StatusMessage": "ClientError: Unable to find an etcdirectory with fstab.

I see that other people here had the same issue, but I couldn’t find a working fix.

How can I build and import the customized AMI on Amazon EC2 ?

Thank you !

And, it was a bit tricky. We must import a snapshot, not an image !

More details available on this issue : https://github.com/NixOS/nixpkgs/issues/71770#issuecomment-613932524