Skip to content

Commit a806d50

Browse files
appvm: align the naming conventions for resources
Appvms were using ramMb and cores while the sysvms were using mem and vcpu. consolidate the naming conventions on mem and vcpu across both types of vm. Signed-off-by: Brian McGillion <bmg.avoin@gmail.com>
1 parent 79c0c8c commit a806d50

File tree

16 files changed

+49
-49
lines changed

16 files changed

+49
-49
lines changed

docs/src/content/docs/ghaf/dev/guides/creating-vms.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ Application VMs use a template pattern for multiple instances.
220220

221221
### Using mkAppVm
222222

223-
The `mkAppVm` function creates application VMs. All values (name, ramMb, borderColor, applications, vtpm) are defined in the `mkAppVm` call and stored in `evaluatedConfig.config.ghaf.appvm.vmDef`. Host-level options automatically read from there.
223+
The `mkAppVm` function creates application VMs. All values (name, mem, borderColor, applications, vtpm) are defined in the `mkAppVm` call and stored in `evaluatedConfig.config.ghaf.appvm.vmDef`. Host-level options automatically read from there.
224224

225225
```nix
226226
{ config, lib, ... }:
@@ -277,7 +277,7 @@ Use the `extensions` option to add modules to an existing app VM without modifyi
277277
| `usbPassthrough` | list | USB passthrough rules (host-side) |
278278
| `bootPriority` | enum | Boot priority: "low", "medium", "high" |
279279

280-
Values like `name`, `ramMb`, `borderColor`, `applications`, and `vtpm` are all derived from `evaluatedConfig.config.ghaf.appvm.vmDef` and should be set in the `mkAppVm` call, not at the host level.
280+
Values like `name`, `mem`, `borderColor`, `applications`, and `vtpm` are all derived from `evaluatedConfig.config.ghaf.appvm.vmDef` and should be set in the `mkAppVm` call, not at the host level.
281281

282282
### Application Definition
283283

docs/src/content/docs/ghaf/dev/ref/creating_appvm.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ To create an App VM, do the following:
2020
| name | str | yes | This name is postfixed with `-vm` and will be shown in microvm list. The name, for example, `chromium-vm` will be also the VM hostname. The length of the name must be 8 characters or less. | “chromium” |
2121
| packages | list of types.package | no | Packages to include in a VM. It is possible to make it empty or add several packages. | [chromium top] |
2222
| macAddress | str | yes | Needed for network configuration. | "02:00:00:03:03:05" |
23-
| ramMb | int, [1, …, host memory] | no | Memory in MB. | 3072 |
24-
| cores | int, [1, …, host cores] | no | Virtual CPU cores. |
23+
| mem | int, [1, …, host memory] | no | Memory in MB. | 3072 |
24+
| vcpu | int, [1, …, host cores] | no | Virtual CPU cores. |
2525

2626
2. Create a new option for your VM in [modules/reference/appvms/default.nix](https://github.com/tiiuae/ghaf/blob/main/modules/reference/appvms/default.nix). For example:
2727

modules/microvm/appvm.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# The VM-side configuration is in appvm-base.nix, created via mkAppVm in profiles.
1313
#
1414
# Extension Pattern:
15-
# ALL values (name, ramMb, borderColor, applications, etc.) should be defined ONLY
15+
# ALL values (name, mem, borderColor, applications, etc.) should be defined ONLY
1616
# in the mkAppVm call. Host-level options automatically read from
1717
# evaluatedConfig.config.ghaf.appvm.vmDef. This eliminates duplication.
1818
#
@@ -59,7 +59,7 @@ let
5959
evaluatedConfig = finalEvaluatedConfig;
6060
# Derive values from vmDef - the attrset key is used as fallback for name
6161
name = vmDef.name or attrName;
62-
ramMb = vmDef.ramMb or 4096;
62+
mem = vmDef.mem or 4096;
6363
balloonRatio = vmDef.balloonRatio or 2;
6464
borderColor = vmDef.borderColor or null;
6565
applications = vmDef.applications or [ ];
@@ -139,7 +139,7 @@ in
139139
description = ''
140140
Read-only attrset of enabled VMs with all values derived from evaluatedConfig.
141141
Use this instead of accessing vms directly when you need derived values
142-
like vtpm, applications, ramMb, etc.
142+
like vtpm, applications, mem, etc.
143143
'';
144144
};
145145

@@ -148,7 +148,7 @@ in
148148
App VM configurations. Each VM must have evaluatedConfig set via mkAppVm.
149149
150150
Extension Pattern:
151-
- ALL values (name, ramMb, borderColor, applications, vtpm, etc.)
151+
- ALL values (name, mem, borderColor, applications, vtpm, etc.)
152152
are derived from evaluatedConfig.config.ghaf.appvm.vmDef
153153
- You only need to set 'enable' and 'evaluatedConfig' here
154154
- Use 'extensions' to add modules from external features (e.g., ghaf-intro)

modules/microvm/host/mem-manager.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ in
3030
let
3131
vmConfig = lib.ghaf.vm.getConfig config.microvm.vms.${name};
3232
microvmConfig = vmConfig.microvm;
33-
# Use enabledVms which has derived ramMb from evaluatedConfig
33+
# Use enabledVms which has derived mem from evaluatedConfig
3434
vmBaseName = lib.removeSuffix "-vm" name;
3535
appvmConfig = config.ghaf.virtualization.microvm.appvm.enabledVms.${vmBaseName} or null;
3636
in
@@ -43,7 +43,7 @@ in
4343
Type = "simple";
4444
WorkingDirectory = "${config.microvm.stateDir}/${name}";
4545
ExecStart = "${pkgs.ghaf-mem-manager}/bin/ghaf-mem-manager -s ${name}.sock -m ${
46-
toString (appvmConfig.ramMb * 1024 * 1024)
46+
toString (appvmConfig.mem * 1024 * 1024)
4747
} -M ${toString (microvmConfig.mem * 1024 * 1024)}";
4848
};
4949
};

modules/microvm/sysvms/appvm-base.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Unlike singleton VMs (gui-vm, net-vm, etc.), App VMs are instantiated multiple times.
1010
# Each instance is configured via hostConfig.appvm which contains:
1111
# - name: VM name (e.g., "chromium", "comms")
12-
# - ramMb, cores: Resource allocation
12+
# - mem, vcpu: Resource allocation
1313
# - applications: List of apps with name, command, packages, etc.
1414
# - packages: Additional packages for the VM
1515
# - vtpm, waypipe, ghafAudio: Feature flags
@@ -305,10 +305,10 @@ in
305305
microvm = {
306306
optimize.enable = false;
307307
# Sensible defaults based on vm definition - can be further overridden via vmConfig
308-
mem = lib.mkDefault ((vm.ramMb or 4096) * ((vm.balloonRatio or 2) + 1));
308+
mem = lib.mkDefault ((vm.mem or 4096) * ((vm.balloonRatio or 2) + 1));
309309
balloon = (vm.balloonRatio or 2) > 0;
310310
deflateOnOOM = false;
311-
vcpu = lib.mkDefault (vm.cores or 4);
311+
vcpu = lib.mkDefault (vm.vcpu or 4);
312312
hypervisor = "qemu";
313313

314314
shares = [

modules/microvm/vm-config.nix

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ let
8282
};
8383
};
8484

85-
# App VM configuration submodule (uses ramMb/cores for consistency with appvm definitions)
85+
# App VM configuration submodule (uses mem/vcpu for consistency with system VM definitions)
8686
appVmConfigType = types.submodule {
8787
options = {
88-
ramMb = mkOption {
88+
mem = mkOption {
8989
type = types.nullOr types.int;
9090
default = null;
9191
description = "App VM memory allocation in MB.";
9292
};
9393

94-
cores = mkOption {
94+
vcpu = mkOption {
9595
type = types.nullOr types.int;
9696
default = null;
9797
description = "App VM vCPU count.";
@@ -101,7 +101,7 @@ let
101101
type = types.nullOr types.int;
102102
default = null;
103103
description = ''
104-
Memory balloon ratio. The VM is allocated ramMb * (balloonRatio + 1)
104+
Memory balloon ratio. The VM is allocated mem * (balloonRatio + 1)
105105
bytes of memory, with ballooning enabled when balloonRatio > 0.
106106
If null, uses the default from the VM definition (typically 2).
107107
'';
@@ -157,8 +157,8 @@ in
157157
'';
158158
example = literalExpression ''
159159
{
160-
chromium = { ramMb = 8192; extraModules = [ ./chrome.nix ]; };
161-
comms = { ramMb = 4096; };
160+
chromium = { mem = 8192; extraModules = [ ./chrome.nix ]; };
161+
comms = { mem = 4096; };
162162
}
163163
'';
164164
};

modules/profiles/laptop-x86.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ in
213213
mkAppVm =
214214
vmDef:
215215
let
216-
# Apply vmConfig.appvms overrides (ramMb, cores)
216+
# Apply vmConfig.appvms overrides (mem, vcpu)
217217
vmCfg = config.ghaf.virtualization.vmConfig.appvms.${vmDef.name} or { };
218218
effectiveDef =
219219
vmDef
220-
// lib.optionalAttrs ((vmCfg.ramMb or null) != null) { inherit (vmCfg) ramMb; }
221-
// lib.optionalAttrs ((vmCfg.cores or null) != null) { inherit (vmCfg) cores; }
220+
// lib.optionalAttrs ((vmCfg.mem or null) != null) { inherit (vmCfg) mem; }
221+
// lib.optionalAttrs ((vmCfg.vcpu or null) != null) { inherit (vmCfg) vcpu; }
222222
// lib.optionalAttrs ((vmCfg.balloonRatio or null) != null) { inherit (vmCfg) balloonRatio; };
223223
in
224224
lib.nixosSystem {

modules/reference/appvms/business.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ in
133133
# (reference appvms use laptop-x86.mkAppVm which doesn't exist on other profiles like Orin)
134134
config = lib.mkIf (cfg.enable && config.ghaf.profiles.laptop-x86.enable or false) {
135135
# DRY: Only enable, evaluatedConfig, and usbPassthrough at host level.
136-
# All values (name, ramMb, borderColor, applications, vtpm) are derived from vmDef.
136+
# All values (name, mem, borderColor, applications, vtpm) are derived from vmDef.
137137
ghaf.virtualization.microvm.appvm.vms.business = {
138138
enable = lib.mkDefault true;
139139

@@ -149,8 +149,8 @@ in
149149
evaluatedConfig = config.ghaf.profiles.laptop-x86.mkAppVm {
150150
name = "business";
151151
packages = optionals config.ghaf.profiles.debug.enable [ pkgs.tcpdump ];
152-
ramMb = 6144;
153-
cores = 4;
152+
mem = 6144;
153+
vcpu = 4;
154154
borderColor = "#218838";
155155
ghafAudio.enable = lib.mkDefault true;
156156
vtpm = {

modules/reference/appvms/chromium.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ in
2323
# (reference appvms use laptop-x86.mkAppVm which doesn't exist on other profiles like Orin)
2424
config = lib.mkIf (cfg.enable && config.ghaf.profiles.laptop-x86.enable or false) {
2525
# DRY: Only enable and evaluatedConfig at host level.
26-
# All values (name, ramMb, borderColor, applications, vtpm) are derived from vmDef.
26+
# All values (name, mem, borderColor, applications, vtpm) are derived from vmDef.
2727
ghaf.virtualization.microvm.appvm.vms.chromium = {
2828
enable = lib.mkDefault false;
2929

3030
evaluatedConfig = config.ghaf.profiles.laptop-x86.mkAppVm {
3131
name = "chromium";
3232
packages = lib.optional config.ghaf.development.debug.tools.enable pkgs.alsa-utils;
33-
ramMb = 6144;
34-
cores = 4;
33+
mem = 6144;
34+
vcpu = 4;
3535
borderColor = "#9C0000";
3636
ghafAudio.enable = lib.mkDefault true;
3737
vtpm = {

modules/reference/appvms/comms.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ in
2323
# (reference appvms use laptop-x86.mkAppVm which doesn't exist on other profiles like Orin)
2424
config = lib.mkIf (cfg.enable && config.ghaf.profiles.laptop-x86.enable or false) {
2525
# DRY: Only enable and evaluatedConfig at host level.
26-
# All values (name, ramMb, borderColor, applications, vtpm) are derived from vmDef.
26+
# All values (name, mem, borderColor, applications, vtpm) are derived from vmDef.
2727
ghaf.virtualization.microvm.appvm.vms.comms = {
2828
enable = lib.mkDefault true;
2929

@@ -34,8 +34,8 @@ in
3434
pkgs.gpsd
3535
]
3636
++ lib.optionals config.ghaf.profiles.debug.enable [ pkgs.tcpdump ];
37-
ramMb = 4096;
38-
cores = 4;
37+
mem = 4096;
38+
vcpu = 4;
3939
borderColor = "#337aff";
4040
ghafAudio.enable = lib.mkDefault true;
4141
vtpm = {

0 commit comments

Comments
 (0)