Files
infrastructure/machines/modules/malobeo/microvm_host.nix
kalipso 29afc27594
Some checks failed
Evaluate Hydra Jobs / eval-hydra-jobs (push) Successful in 2m48s
Evaluate Hydra Jobs / eval-hydra-jobs (pull_request) Failing after 13m49s
[microvm] fix comparision
2024-11-21 13:02:54 +01:00

80 lines
2.0 KiB
Nix

{ 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.";
};
deployHosts = mkOption {
default = [];
type = types.listOf string;
description = ''
List hostnames of MicroVMs that should be automatically initializes and autostart
'';
};
};
};
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";
};
};
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);
};
}