add basic guest config (warning CI is definitely failing lol)

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
ahuston-0 2024-05-25 15:19:01 -04:00
parent 45610cb886
commit 3a61c7522d
No known key found for this signature in database
GPG Key ID: 1FACF4075E3212F7
6 changed files with 85 additions and 9 deletions

View File

@ -3,7 +3,7 @@
# create rad-dev namespace for lib
rad-dev = rec {
systems = import ./systems.nix { inherit lib; };
microvm = import ./microvms.nix { inherit lib; };
# any(), but checks if any value in the list is true
#
# args:

63
lib/microvms.nix Normal file
View File

@ -0,0 +1,63 @@
{ lib, ... }:
rec {
genK3SFromList =
server-config: agent-config:
{
host,
ipv4,
server ? false,
}@args:
lib.mapAttrs (
args:
lib.rad-dev.microvms.genMicroVM args.host args.ipv4 "x86_64-linux" (
if server then import server-config else import agent-config
)
) args;
genMicroVM =
hostName: ipv4: system: vm-config:
# microvm refers to microvm.nixosModules
{
config,
pkgs,
lib,
...
}:
{
${hostName} = {
# The package set to use for the microvm. This also determines the microvm's architecture.
# Defaults to the host system's package set if not given.
pkgs = import pkgs { inherit system; };
# (Optional) A set of special arguments to be passed to the MicroVM's NixOS modules.
#specialArgs = {};
# The configuration for the MicroVM.
# Multiple definitions will be merged as expected.
config = {
# It is highly recommended to share the host's nix-store
# with the VMs to prevent building huge images.
microvm.shares = [
{
source = "/nix/store";
mountPoint = "/nix/.ro-store";
tag = "ro-store";
proto = "virtiofs";
}
];
networking = {
inherit hostName;
interfaces.ether.ipv4.addreses = {
address = ipv4;
prefixLength = 24;
};
};
# Any other configuration for your MicroVM
# [...]
} // vm-config;
};
};
}

View File

@ -0,0 +1 @@
{ ... }: { }

View File

@ -0,0 +1 @@
{ ... }: { }

View File

@ -12,7 +12,7 @@ in
imports = [ microvm.host ];
options.rad-dev.microvm-host = {
vms = lib.mkOption {
type = lib.types.attrset;
type = lib.types.attrs;
default = { };
description = "A list of VMs to construct on the host";
};
@ -20,13 +20,6 @@ in
config = {
networking.useNetworkd = true;
microvm.vms = cfg.vms;
microvm.shares = [
{
tag = "ro-store";
source = "/nix/store";
mountPoint = "/nix/.ro-store";
}
];
# TODO: deprecate this once we have syslog forwarders
systemd.tmpfiles.rules = map (

View File

@ -2,8 +2,26 @@
config,
lib,
pkgs,
src,
...
}:
let
inherit (lib.rad-dev.microvm) genFromList;
in
{
# rad-dev.microvm-host.enable = true;
rad-dev.microvm-host.vms = (
genFromList (src + "/modules/opt/k3s-server.nix") (src + "/modules/opt/k3s-agent.nix") [
{
host = "ph-server-1";
ipv4 = "192.168.69.10";
server = true;
}
{
host = "ph-agent-1";
ipv4 = "192.168.69.30";
}
]
);
}