Skip to content

Conversation

Mic92
Copy link
Member

@Mic92 Mic92 commented Jun 1, 2025

This PR adds support for the machineConfigModule parameter to all distro modules (ubuntu, debian, fedora), allowing users to customize VM configuration such as memory size, CPU count, and other virtualisation settings.

Changes

All distro modules (ubuntu, debian, fedora):

  • Added machineConfigModule parameter to makeVmTestForImage function
  • Parameter defaults to generic.defaultMachineConfigModule for backward compatibility
  • Passes the parameter through to generic.makeVmTest

Debian module specifically:

  • Fixed missing extraPathsToRegister parameter in makeVmTestForImage function
  • This ensures consistency with ubuntu and fedora modules

Usage

Users can now customize VM configuration like this:

nix-vm-test.lib.x86_64-linux.ubuntu."22_04" {
  testScript = "...";
  sharedDirs = {};
  machineConfigModule = { ... }: {
    nodes.vm.virtualisation.memorySize = 2048;  # 2GB RAM
    nodes.vm.virtualisation.cpus = 2;           # 2 CPU cores
  };
}

Backward Compatibility

All changes are backward compatible - existing code will continue to work without modification.

Mic92 added 2 commits June 1, 2025 10:08
- Add machineConfigModule parameter to ubuntu, debian, and fedora makeVmTestForImage functions
- Default to generic.defaultMachineConfigModule when not provided
- This allows users to customize machine configuration for VM tests
- Add missing extraPathsToRegister parameter to debian makeVmTestForImage function
- This ensures consistency with ubuntu and fedora modules
- Fixes parameter mismatch where prepareDebianImage expected extraPathsToRegister but makeVmTestForImage didn't accept it
@Mic92 Mic92 requested review from picnoir and r-vdp and removed request for picnoir June 2, 2025 15:12
@picnoir
Copy link
Member

picnoir commented Jun 2, 2025

Hmm, this API was not originally meant to be public. Doing this, we're exposing a few footguns (the vlan and rootImage part mostly). We probably should clean this up/filter those, but it's fine to do that in a subsequent PR.

I'm fine to merge this if you add a brief description of this new API to the reference documentation?

#### Inputs
(at least for memorySize and cpus).

@picnoir
Copy link
Member

picnoir commented Jun 2, 2025

On second thought, a proper way to do this would be to add memorySize and cpus, the only bits that really matter, to the makeVmTestForImage APIs. There's one call site per distribution. We could probably merge all that.

@Mic92
Copy link
Member Author

Mic92 commented Jun 2, 2025

When I was looking at the code I also wondering why nix-vm-test is not just a module for the nixos vm test module system? This is how we implemented our clan vm tests and nixos container. Is this something you considered?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants