2.7 KiB
Declaring a MicroVM
The hosts nixosSystems modules should be declared using the makeMicroVM helper function.
Use durruti as orientation:
modules = makeMicroVM "durruti" "10.0.0.5" [
./durruti/configuration.nix
];
"durruti" is the hostname.
"10.0.0.5" is the IP assigned to its tap interface.
Testing MicroVMs locally
MicroVMs can be built and run easily on your local host, but they are not persistent! For durruti for example this is done by:
nix run .\#durruti-vm
Testing persistent microvms
In order to test persistent microvms locally we need to create them using the microvm command.
This is necessary to be able to mount persistent /etc and /var volumes on those hosts.
Do the following:
# go into our repo and start the default dev shell (or us direnv)
nix develop .#
# create a microvm on your host (on the example of durruti)
sudo microvm -c durruti -f git+file:///home/username/path/to/infrastructure/repo
# start the vm
sudo systemctl start microvm@durruti.serivce
# this may fail, if so we most probably need to create /var /etc manually, then restart
sudo mkdir /var/lib/microvms/durruti/{var, etc}
# now you can for example get the rsa host key from /var/lib/microvms/durruti/etc/ssh/
# alternatively u can run the vm in interactive mode (maybe stop the microvm@durruti.service first)
microvm -r durruti
# after u made changes to the microvm update and restart the vm
microvm -uR durruti
# deleting the vm again:
sudo systemctl stop microvm@durruti.service
sudo systemctl stop microvm-virtiofsd@durruti.service
sudo rm -rf /var/lib/microvms/durruti
Host Setup
Network Bridge
To provide network access to the VMs a bridge interface needs to be created on your host. For that:
- Add the infrastructure flake as input to your hosts flake
- Add
inputs.malobeo.nixosModules.malobeoto your hosts imports - enable the host bridge:
services.malobeo.microvm.enableHostBridge = true;
If you want to provide Internet access to the VM it is necessary to create a nat. This could be done like this:
networking.nat = {
enable = true;
internalInterfaces = [ "microvm" ];
externalInterface = "eth0"; #change to your interface name
};
Auto Deploy VMs
By default no MicroVMs will be initialized on the host - this should be done using the microvm commandline tool.
But since we want to always deploy certain VMs it can be configured using the malobeo.microvm.deployHosts option.
VMs configured using this option will be initialized and autostarted at boot.
Updating still needs to be done imperative, or by enabling autoupdates.nix
The following example would init and autostart durruti and gitea:
malobeo.microvm.deployHosts = [ "durruti" "gitea" ];