Compare commits
5 Commits
script
...
9b014c5ff0
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b014c5ff0 | |||
| 1c66b6db8c | |||
| 1cecd21763 | |||
| 6456814319 | |||
| 21310dcf3c |
@@ -14,3 +14,4 @@
|
|||||||
- [How-to]()
|
- [How-to]()
|
||||||
- [Updates](./anleitung/updates.md)
|
- [Updates](./anleitung/updates.md)
|
||||||
- [Rollbacks](./anleitung/rollback.md)
|
- [Rollbacks](./anleitung/rollback.md)
|
||||||
|
- [MicroVM](./anleitung/microvm.md)
|
||||||
|
|||||||
39
doc/src/anleitung/microvm.md
Normal file
39
doc/src/anleitung/microvm.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
### Declaring a MicroVM
|
||||||
|
|
||||||
|
The hosts nixosSystems modules should be declared using the ```makeMicroVM``` helper function.
|
||||||
|
Use durruti as orientation:
|
||||||
|
``` nix
|
||||||
|
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.
|
||||||
|
For durruti this is done by:
|
||||||
|
``` bash
|
||||||
|
sudo nix run .\#nixosConfigurations.durruti.config.microvm.declaredRunner
|
||||||
|
```
|
||||||
|
|
||||||
|
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
|
||||||
|
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.malobeo``` to 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:
|
||||||
|
``` nix
|
||||||
|
networking.nat = {
|
||||||
|
enable = true;
|
||||||
|
internalInterfaces = [ "microvm" ];
|
||||||
|
externalInterface = "eth0"; #change to your interface name
|
||||||
|
};
|
||||||
|
```
|
||||||
@@ -46,6 +46,11 @@ let
|
|||||||
{
|
{
|
||||||
microvm = {
|
microvm = {
|
||||||
hypervisor = "qemu";
|
hypervisor = "qemu";
|
||||||
|
shares = [ {
|
||||||
|
tag = "ro-store";
|
||||||
|
source = "/nix/store";
|
||||||
|
mountPoint = "/nix/.ro-store";
|
||||||
|
} ];
|
||||||
interfaces = [
|
interfaces = [
|
||||||
{
|
{
|
||||||
type = "tap";
|
type = "tap";
|
||||||
|
|||||||
@@ -13,6 +13,14 @@ in
|
|||||||
type = types.bool;
|
type = types.bool;
|
||||||
description = lib.mdDoc "Setup bridge device for microvms.";
|
description = lib.mdDoc "Setup bridge device for microvms.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
deployHosts = mkOption {
|
||||||
|
default = [];
|
||||||
|
type = types.listOf string;
|
||||||
|
description = ''
|
||||||
|
List hostnames of MicroVMs that should be automatically initializes and autostart
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -48,5 +56,24 @@ in
|
|||||||
networkConfig.Bridge = "microvm";
|
networkConfig.Bridge = "microvm";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
imports = mkIf (lib.length cfg.deployHosts != 0) [
|
||||||
|
inputs.microvm.nixosModules.host
|
||||||
|
];
|
||||||
|
|
||||||
|
microvm.autostart = cfg.deployHosts;
|
||||||
|
microvm.vms =
|
||||||
|
let
|
||||||
|
# Map the values to each hostname to then generate a Attrs using listToAttrs
|
||||||
|
mapperFunc = name: { inherit name; value = {
|
||||||
|
# Host build-time reference to where the MicroVM NixOS is defined
|
||||||
|
# under nixosConfigurations
|
||||||
|
flake = self;
|
||||||
|
# Specify from where to let `microvm -u` update later on
|
||||||
|
updateFlake = "git+https://git.dynamicdiscord.de/kalipso/infrastructure?ref=microvm";
|
||||||
|
}; };
|
||||||
|
in
|
||||||
|
mkIf (lib.length cfg.deployHosts != 0)
|
||||||
|
builtins.listToAttrs (map mapperFunc cfg.deployHosts);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
|
|||||||
apps = {
|
apps = {
|
||||||
docs = {
|
docs = {
|
||||||
type = "app";
|
type = "app";
|
||||||
program = builtins.toString (pkgs.writeScript "docs" ''
|
program = builtins.toString (pkgs.writeShellScript "docs" ''
|
||||||
${pkgs.mdbook}/bin/mdbook serve --open ./doc
|
${pkgs.mdbook}/bin/mdbook serve --open ./doc
|
||||||
'');
|
'');
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user