Building QEMU/KVM VMs

For quick experiments, I use nixos-shell

Here’s my vm.nix for reference:

{ pkgs, ... }: {
  boot.kernelPackages = pkgs.linuxPackages_latest;
  services.openssh.enable = true;
  virtualisation = {
    cores = 8;
    memorySize = 8192;
  };
  environment.systemPackages = with pkgs;[
    git
    helix
    bat
    tmux
  ];
  nix.settings.experimental-features = [ "nix-command" "flakes" ];
}

From the directory that has this file, I run nix run nixpkgs#nixos-shell

1 Like

Thank you @Majiir for sharing that - nice and easy.

But how do you deal with Package x is not available on the requested hostPlatformhostPlatform.config = "x86_64-unknown-linux-gnu" ?

Or are you building those SD images on ARM?

Thank you

I build on x86_64-linux using boot.binfmt.emulatedSystems to emulate aarch64-linux. As long as packages are available in the cache, the emulation doesn’t slow things down. If I need to build something big myself, I switch to cross-compilation.

1 Like

Thank you @Majiir . I set boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; and I got some errors that some packages are only for “x86_64-linux” and “i686-linux” which is a good sign that it is working.

I remove those packages, run build again and I got

error: Package ‘uboot-rpi_3_defconfig-2023.01’ in /nix/store/fwpalmvh6cnphvvd6n362a5cq22ixniz-source/pkgs/misc/uboot/default.nix:124 is not available on the requested hostPlatform:
         hostPlatform.config = "x86_64-unknown-linux-gnu"
         package.meta.platforms = [
           "aarch64-linux"
         ]
         package.meta.badPlatforms = [ ]
       , refusing to evaluate.

Strange.

You can check that your config is OK by building it first on an actual ARM instance - for example AWS m6g.large will cost you less than $1 even if you keep it running for a whole day. And prebuild NixOS instances are available in AWS for ARM CPUs.

1 Like

Thank you. Tested on AWS and it is building. So… I’m not sure where is the error…

The error you posted looks like your system is still set to x86_64.

1 Like

Yes! Thank you! It is building now. And I can see qemu in the list of processes :wink:

1 Like