diff --git a/examples/compose.nix b/examples/compose.nix index b7cc58ae..b84644db 100644 --- a/examples/compose.nix +++ b/examples/compose.nix @@ -5,10 +5,15 @@ let in microvm.lib.compose.evalModules { - modules = [ { - microvm.vms.foo.config = { + modules = builtins.genList (n: { + microvm.vms."qemu${toString n}".config = { + microvm.hypervisor = "qemu"; }; - microvm.vms.bar.config = { - }; - } ]; + # microvm.vms."chv${toString n}".config = { + # microvm.hypervisor = "cloud-hypervisor"; + # }; + # microvm.vms."firecracker${toString n}".config = { + # microvm.hypervisor = "firecracker"; + # }; + }) 1; } diff --git a/lib/compose/modules/base.nix b/lib/compose/modules/base.nix index 27620175..89bb7e38 100644 --- a/lib/compose/modules/base.nix +++ b/lib/compose/modules/base.nix @@ -9,6 +9,4 @@ in # system.build (nixosModulesPath + "/system/build.nix") ]; - - nixpkgs = nixpkgs; } diff --git a/lib/compose/modules/process-compose.nix b/lib/compose/modules/process-compose.nix index 8873e62c..25e51a74 100644 --- a/lib/compose/modules/process-compose.nix +++ b/lib/compose/modules/process-compose.nix @@ -1,13 +1,22 @@ -{ config, pkgs, ... }: +{ config, lib, pkgs, ... }: { system.build = { process-compose-workflow = { version = "1.34"; + is_strict = true; - processes = builtins.mapAttrs (name: runner: { - command = "${runner}/bin/microvm-run"; - }) config.system.microvmRunners; + processes = lib.concatMapAttrs (name: config: + let + inherit (config.networking) hostName; + mainName = "${config.microvm.hypervisor}-${hostName}"; + in { + ${mainName} = { + command = "${config.microvm.declaredRunner}/bin/microvm-run"; + is_tty = true; + namespace = hostName; + }; + }) config.system.microvmConfigs; }; process-compose-file = pkgs.writers.writeYAML "process-compose.yaml" diff --git a/lib/compose/modules/vms.nix b/lib/compose/modules/vms.nix index a2fab37b..1282833c 100644 --- a/lib/compose/modules/vms.nix +++ b/lib/compose/modules/vms.nix @@ -5,18 +5,14 @@ let microvm = { shares = [ { proto = "9p"; - tag = "store"; + tag = "nix-store"; source = "/nix/store"; mountPoint = "/nix/store"; } ]; + socket = "control-${config.networking.hostName}.socket"; }; }; - # Configuration that depends on config at extendModules-time. - extensionConfig = { config, ... }: { - microvm.socket = "control-${config.networking.hostName}.socket"; - }; - # A base system that is fully evaluated once, and reused with extendModules per VM. baseSystem = lib.nixosSystem { # TODO: option @@ -39,28 +35,14 @@ in internal = true; }; - options.system.microvmRunners = with lib; mkOption { - type = with types; attrsOf package; - default = {}; - description = '' - Generated `microvm.declaredRunner` - ''; - internal = true; - }; - config.system = { microvmConfigs = builtins.mapAttrs (name: { config, ... }: (baseSystem.extendModules { modules = [ + { networking.hostName = name; } config - extensionConfig ]; }).config ) config.microvm.vms; - - microvmRunners = builtins.mapAttrs (name: config: - builtins.trace "runner: ${name}" - config.microvm.declaredRunner - ) config.system.microvmConfigs; }; }