Skip to content

Commit

Permalink
compose: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Oct 21, 2024
1 parent 7412527 commit 9f5df10
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
15 changes: 10 additions & 5 deletions examples/compose.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 0 additions & 2 deletions lib/compose/modules/base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ in
# system.build
(nixosModulesPath + "/system/build.nix")
];

nixpkgs = nixpkgs;
}
17 changes: 13 additions & 4 deletions lib/compose/modules/process-compose.nix
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
24 changes: 3 additions & 21 deletions lib/compose/modules/vms.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
};
}

0 comments on commit 9f5df10

Please sign in to comment.