vms almost working

This commit is contained in:
baritone 2025-03-04 16:51:18 +01:00
parent 110864d9d0
commit 209e5f2a8f
4 changed files with 85 additions and 23 deletions

View file

@ -1,3 +1,38 @@
{...}: { {
microvm.hyprvisor = "cloud-hyprvisor"; config,
lib,
...
}: let
attrSets = lib.lists.imap1 (i: v: {
name = v;
index = i;
}) (builtins.attrNames config.microvm.vms);
in {
config.microvm.hyprvisor = "cloud-hyprvisor";
systemd.network.networks = builtins.listToAttrs attrSet ({
name,
index,
}: {
name = "30-vm${name}";
value = {
matchConfig.Name = "vm${name}";
address = [
"10.0.0.0/32"
];
routes = [
{
Destination = "10.0.0.${toString index}/32";
}
];
networkConfig = {IPv4Forwarding = true;};
};
});
# NAT (make vms accessible in host)
networking.nat = {
enable = true;
internalIps = ["10.0.0.0/24"];
externalInterface = "enp2s0";
};
} }

View file

@ -1,8 +1,8 @@
{...}: { {...}: {
networking.useDHCP = false; networking.useDHCP = false;
networking.wakeOnLan.enable = true; # networking.wakeOnLan.enable = true;
networking.enp2s0.wakeOnLan.policy = "magic"; # networking.interfaces.enp2s0.wakeOnLan.policy = "magic";
networking.interfaces.enp2s0 = { networking.interfaces.enp2s0 = {
ipv4.addresses = [ ipv4.addresses = [

View file

@ -1,7 +1,8 @@
{hostname ? "server"}: {...}: { {hostname ? "server"}: {...}: {
networking.hostName = hostname; networking.hostName = hostname;
networking.hostId = "2ead098f"; networking.hostId = "2ead098f";
networking.networkmanager.enable = true; networking.networkmanager.enable = false;
networking.useNetworkd = true;
networking.firewall = { networking.firewall = {
enable = true; enable = true;
allowedTCPPorts = []; allowedTCPPorts = [];

View file

@ -1,16 +1,20 @@
{lib, ...}: let {lib, ...}: let
host = "127.0.0.1"; host = "127.0.0.1";
port = 8989; port = 8989;
vm-index = 1;
vm-mac = "00:00:00:00:00:01";
in { in {
config.microvm.autostart = ["sonarr"]; config.microvm.autostart = ["sonarr"];
config.system.activationScripts.makeSonarrDir = lib.stringAfter ["var"] '' config.system.activationScripts.makeSonarrDir = lib.stringAfter ["var"] ''
mkdir -p /var/lib/sonarr mkdir -p /var/lib/sonarr
chmod -R microvm /var/lib/sonarr
''; '';
config.microvm.vms."sonarr" = { config.microvm.vms."sonarr" = {
config = { config = {
system.stateVersion = "24.11"; system.stateVersion = "24.11";
# Storage share configuration
microvm.shares = [ microvm.shares = [
{ {
tag = "ro-store"; tag = "ro-store";
@ -21,33 +25,55 @@ in {
tag = "data-dir"; tag = "data-dir";
source = "/var/lib/sonarr"; source = "/var/lib/sonarr";
mountPoint = "/var/lib/sonarr"; mountPoint = "/var/lib/sonarr";
proto = "virtiofs";
} }
]; ];
# VM Networking
microvm.interfaces = [ microvm.interfaces = [
{ {
id = "vm${toString vm-index}";
type = "tap"; type = "tap";
mac = vm-mac;
# interface name on the host
id = "vm-sonarr";
# Ethernet address of the MicroVM's interface, not the host's
#
# Locally administered have one of 2/6/A/E in the second nibble.
mac = "02:00:00:00:00:01";
} }
]; ];
networking.useNetworkd = true;
services.sonarr = { systemd.network.networks."10-eth" = {
enable = true; matchConfig.MACAddress = vm-mac;
openFirewall = true; # Hide sonarr behind firewall address = [
"10.0.0.${toString vm-index}/32"
];
routes = [
# Host Route
{
Destination = "10.0.0.0/32";
GatewayOnLink = true;
}
# Default route
{
Destination = "0.0.0.0/0";
Gateway = "10.0.0.0";
GatewayOnLink = true;
}
];
networkConfig = {
DNS = [
"9.9.9.9"
"8.8.8.8"
"8.8.4.4"
];
};
}; };
services.nginx.virtualHosts."sonarr.spoodythe.one" = { # Service
addSSL = true; services.sonarr = {
enableACME = true; enable = true;
locations."/" = { openFirewall = true;
proxyPass = "http://${host}:${toString port}"; };
};
# Debug user
users.users."root" = {
password = "1234";
}; };
}; };
}; };