Skip to content

Commit d85657c

Browse files
sysvm: Create a registry of the available vms
Creates a registry of both the registered, available and enabled system vms. In the future we can add "features" to the system vms that could be queried to define the functionality that they support or make available to the system, similar to how the appvms currently make their features available to the guivm. Signed-off-by: Brian McGillion <[email protected]>
1 parent 7831c6f commit d85657c

File tree

8 files changed

+220
-109
lines changed

8 files changed

+220
-109
lines changed

lib/global-config.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,8 @@ rec {
636636
# AppVM configurations (needed by guivm for launcher generation)
637637
# Use enabledVms which has derived values including applications from vmDef
638638
appvms = config.ghaf.virtualization.microvm.appvm.enabledVms or { };
639+
# System VM configurations (for dynamic discovery of enabled system VMs)
640+
sysvms = config.ghaf.virtualization.microvm.sysvm.enabledVms or { };
639641
# GUIVM applications (needed by guivm for local launcher generation)
640642
guivm = {
641643
applications = config.ghaf.virtualization.microvm.guivm.applications or [ ];

modules/microvm/flake-module.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ _: {
1818
./sysvms/audiovm.nix
1919
./sysvms/idsvm/idsvm.nix
2020
./common/microvm-store-mode.nix
21+
./sysvm-registry.nix
2122
./vm-config.nix
2223
];
2324

modules/microvm/sysvm-registry.nix

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# SPDX-FileCopyrightText: 2022-2026 TII (SSRC) and the Ghaf contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# System VM Registry
5+
#
6+
# Defines the sysvm.vms attrsOf option where each system VM module
7+
# self-registers. This mirrors the appvm.vms pattern — the registry
8+
# names zero VMs; each VM module contributes its own entry.
9+
#
10+
# Use sysvm.enabledVms for the filtered view of active VMs.
11+
#
12+
{
13+
config,
14+
lib,
15+
...
16+
}:
17+
let
18+
cfg = config.ghaf.virtualization.microvm.sysvm;
19+
in
20+
{
21+
_file = ./sysvm-registry.nix;
22+
23+
options.ghaf.virtualization.microvm.sysvm = {
24+
vms = lib.mkOption {
25+
type = lib.types.attrsOf (
26+
lib.types.submodule {
27+
options = {
28+
enable = lib.mkEnableOption "this system VM";
29+
30+
vmName = lib.mkOption {
31+
type = lib.types.str;
32+
description = "VM name with hyphen (e.g., gui-vm, net-vm).";
33+
};
34+
35+
evaluatedConfig = lib.mkOption {
36+
type = lib.types.nullOr lib.types.unspecified;
37+
default = null;
38+
description = "Pre-evaluated NixOS configuration for this system VM.";
39+
};
40+
41+
extraNetworking = lib.mkOption {
42+
type = lib.types.networking;
43+
default = { };
44+
description = "Extra networking configuration for this system VM.";
45+
};
46+
};
47+
}
48+
);
49+
default = { };
50+
description = ''
51+
System VM registry. Each system VM module self-registers here.
52+
Keys are vmType names (guivm, netvm, etc.) matching vmConfig.sysvms keys.
53+
Use enabledVms for the filtered view of active VMs.
54+
'';
55+
};
56+
57+
enabledVms = lib.mkOption {
58+
type = lib.types.attrsOf lib.types.unspecified;
59+
readOnly = true;
60+
description = ''
61+
Read-only attrset of enabled system VMs.
62+
Filtered from sysvm.vms to only include VMs with enable = true.
63+
'';
64+
};
65+
};
66+
67+
config.ghaf.virtualization.microvm.sysvm.enabledVms = lib.filterAttrs (_: vm: vm.enable) cfg.vms;
68+
}

modules/microvm/sysvms/adminvm.nix

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,34 @@ in
4343
};
4444
};
4545

46-
config = lib.mkIf cfg.enable {
47-
assertions = [
48-
{
49-
assertion = cfg.evaluatedConfig != null;
50-
message = ''
51-
ghaf.virtualization.microvm.adminvm.evaluatedConfig must be set.
52-
Use adminvmBase.extendModules from a profile (laptop-x86, orin, etc.).
53-
Example:
54-
ghaf.virtualization.microvm.adminvm.evaluatedConfig =
55-
config.ghaf.profiles.laptop-x86.adminvmBase.extendModules { modules = [...]; };
56-
'';
57-
}
58-
];
46+
config = lib.mkMerge [
47+
{
48+
ghaf.virtualization.microvm.sysvm.vms.adminvm = {
49+
inherit vmName;
50+
inherit (cfg) enable evaluatedConfig extraNetworking;
51+
};
52+
}
53+
(lib.mkIf cfg.enable {
54+
assertions = [
55+
{
56+
assertion = cfg.evaluatedConfig != null;
57+
message = ''
58+
ghaf.virtualization.microvm.adminvm.evaluatedConfig must be set.
59+
Use adminvmBase.extendModules from a profile (laptop-x86, orin, etc.).
60+
Example:
61+
ghaf.virtualization.microvm.adminvm.evaluatedConfig =
62+
config.ghaf.profiles.laptop-x86.adminvmBase.extendModules { modules = [...]; };
63+
'';
64+
}
65+
];
5966

60-
ghaf.common.extraNetworking.hosts.${vmName} = cfg.extraNetworking;
67+
ghaf.common.extraNetworking.hosts.${vmName} = cfg.extraNetworking;
6168

62-
microvm.vms."${vmName}" = {
63-
autostart = true;
64-
inherit (inputs) nixpkgs;
65-
inherit (cfg) evaluatedConfig;
66-
};
67-
};
69+
microvm.vms."${vmName}" = {
70+
autostart = true;
71+
inherit (inputs) nixpkgs;
72+
inherit (cfg) evaluatedConfig;
73+
};
74+
})
75+
];
6876
}

modules/microvm/sysvms/audiovm.nix

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,34 @@ in
4343
};
4444
};
4545

46-
config = lib.mkIf cfg.enable {
47-
assertions = [
48-
{
49-
assertion = cfg.evaluatedConfig != null;
50-
message = ''
51-
ghaf.virtualization.microvm.audiovm.evaluatedConfig must be set.
52-
Use audiovmBase.extendModules from a profile (laptop-x86, orin, etc.).
53-
Example:
54-
ghaf.virtualization.microvm.audiovm.evaluatedConfig =
55-
config.ghaf.profiles.laptop-x86.audiovmBase.extendModules { modules = [...]; };
56-
'';
57-
}
58-
];
46+
config = lib.mkMerge [
47+
{
48+
ghaf.virtualization.microvm.sysvm.vms.audiovm = {
49+
inherit vmName;
50+
inherit (cfg) enable evaluatedConfig extraNetworking;
51+
};
52+
}
53+
(lib.mkIf cfg.enable {
54+
assertions = [
55+
{
56+
assertion = cfg.evaluatedConfig != null;
57+
message = ''
58+
ghaf.virtualization.microvm.audiovm.evaluatedConfig must be set.
59+
Use audiovmBase.extendModules from a profile (laptop-x86, orin, etc.).
60+
Example:
61+
ghaf.virtualization.microvm.audiovm.evaluatedConfig =
62+
config.ghaf.profiles.laptop-x86.audiovmBase.extendModules { modules = [...]; };
63+
'';
64+
}
65+
];
5966

60-
ghaf.common.extraNetworking.hosts.${vmName} = cfg.extraNetworking;
67+
ghaf.common.extraNetworking.hosts.${vmName} = cfg.extraNetworking;
6168

62-
microvm.vms."${vmName}" = {
63-
autostart = !config.ghaf.microvm-boot.enable;
64-
inherit (inputs) nixpkgs;
65-
inherit (cfg) evaluatedConfig;
66-
};
67-
};
69+
microvm.vms."${vmName}" = {
70+
autostart = !config.ghaf.microvm-boot.enable;
71+
inherit (inputs) nixpkgs;
72+
inherit (cfg) evaluatedConfig;
73+
};
74+
})
75+
];
6876
}

modules/microvm/sysvms/guivm.nix

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,37 @@ in
5151
};
5252
};
5353

54-
config = lib.mkIf cfg.enable {
55-
assertions = [
56-
{
57-
assertion = cfg.evaluatedConfig != null;
58-
message = ''
59-
ghaf.virtualization.microvm.guivm.evaluatedConfig must be set.
60-
Use guivmBase.extendModules from a profile (laptop-x86, orin, etc.).
61-
Example:
62-
ghaf.virtualization.microvm.guivm.evaluatedConfig =
63-
lib.ghaf.vm.applyVmConfig {
64-
baseConfig = config.ghaf.profiles.laptop-x86.guivmBase.extendModules { ... };
65-
...
66-
};
67-
'';
68-
}
69-
];
54+
config = lib.mkMerge [
55+
{
56+
ghaf.virtualization.microvm.sysvm.vms.guivm = {
57+
inherit vmName;
58+
inherit (cfg) enable evaluatedConfig extraNetworking;
59+
};
60+
}
61+
(lib.mkIf cfg.enable {
62+
assertions = [
63+
{
64+
assertion = cfg.evaluatedConfig != null;
65+
message = ''
66+
ghaf.virtualization.microvm.guivm.evaluatedConfig must be set.
67+
Use guivmBase.extendModules from a profile (laptop-x86, orin, etc.).
68+
Example:
69+
ghaf.virtualization.microvm.guivm.evaluatedConfig =
70+
lib.ghaf.vm.applyVmConfig {
71+
baseConfig = config.ghaf.profiles.laptop-x86.guivmBase.extendModules { ... };
72+
...
73+
};
74+
'';
75+
}
76+
];
7077

71-
ghaf.common.extraNetworking.hosts.${vmName} = cfg.extraNetworking;
78+
ghaf.common.extraNetworking.hosts.${vmName} = cfg.extraNetworking;
7279

73-
microvm.vms."${vmName}" = {
74-
autostart = !config.ghaf.microvm-boot.enable;
75-
inherit (inputs) nixpkgs;
76-
inherit (cfg) evaluatedConfig;
77-
};
78-
};
80+
microvm.vms."${vmName}" = {
81+
autostart = !config.ghaf.microvm-boot.enable;
82+
inherit (inputs) nixpkgs;
83+
inherit (cfg) evaluatedConfig;
84+
};
85+
})
86+
];
7987
}

modules/microvm/sysvms/idsvm/idsvm.nix

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,34 @@ in
4747
};
4848
};
4949

50-
config = lib.mkIf cfg.enable {
51-
assertions = [
52-
{
53-
assertion = cfg.evaluatedConfig != null;
54-
message = ''
55-
ghaf.virtualization.microvm.idsvm.evaluatedConfig must be set.
56-
Use idsvmBase.extendModules from a profile (laptop-x86, etc.).
57-
Example:
58-
ghaf.virtualization.microvm.idsvm.evaluatedConfig =
59-
config.ghaf.profiles.laptop-x86.idsvmBase.extendModules { modules = [...]; };
60-
'';
61-
}
62-
];
50+
config = lib.mkMerge [
51+
{
52+
ghaf.virtualization.microvm.sysvm.vms.idsvm = {
53+
inherit vmName;
54+
inherit (cfg) enable evaluatedConfig extraNetworking;
55+
};
56+
}
57+
(lib.mkIf cfg.enable {
58+
assertions = [
59+
{
60+
assertion = cfg.evaluatedConfig != null;
61+
message = ''
62+
ghaf.virtualization.microvm.idsvm.evaluatedConfig must be set.
63+
Use idsvmBase.extendModules from a profile (laptop-x86, etc.).
64+
Example:
65+
ghaf.virtualization.microvm.idsvm.evaluatedConfig =
66+
config.ghaf.profiles.laptop-x86.idsvmBase.extendModules { modules = [...]; };
67+
'';
68+
}
69+
];
6370

64-
ghaf.common.extraNetworking.hosts.${vmName} = cfg.extraNetworking;
71+
ghaf.common.extraNetworking.hosts.${vmName} = cfg.extraNetworking;
6572

66-
microvm.vms."${vmName}" = {
67-
autostart = true;
68-
inherit (inputs) nixpkgs;
69-
inherit (cfg) evaluatedConfig;
70-
};
71-
};
73+
microvm.vms."${vmName}" = {
74+
autostart = true;
75+
inherit (inputs) nixpkgs;
76+
inherit (cfg) evaluatedConfig;
77+
};
78+
})
79+
];
7280
}

modules/microvm/sysvms/netvm.nix

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,42 @@ in
3939
};
4040
};
4141

42-
config = lib.mkIf cfg.enable {
43-
assertions = [
44-
{
45-
assertion = cfg.evaluatedConfig != null;
46-
message = ''
47-
ghaf.virtualization.microvm.netvm.evaluatedConfig must be set.
48-
Use a profile that provides netvmBase (laptop-x86 or orin).
42+
config = lib.mkMerge [
43+
{
44+
ghaf.virtualization.microvm.sysvm.vms.netvm = {
45+
inherit vmName;
46+
inherit (cfg) enable evaluatedConfig extraNetworking;
47+
};
48+
}
49+
(lib.mkIf cfg.enable {
50+
assertions = [
51+
{
52+
assertion = cfg.evaluatedConfig != null;
53+
message = ''
54+
ghaf.virtualization.microvm.netvm.evaluatedConfig must be set.
55+
Use a profile that provides netvmBase (laptop-x86 or orin).
4956
50-
For x86 laptops:
51-
netvm.evaluatedConfig = config.ghaf.profiles.laptop-x86.netvmBase.extendModules {
52-
modules = config.ghaf.hardware.definition.netvm.extraModules or [];
53-
};
57+
For x86 laptops:
58+
netvm.evaluatedConfig = config.ghaf.profiles.laptop-x86.netvmBase.extendModules {
59+
modules = config.ghaf.hardware.definition.netvm.extraModules or [];
60+
};
5461
55-
For Jetson (Orin):
56-
netvm.evaluatedConfig = config.ghaf.profiles.orin.netvmBase.extendModules {
57-
modules = config.ghaf.hardware.definition.netvm.extraModules or [];
58-
};
59-
'';
60-
}
61-
];
62+
For Jetson (Orin):
63+
netvm.evaluatedConfig = config.ghaf.profiles.orin.netvmBase.extendModules {
64+
modules = config.ghaf.hardware.definition.netvm.extraModules or [];
65+
};
66+
'';
67+
}
68+
];
6269

63-
ghaf.common.extraNetworking.hosts.${vmName} = cfg.extraNetworking;
70+
ghaf.common.extraNetworking.hosts.${vmName} = cfg.extraNetworking;
6471

65-
microvm.vms."${vmName}" = {
66-
autostart = !config.ghaf.microvm-boot.enable;
67-
restartIfChanged = false;
68-
inherit (inputs) nixpkgs;
69-
inherit (cfg) evaluatedConfig;
70-
};
71-
};
72+
microvm.vms."${vmName}" = {
73+
autostart = !config.ghaf.microvm-boot.enable;
74+
restartIfChanged = false;
75+
inherit (inputs) nixpkgs;
76+
inherit (cfg) evaluatedConfig;
77+
};
78+
})
79+
];
7280
}

0 commit comments

Comments
 (0)