add basic guest config (warning CI is definitely failing lol)
Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
parent
45610cb886
commit
3a61c7522d
@ -3,7 +3,7 @@
|
|||||||
# create rad-dev namespace for lib
|
# create rad-dev namespace for lib
|
||||||
rad-dev = rec {
|
rad-dev = rec {
|
||||||
systems = import ./systems.nix { inherit lib; };
|
systems = import ./systems.nix { inherit lib; };
|
||||||
|
microvm = import ./microvms.nix { inherit lib; };
|
||||||
# any(), but checks if any value in the list is true
|
# any(), but checks if any value in the list is true
|
||||||
#
|
#
|
||||||
# args:
|
# args:
|
||||||
|
63
lib/microvms.nix
Normal file
63
lib/microvms.nix
Normal 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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
1
modules/opt/k3s-agent.nix
Normal file
1
modules/opt/k3s-agent.nix
Normal file
@ -0,0 +1 @@
|
|||||||
|
{ ... }: { }
|
1
modules/opt/k3s-server.nix
Normal file
1
modules/opt/k3s-server.nix
Normal file
@ -0,0 +1 @@
|
|||||||
|
{ ... }: { }
|
@ -12,7 +12,7 @@ in
|
|||||||
imports = [ microvm.host ];
|
imports = [ microvm.host ];
|
||||||
options.rad-dev.microvm-host = {
|
options.rad-dev.microvm-host = {
|
||||||
vms = lib.mkOption {
|
vms = lib.mkOption {
|
||||||
type = lib.types.attrset;
|
type = lib.types.attrs;
|
||||||
default = { };
|
default = { };
|
||||||
description = "A list of VMs to construct on the host";
|
description = "A list of VMs to construct on the host";
|
||||||
};
|
};
|
||||||
@ -20,13 +20,6 @@ in
|
|||||||
config = {
|
config = {
|
||||||
networking.useNetworkd = true;
|
networking.useNetworkd = true;
|
||||||
microvm.vms = cfg.vms;
|
microvm.vms = cfg.vms;
|
||||||
microvm.shares = [
|
|
||||||
{
|
|
||||||
tag = "ro-store";
|
|
||||||
source = "/nix/store";
|
|
||||||
mountPoint = "/nix/.ro-store";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
# TODO: deprecate this once we have syslog forwarders
|
# TODO: deprecate this once we have syslog forwarders
|
||||||
systemd.tmpfiles.rules = map (
|
systemd.tmpfiles.rules = map (
|
||||||
|
@ -2,8 +2,26 @@
|
|||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
pkgs,
|
pkgs,
|
||||||
|
src,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
let
|
||||||
|
inherit (lib.rad-dev.microvm) genFromList;
|
||||||
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
# rad-dev.microvm-host.enable = true;
|
# 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";
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user