forked from malobeo/infrastructure
[microvm] put vms on local network
This commit is contained in:
@@ -1,5 +1,22 @@
|
|||||||
{ ... }:
|
{ ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
createMaloNet = hostId: mac: {
|
||||||
|
local = true;
|
||||||
|
address = "192.168.1.${hostId}";
|
||||||
|
gateway = "192.168.1.1";
|
||||||
|
nameservers = [ "192.168.1.17" "1.1.1.1" ]; #setting ns1 as nameserver
|
||||||
|
mac = mac;
|
||||||
|
};
|
||||||
|
|
||||||
|
createOffsiteNet = address: mac: {
|
||||||
|
local = false;
|
||||||
|
address = address;
|
||||||
|
gateway = "10.0.10.1";
|
||||||
|
nameservers = [ "1.1.1.1" ];
|
||||||
|
mac = mac;
|
||||||
|
};
|
||||||
|
in
|
||||||
{
|
{
|
||||||
#TODO: fix local 192.168.1.0/24 addresses they are just palceholders!
|
#TODO: fix local 192.168.1.0/24 addresses they are just palceholders!
|
||||||
malobeo = {
|
malobeo = {
|
||||||
@@ -19,7 +36,7 @@
|
|||||||
address = "192.168.1.12";
|
address = "192.168.1.12";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
fanny = {
|
fanny = {
|
||||||
type = "host";
|
type = "host";
|
||||||
network = {
|
network = {
|
||||||
@@ -27,12 +44,7 @@
|
|||||||
address = "192.168.1.13";
|
address = "192.168.1.13";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
ns1 = {
|
|
||||||
type = "host";
|
|
||||||
network.local = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
lucia = {
|
lucia = {
|
||||||
type = "rpi";
|
type = "rpi";
|
||||||
network = {
|
network = {
|
||||||
@@ -40,60 +52,45 @@
|
|||||||
address = "192.168.1.15";
|
address = "192.168.1.15";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
durruti = {
|
durruti = {
|
||||||
type = "microvm";
|
type = "microvm";
|
||||||
network = {
|
network = createMaloNet "5" "52:DA:0D:F9:EF:F9";
|
||||||
local = true;
|
|
||||||
address = "10.0.0.5";
|
|
||||||
mac = "52:DA:0D:F9:EF:F9";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
vpn = {
|
vpn = {
|
||||||
type = "microvm";
|
type = "microvm";
|
||||||
network.local = false;
|
network = createOffsiteNet "10.0.0.10" "52:DA:0D:F9:EF:E6";
|
||||||
};
|
};
|
||||||
|
|
||||||
infradocs = {
|
infradocs = {
|
||||||
type = "microvm";
|
type = "microvm";
|
||||||
network = {
|
network = createMaloNet "11" "52:DA:0D:F9:EF:E7";
|
||||||
local = true;
|
|
||||||
address = "10.0.0.11";
|
|
||||||
mac = "D0:E5:CA:F0:D7:E7";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
uptimekuma = {
|
uptimekuma = {
|
||||||
type = "microvm";
|
type = "microvm";
|
||||||
network.local = false;
|
network = createOffsiteNet "10.0.0.12" "52:DA:0D:F9:EF:E8";
|
||||||
};
|
};
|
||||||
|
|
||||||
nextcloud = {
|
nextcloud = {
|
||||||
type = "microvm";
|
type = "microvm";
|
||||||
network = {
|
network = createMaloNet "13" "52:DA:0D:F9:EF:E9";
|
||||||
local = true;
|
|
||||||
address = "10.0.0.13";
|
|
||||||
mac = "D0:E5:CA:F0:D7:E9";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
overwatch = {
|
overwatch = {
|
||||||
type = "microvm";
|
type = "microvm";
|
||||||
network = {
|
network = createMaloNet "14" "52:DA:0D:F9:EF:E0";
|
||||||
local = true;
|
|
||||||
address = "10.0.0.14";
|
|
||||||
mac = "D0:E5:CA:F0:D7:E0";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
zineshop = {
|
zineshop = {
|
||||||
type = "microvm";
|
type = "microvm";
|
||||||
network = {
|
network = createMaloNet "15" "52:DA:0D:F9:EF:F1";
|
||||||
local = true;
|
};
|
||||||
address = "10.0.0.15";
|
|
||||||
mac = "D0:E5:CA:F0:D7:F1";
|
ns1 = {
|
||||||
};
|
type = "microvm";
|
||||||
|
network = createMaloNet "17" "52:DA:0D:F9:EF:F3";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ rec {
|
|||||||
];
|
];
|
||||||
defaultModules = baseModules;
|
defaultModules = baseModules;
|
||||||
|
|
||||||
makeMicroVM = hostName: ipv4Addr: macAddr: modules: [
|
makeMicroVM = hostName: network: modules: [
|
||||||
{
|
{
|
||||||
microvm = {
|
microvm = {
|
||||||
hypervisor = "cloud-hypervisor";
|
hypervisor = "cloud-hypervisor";
|
||||||
@@ -83,7 +83,7 @@ rec {
|
|||||||
{
|
{
|
||||||
type = "tap";
|
type = "tap";
|
||||||
id = "vm-${hostName}";
|
id = "vm-${hostName}";
|
||||||
mac = "${macAddr}";
|
mac = "${network.mac}";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
@@ -93,9 +93,9 @@ rec {
|
|||||||
systemd.network.networks."20-lan" = {
|
systemd.network.networks."20-lan" = {
|
||||||
matchConfig.Type = "ether";
|
matchConfig.Type = "ether";
|
||||||
networkConfig = {
|
networkConfig = {
|
||||||
Address = [ "${ipv4Addr}/24" ];
|
Address = [ "${network.address}/24" ];
|
||||||
Gateway = "10.0.0.1";
|
Gateway = "${network.gateway}";
|
||||||
DNS = ["1.1.1.1"];
|
DNS = network.nameservers;
|
||||||
DHCP = "no";
|
DHCP = "no";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -210,8 +210,7 @@ rec {
|
|||||||
specialArgs.self = self;
|
specialArgs.self = self;
|
||||||
config = {
|
config = {
|
||||||
imports = (makeMicroVM "${name}"
|
imports = (makeMicroVM "${name}"
|
||||||
"${hosts.malobeo.hosts.${name}.network.address}"
|
hosts.malobeo.hosts.${name}.network [
|
||||||
"${hosts.malobeo.hosts.${name}.network.mac}" [
|
|
||||||
../${name}/configuration.nix
|
../${name}/configuration.nix
|
||||||
(vmMicroVMOverwrites name {
|
(vmMicroVMOverwrites name {
|
||||||
withNetworking = true;
|
withNetworking = true;
|
||||||
@@ -250,7 +249,7 @@ rec {
|
|||||||
modules = (if (settings.type != "microvm") then
|
modules = (if (settings.type != "microvm") then
|
||||||
defaultModules ++ [ ../${host}/configuration.nix ]
|
defaultModules ++ [ ../${host}/configuration.nix ]
|
||||||
else
|
else
|
||||||
makeMicroVM "${host}" "${settings.network.address}" "${settings.network.mac}" [
|
makeMicroVM "${host}" settings.network [
|
||||||
inputs.microvm.nixosModules.microvm
|
inputs.microvm.nixosModules.microvm
|
||||||
../${host}/configuration.nix
|
../${host}/configuration.nix
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -14,6 +14,26 @@ in
|
|||||||
description = lib.mdDoc "Setup bridge device for microvms.";
|
description = lib.mdDoc "Setup bridge device for microvms.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface = mkOption {
|
||||||
|
default = "eno1";
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
|
||||||
|
gateway = mkOption {
|
||||||
|
default = "10.0.0.1";
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
|
||||||
|
address = mkOption {
|
||||||
|
default = "10.0.0.1/24";
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
|
||||||
|
dns = mkOption {
|
||||||
|
default = [ "1.1.1.1" ];
|
||||||
|
type = types.listOf types.str;
|
||||||
|
};
|
||||||
|
|
||||||
enableHostBridgeUnstable = mkOption {
|
enableHostBridgeUnstable = mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
@@ -47,29 +67,29 @@ in
|
|||||||
|
|
||||||
systemd.network = mkIf (cfg.enableHostBridge || cfg.enableHostBridgeUnstable) {
|
systemd.network = mkIf (cfg.enableHostBridge || cfg.enableHostBridgeUnstable) {
|
||||||
enable = true;
|
enable = true;
|
||||||
# create a bride device that all the microvms will be connected to
|
networks."10-lan" = {
|
||||||
netdevs."10-microvm".netdevConfig = {
|
matchConfig.Name = [ "${cfg.interface}" "vm-*"];
|
||||||
Kind = "bridge";
|
|
||||||
Name = "microvm";
|
|
||||||
};
|
|
||||||
|
|
||||||
networks."10-microvm" = {
|
|
||||||
matchConfig.Name = "microvm";
|
|
||||||
networkConfig = {
|
networkConfig = {
|
||||||
DHCPServer = true;
|
Bridge = "malobeo0";
|
||||||
IPv6SendRA = true;
|
|
||||||
};
|
};
|
||||||
addresses = if cfg.enableHostBridgeUnstable then [
|
|
||||||
{ Address = "10.0.0.1/24"; }
|
|
||||||
] else [
|
|
||||||
{ Address = "10.0.0.1/24"; }
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# connect the vms to the bridge
|
netdevs."malobeo0" = {
|
||||||
networks."11-microvm" = {
|
netdevConfig = {
|
||||||
matchConfig.Name = "vm-*";
|
Name = "malobeo0";
|
||||||
networkConfig.Bridge = "microvm";
|
Kind = "bridge";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
networks."10-lan-bridge" = {
|
||||||
|
matchConfig.Name = "malobeo0";
|
||||||
|
networkConfig = {
|
||||||
|
Address = [ "${cfg.address}" ];
|
||||||
|
Gateway = "${cfg.gateway}";
|
||||||
|
DNS = cfg.dns;
|
||||||
|
IPv6AcceptRA = true;
|
||||||
|
};
|
||||||
|
linkConfig.RequiredForOnline = "routable";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user