Preparing a NixOS host for declarative MicroVMs

microvm.nix adds the following configuration for servers to host MicroVMs reliably:

Prepare your host by including the microvm.nix host nixosModule:

# Your server's flake.nix
{
  inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  inputs.microvm.url = "github:astro/microvm.nix";
  inputs.microvm.inputs.nixpkgs.follows = "nixpkgs";

  outputs = { self, nixpkgs, microvm }: {
    # Example nixosConfigurations entry
    nixosConfigurations.server1 = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        # Include the microvm host module
        microvm.nixosModules.host
        # Add more modules here
        {
          networking.hostName = "server1";

          # try to automatically start these MicroVMs on bootup
          microvm.autostart = [
            "my-microvm"
            "your-microvm"
            "their-microvm"
          ];
        }
      ];
    };
  };
}

Preparing a non-Flakes host

If you really cannot migrate to Flakes easily, just import the host module directly in your NixOS configuration:

imports = [ (builtins.fetchGit {
  url = "https://github.com/astro/microvm.nix";
} + "/nixos-modules/host") ];