9 Commits

Author SHA1 Message Date
6f0bf4aacb [gitea] init
All checks were successful
Evaluate Hydra Jobs / eval-hydra-jobs (push) Successful in 4m10s
Evaluate Hydra Jobs / eval-hydra-jobs (pull_request) Successful in 2m49s
2024-11-19 19:41:51 +01:00
6456814319 [doc] add basic microvm documentation
All checks were successful
Evaluate Hydra Jobs / eval-hydra-jobs (push) Successful in 3m39s
Evaluate Hydra Jobs / eval-hydra-jobs (pull_request) Successful in 3m38s
2024-11-19 15:43:23 +01:00
21310dcf3c [docs] fix docs app exec format error 2024-11-19 15:31:27 +01:00
63c36f6add [microvm] put vm creation into function
All checks were successful
Evaluate Hydra Jobs / eval-hydra-jobs (push) Successful in 3m14s
Evaluate Hydra Jobs / eval-hydra-jobs (pull_request) Successful in 3m44s
2024-11-19 13:31:09 +01:00
be194e4293 [microvm] rm duplicate option
Some checks failed
Evaluate Hydra Jobs / eval-hydra-jobs (push) Successful in 2m39s
Evaluate Hydra Jobs / eval-hydra-jobs (pull_request) Failing after 13m12s
2024-11-19 13:03:47 +01:00
edb9dcb28b [microvm] split module files
All checks were successful
Evaluate Hydra Jobs / eval-hydra-jobs (push) Successful in 4m0s
Evaluate Hydra Jobs / eval-hydra-jobs (pull_request) Successful in 4m10s
2024-11-19 12:59:11 +01:00
05ec7004ad [microvm] setup network, allow adding bridge interface to host
All checks were successful
Evaluate Hydra Jobs / eval-hydra-jobs (push) Successful in 3m19s
Evaluate Hydra Jobs / eval-hydra-jobs (pull_request) Successful in 3m20s
2024-11-18 22:55:03 +01:00
d1afbe9f14 [durruti] make durruti microvm
All checks were successful
Evaluate Hydra Jobs / eval-hydra-jobs (push) Successful in 3m18s
Evaluate Hydra Jobs / eval-hydra-jobs (pull_request) Successful in 2m56s
Networking still needs to be done but the vm boots using ```nix run .\#nixosConfigurations.durruti.config.microvm.declaredRunner```
2024-11-14 14:37:02 +01:00
807d2007fa [nixpkgs] add microvm.nix 2024-11-14 14:36:32 +01:00
10 changed files with 247 additions and 7 deletions

View File

@@ -13,4 +13,5 @@
- [TODO](./todo.md)
- [How-to]()
- [Updates](./anleitung/updates.md)
- [Rollbacks](./anleitung/rollback.md)
- [Rollbacks](./anleitung/rollback.md)
- [MicroVM](./anleitung/microvm.md)

View 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
};
```

74
flake.lock generated
View File

@@ -21,6 +21,24 @@
"url": "https://git.dynamicdiscord.de/kalipso/ep3-bs.nix"
}
},
"flake-utils": {
"inputs": {
"systems": "systems_3"
},
"locked": {
"lastModified": 1726560853,
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
@@ -61,6 +79,28 @@
"type": "github"
}
},
"microvm": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
],
"spectrum": "spectrum"
},
"locked": {
"lastModified": 1731240174,
"narHash": "sha256-HYu+bPoV3UILhwc4Ar5iQ7aF+DuQWHXl4mljN6Bwq6A=",
"owner": "astro",
"repo": "microvm.nix",
"rev": "dd89404e1885b8d7033106f3898eaef8db660cb2",
"type": "github"
},
"original": {
"owner": "astro",
"repo": "microvm.nix",
"type": "github"
}
},
"nixlib": {
"locked": {
"lastModified": 1729386149,
@@ -182,6 +222,7 @@
"ep3-bs": "ep3-bs",
"home-manager": "home-manager",
"mfsync": "mfsync",
"microvm": "microvm",
"nixos-generators": "nixos-generators",
"nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs_2",
@@ -212,6 +253,22 @@
"type": "github"
}
},
"spectrum": {
"flake": false,
"locked": {
"lastModified": 1729945407,
"narHash": "sha256-iGNMamNOAnVTETnIVqDWd6fl74J8fLEi1ejdZiNjEtY=",
"ref": "refs/heads/main",
"rev": "f1d94ee7029af18637dbd5fdf4749621533693fa",
"revCount": 764,
"type": "git",
"url": "https://spectrum-os.org/git/spectrum"
},
"original": {
"type": "git",
"url": "https://spectrum-os.org/git/spectrum"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
@@ -257,6 +314,21 @@
"type": "github"
}
},
"systems_4": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"tasklist": {
"inputs": {
"nixpkgs": [
@@ -315,7 +387,7 @@
},
"utils_3": {
"inputs": {
"systems": "systems_3"
"systems": "systems_4"
},
"locked": {
"lastModified": 1726560853,

View File

@@ -8,6 +8,8 @@
sops-nix.url = "github:Mic92/sops-nix";
sops-nix.inputs.nixpkgs.follows = "nixpkgs";
mfsync.url = "github:k4lipso/mfsync";
microvm.url = "github:astro/microvm.nix";
microvm.inputs.nixpkgs.follows = "nixpkgs";
utils = {
url = "github:numtide/flake-utils";

View File

@@ -40,6 +40,34 @@ let
}
];
defaultModules = baseModules;
makeMicroVM = hostName: ipv4Addr: modules: [
inputs.microvm.nixosModules.microvm
{
microvm = {
hypervisor = "qemu";
interfaces = [
{
type = "tap";
id = "vm-${hostName}";
mac = "02:00:00:00:00:01";
}
];
};
systemd.network.enable = true;
systemd.network.networks."20-lan" = {
matchConfig.Type = "ether";
networkConfig = {
Address = [ "${ipv4Addr}/24" ];
Gateway = "10.0.0.1";
DNS = ["1.1.1.1"];
DHCP = "no";
};
};
}
] ++ defaultModules ++ modules;
in
{
louise = nixosSystem {
@@ -53,7 +81,7 @@ in
durruti = nixosSystem {
system = "x86_64-linux";
specialArgs.inputs = inputs;
modules = defaultModules ++ [
modules = makeMicroVM "durruti" "10.0.0.5" [
./durruti/configuration.nix
];
};
@@ -66,4 +94,12 @@ in
./lucia/hardware_configuration.nix
];
};
gitea = nixosSystem {
system = "x86_64-linux";
specialArgs.inputs = inputs;
modules = makeMicroVM "gitea" "10.0.0.6" [
./gitea/configuration.nix
];
};
}

View File

@@ -5,7 +5,6 @@ with lib;
{
sops.defaultSopsFile = ./secrets.yaml;
boot.isContainer = true;
networking = {
hostName = mkDefault "durruti";
useDHCP = false;

View File

@@ -44,6 +44,5 @@ in
enableACME= true;
locations."/".proxyPass = "http://${cfg.host_ip}:80";
};
};
}

View File

@@ -0,0 +1,37 @@
{ config, lib, pkgs, inputs, ... }:
with lib;
{
#sops.defaultSopsFile = ./secrets.yaml;
networking = {
hostName = mkDefault "gitea";
useDHCP = false;
nameservers = [ "1.1.1.1" ];
};
imports = [
../modules/malobeo_user.nix
../modules/sshd.nix
../modules/minimal_tools.nix
../modules/autoupdate.nix
];
services.gitea = {
enable = true;
appName = "malobeo git instance";
settings.server = {
DOMAIN = "git.malobeo.org";
HTTP_PORT = 3001;
SSH_PORT = 22;
ROOT_URL = "https://git.malobeo.org/";
};
};
networking.firewall.allowedTCPPorts = [ 3001 ];
system.stateVersion = "22.11"; # Did you read the comment?
}

View File

@@ -0,0 +1,52 @@
{ config, lib, options, pkgs, ... }:
with lib;
let
cfg = config.services.malobeo.microvm;
in
{
options = {
services.malobeo.microvm = {
enableHostBridge = mkOption {
default = false;
type = types.bool;
description = lib.mdDoc "Setup bridge device for microvms.";
};
};
};
config = mkIf cfg.enableHostBridge
{
systemd.network = {
enable = true;
# create a bride device that all the microvms will be connected to
netdevs."10-microvm".netdevConfig = {
Kind = "bridge";
Name = "microvm";
};
networks."10-microvm" = {
matchConfig.Name = "microvm";
networkConfig = {
DHCPServer = true;
IPv6SendRA = true;
};
addresses = [ {
Address = "10.0.0.1/24";
} {
Address = "fd12:3456:789a::1/64";
} ];
ipv6Prefixes = [ {
Prefix = "fd12:3456:789a::/64";
} ];
};
# connect the vms to the bridge
networks."11-microvm" = {
matchConfig.Name = "vm-*";
networkConfig.Bridge = "microvm";
};
};
};
}

View File

@@ -41,7 +41,7 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
apps = {
docs = {
type = "app";
program = builtins.toString (pkgs.writeScript "docs" ''
program = builtins.toString (pkgs.writeShellScript "docs" ''
${pkgs.mdbook}/bin/mdbook serve --open ./doc
'');
};
@@ -52,7 +52,10 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
inherit inputs;
});
nixosModules.malobeo = import ./machines/durruti/host_config.nix;
nixosModules.malobeo.imports = [
./machines/durruti/host_config.nix
./machines/modules/malobeo/microvm_host.nix
];
hydraJobs = nixpkgs.lib.mapAttrs (_: nixpkgs.lib.hydraJob) (
let