microvm host is stable (for now)

- per-system default.nix now inherits the source tree via `src` (this
allows modules to be optionally imported from `modules/opt/`)
- adds a default config for microvm hosts
  - enables systemd-networkd by default
  - allows passing in vms
  - binds vm nix-store to host nix-store
  - allows merging systemd jounals
- adds microvms to palatine-hill

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
ahuston-0 2024-06-22 10:58:39 -04:00
parent f9d31cba65
commit 45610cb886
No known key found for this signature in database
GPG Key ID: 1FACF4075E3212F7
6 changed files with 56 additions and 39 deletions

View File

@ -160,7 +160,12 @@ rec {
lib.nixosSystem {
inherit system;
specialArgs = {
inherit inputs server system;
inherit
inputs
server
system
src
;
};
modules =
[
@ -208,7 +213,7 @@ rec {
inherit inputs src configPath;
hostname = name;
}
// import configPath { inherit inputs; }
// import configPath { inherit inputs src; }
);
}
) (lib.rad-dev.lsdir path)

View File

@ -1,33 +0,0 @@
{
config,
lib,
inputs,
...
}:
let
cfg = config.rad-dev.microvm-host;
inherit (inputs.microvm.nixosModules) microvm;
in
{
# imports = [microvm.host];
options.rad-dev.microvm-host = {
enable = lib.mkEnableOption "microvm-host";
};
config = lib.mkIf cfg.enable {
networking.useNetworkd = true;
# microvm.shares = [
# {
# tag = "ro-store";
# source = "/nix/store";
# mountPoint = "/nix/.ro-store";
# }
# ];
# systemd.tmpfiles.rules = map (vmHost:
# let
# machineId = lib.addresses.machineId.${vmHost};
# in
# # creates a symlink of each MicroVM's journal under the host's /var/log/journal
# "L+ /var/log/journal/${machineId} - - - - /var/lib/microvms/${vmHost}/journal/${machineId}"
# ) (builtins.attrNames lib.addresses.machineId);
};
}

5
modules/opt/default.nix Normal file
View File

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

View File

@ -0,0 +1,41 @@
{
config,
lib,
inputs,
...
}:
let
cfg = config.rad-dev.microvm-host;
microvm = inputs.microvm.nixosModules;
in
{
imports = [ microvm.host ];
options.rad-dev.microvm-host = {
vms = lib.mkOption {
type = lib.types.attrset;
default = { };
description = "A list of VMs to construct on the host";
};
};
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 (
vmHost:
let
machineId = lib.addresses.machineId.${vmHost};
in
# creates a symlink of each MicroVM's journal under the host's /var/log/journal
"L+ /var/log/journal/${machineId} - - - - /var/lib/microvms/${vmHost}/journal/${machineId}"
) (builtins.attrNames lib.addresses.machineId);
};
}

View File

@ -1,4 +1,4 @@
{ inputs, ... }:
{ inputs, src, ... }:
{
users = [
"alice"
@ -6,6 +6,6 @@
];
modules = [
inputs.attic.nixosModules.atticd
inputs.microvm.nixosModules.host
(src + "/modules/opt/microvm-host.nix")
];
}

View File

@ -4,7 +4,6 @@
pkgs,
...
}:
{
rad-dev.microvm-host.enable = true;
# rad-dev.microvm-host.enable = true;
}