Hello community,
I use a flake-based project to manage my NixOS systems. It is based on mitchellh’s one here. Anyway, I would like to add an EC2 image builder to the project. To this end I have used nixos-generators and added the the following to my flake inputs
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
and to the outputs
packages.x86_64-linux = {
amazon = nixos-generators.nixosGenerate {
system = "x86_64-linux";
modules = [
# you can include your own nixos configuration here, i.e.
# ./configuration.nix
({...}: { amazonImage.sizeMB = 60 * 1024; })
./users/jade/nixos.nix
home-manager.nixosModules.home-manager {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.jade = import ./users/jade/home-manager.nix;
}
];
format = "amazon";
# optional arguments:
# explicit nixpkgs and lib:
# pkgs = nixpkgs.legacyPackages.x86_64-linux;
# lib = nixpkgs.legacyPackages.x86_64-linux.lib;
# additional arguments to pass to modules:
# specialArgs = { myExtraArg = "foobar"; };
# specialArgs = {
# diskSize = 100 * 1024;
# };
# you can also define your own custom formats
# customFormats = { "myFormat" = <myFormatModule>; ... };
# format = "myFormat";
};
};
The image is built by issuing
nix build .#amazon
I then use a minor variation of this script create-amis.sh to make accessible on AWS (I am following Install_NixOS_on_Amazon_EC2
Unfortunately when I try to connect to an instance using the resulting ami I encounter this message
An error occurred (TargetNotConnected) when calling the StartSession operation: ...
I have no trouble connecting to the latest official nixos image ami-0826e43ab152a4208
(nixos/24.05.1791.4e6d12181cf6-x86_64-linux).
My hunch is that I might benefit from applying the content found in nixos/modules/virtualisation/amazon-image.nix such as
services.amazon-ssm-agent.enable = true;
and
imports = [
../profiles/headless.nix
./ec2-data.nix
./amazon-init.nix
];
… I kind of expected this to be done by nixosGenerate { format = "amazon"; }
above. Perhaps my home-manager module imports have messed things up?
Any guidance, suggestions, or thoughts appreciated!