Search code examples
nixnixosnixpkgs

Building NixOS AMI image for Amazon from Nix on non-NixOS Linux


I'm trying to use nixos-generators to build an AMI in my Ubuntu machine which has nix package manager installed. I have this configuration:

$ cat configuration.nix
{ pkgs, ... }:

{
  imports = [ <nixpkgs/nixos/modules/virtualisation/amazon-image.nix> ];
  ec2.hvm = true;
  environment.systemPackages = with pkgs; [ git ];
}

And then I use this command to create an AMI:

$ nixos-generate -f amazon -c ./configuration.nix
these derivations will be built:
  /nix/store/zc68psb6kxz9sxqr82bqs7x6c3vamnbd-nixos-amazon-image-20.09pre-git-x86_64-linux.drv
error: a 'x86_64-linux' with features {kvm} is required to build '/nix/store/zc68psb6kxz9sxqr82bqs7x6c3vamnbd-nixos-amazon-image-20.09pre-git-x86_64-linux.drv', but I am a 'x86_64-linux' with features {benchmark, big-parallel, nixos-test}

You can see the above error which I get. I do know that my system is capable of running KVM virtual machines:

$ kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used

And based on reading the documentation, I populate the nix.conf with this:

$ cat ~/.config/nix/nix.conf
system-features = "kvm"

And to this, I get this strange error:

$ nixos-generate -f amazon -c ./configuration.nix
these derivations will be built:
  /nix/store/zc68psb6kxz9sxqr82bqs7x6c3vamnbd-nixos-amazon-image-20.09pre-git-x86_64-linux.drv
error: a 'x86_64-linux' with features {kvm} is required to build '/nix/store/zc68psb6kxz9sxqr82bqs7x6c3vamnbd-nixos-amazon-image-20.09pre-git-x86_64-linux.drv', but I am a 'x86_64-linux' with features {"kvm"}

Any idea on how to resolve this issue and build an AMI ?


Solution

  • @patogonicus from IRC found that the issue was double quotes in the nix.conf file:

    system-features = kvm
    

    And it worked fine with that configuration.