feat: allow microvms to override configPath

This commit is contained in:
oddlama 2023-05-23 01:09:37 +02:00
parent f65b217a92
commit cc2397669d
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
7 changed files with 74 additions and 53 deletions

View file

@ -89,25 +89,9 @@
};
microvm.vms.${vmName} = let
# Loads configuration from a subfolder of this nodes configuration, if it exists.
configPath =
if nodePath == null
then null
else nodePath + "/microvms/${vmName}";
node =
(import ../nix/generate-node.nix inputs)
vmCfg.nodeName
{
inherit (vmCfg) system;
# Load configPath, if it exists.
${
if configPath != null && builtins.pathExists configPath
then "config"
else null
} =
configPath;
};
node = import ../nix/generate-node.nix inputs vmCfg.nodeName {
inherit (vmCfg) system configPath;
};
mac = net.mac.addPrivate vmCfg.id cfg.networking.baseMac;
in {
# Allow children microvms to know which node is their parent
@ -265,6 +249,12 @@ in {
];
options.extra.microvms = {
commonImports = mkOption {
type = types.listOf types.unspecified;
default = [];
description = mdDoc "Modules to import on all microvms.";
};
networking = {
baseMac = mkOption {
type = net.types.mac;
@ -353,6 +343,26 @@ in {
'';
};
configPath = mkOption {
type = types.nullOr types.path;
default =
if nodePath != null && builtins.pathExists (nodePath + "/microvms/${name}")
then nodePath + "/microvms/${name}"
else null;
description = mdDoc ''
The main configuration directory for this microvm. If not-null, the given
directory will automatically be imported as system configuration. It will
become the nodePath for the microvm meaning that some machine-specific files
may be referenced there automatically (for example host.pub).
This can also be set to a file, which will then simply be used as the main
import for configuration, without setting a nodePath.
By default this will be set to the current node's <nodePath>/microvms/<vmname>
if the current nodePath is non-null and the directory exists.
'';
};
id = mkOption {
type =
types.addCheck types.int (x: x > 1)