Compare commits
2 Commits
72ab98e6b7
...
34c008c05b
| Author | SHA1 | Date | |
|---|---|---|---|
| 34c008c05b | |||
| 40f3ce8522 |
@@ -12,14 +12,44 @@ Use durruti as orientation:
|
||||
"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.
|
||||
For durruti this is done by:
|
||||
MicroVMs can be built and run easily on your local host, but they are not persistent!
|
||||
For durruti for example this is done by:
|
||||
``` bash
|
||||
sudo nix run .\#nixosConfigurations.durruti.config.microvm.declaredRunner
|
||||
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:
|
||||
|
||||
```bash
|
||||
# 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
|
||||
```
|
||||
|
||||
It seems to be necessary to run this as root so that the according tap interface can be created.
|
||||
To be able to ping the VM or give Internet Access to the VM your host needs to be setup as described below.
|
||||
|
||||
### Host Setup
|
||||
|
||||
|
||||
41
outputs.nix
41
outputs.nix
@@ -56,7 +56,46 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
|
||||
cp -r ./book/* $dest
|
||||
'';
|
||||
};
|
||||
};
|
||||
} //
|
||||
|
||||
builtins.foldl'
|
||||
(result: host:
|
||||
let
|
||||
inherit (self.nixosConfigurations.${host}) config;
|
||||
in
|
||||
result // {
|
||||
# boot any machine in a microvm
|
||||
"${host}-vm" = (self.nixosConfigurations.${host}.extendModules {
|
||||
modules = [{
|
||||
microvm = {
|
||||
mem = pkgs.lib.mkForce 4096;
|
||||
hypervisor = pkgs.lib.mkForce "qemu";
|
||||
socket = pkgs.lib.mkForce null;
|
||||
shares = pkgs.lib.mkForce [{
|
||||
tag = "ro-store";
|
||||
source = "/nix/store";
|
||||
mountPoint = "/nix/.ro-store";
|
||||
}];
|
||||
interfaces = pkgs.lib.mkForce [{
|
||||
type = "user";
|
||||
id = "eth0";
|
||||
mac = "02:23:de:ad:be:ef";
|
||||
}];
|
||||
};
|
||||
boot.isContainer = pkgs.lib.mkForce false;
|
||||
users.users.root.password = "";
|
||||
fileSystems."/".fsType = pkgs.lib.mkForce "tmpfs";
|
||||
services.getty.helpLine = ''
|
||||
Log in as "root" with an empty password.
|
||||
Use "reboot" to shut qemu down.
|
||||
'';
|
||||
}] ++ pkgs.lib.optionals (! config ? microvm) [
|
||||
microvm.nixosModules.microvm
|
||||
];
|
||||
}).config.microvm.declaredRunner;
|
||||
})
|
||||
{ }
|
||||
(builtins.attrNames self.nixosConfigurations);
|
||||
|
||||
apps = {
|
||||
docs = {
|
||||
|
||||
Reference in New Issue
Block a user