EC2 Nixos flakes

I’m trying to import the nixpkgs/nixos/modules/virtualisation/amazon-image.nix NixOS module into an EC2 NixOS flake. Is the amazon-image.nix functionality exposed in flakes anywhere? If not, what’s best way of doing this?

Well you can import any module using something like:

imports = [ "${nixpkgs.path}/nixos/modules/virtualisation/amazon-image.nix" ];

(From my memory, can’t test as I’m on my phone, if it fails maybe try without the .path)

1 Like

This worked:

imports = [ "${nixpkgs}/nixos/modules/virtualisation/amazon-image.nix" ];

Thank you @tobiasBora

This definitely works. Also keep in mind that there is a defult module option modulesPath passed to every nixos module containing the path to the module directory of the checkout of nixpkgs used to evaluate the NixOS config. so you could have done:

{modulesPath, ...}: {
  imports = [ "${modulesPath}/virtualisation/amazon-image.nix"];
}

Slight more compact, but either should work

2 Likes