interactive-vm: convert into NixOS module

This commit is contained in:
Michael Hoang 2024-09-08 03:29:33 +10:00
parent ba66c22ec1
commit 0943a50ee7
3 changed files with 44 additions and 46 deletions

View file

@ -16,8 +16,6 @@ let
# a version of makeDiskImage which runs outside of the store # a version of makeDiskImage which runs outside of the store
makeDiskImagesScript = args: (import ./make-disk-image.nix ({ inherit diskoLib; } // args)).impure; makeDiskImagesScript = args: (import ./make-disk-image.nix ({ inherit diskoLib; } // args)).impure;
makeVMRunner = args: import ./interactive-vm.nix ({ inherit diskoLib; } // args);
testLib = import ./tests.nix { inherit lib makeTest eval-config; }; testLib = import ./tests.nix { inherit lib makeTest eval-config; };
# like lib.types.oneOf but instead of a list takes an attrset # like lib.types.oneOf but instead of a list takes an attrset
# uses the field "type" to find the correct type in the attrset # uses the field "type" to find the correct type in the attrset

View file

@ -1,10 +1,9 @@
{ nixosConfig # We need to specify extendModules here to ensure that it is available
, diskoLib # in args for makeDiskImages
, pkgs ? nixosConfig.pkgs { diskoLib, modulesPath, config, pkgs, lib, extendModules, ... }@args:
}:
let let
lib = pkgs.lib; vm_disko = (diskoLib.testLib.prepareDiskoConfig config diskoLib.testLib.devices).disko;
vm_disko = (diskoLib.testLib.prepareDiskoConfig nixosConfig.config diskoLib.testLib.devices).disko;
cfg_ = (lib.evalModules { cfg_ = (lib.evalModules {
modules = lib.singleton { modules = lib.singleton {
# _file = toString input; # _file = toString input;
@ -22,7 +21,7 @@ let
}).config; }).config;
disks = lib.attrValues cfg_.disko.devices.disk; disks = lib.attrValues cfg_.disko.devices.disk;
diskoImages = diskoLib.makeDiskImages { diskoImages = diskoLib.makeDiskImages {
nixosConfig = nixosConfig; nixosConfig = args;
copyNixStore = false; copyNixStore = false;
extraConfig = { extraConfig = {
disko.devices = cfg_.disko.devices; disko.devices = cfg_.disko.devices;
@ -45,11 +44,18 @@ let
driveExtraOpts.werror = "report"; driveExtraOpts.werror = "report";
}) })
(builtins.tail disks); (builtins.tail disks);
in nixosConfig.extendModules {
modules = [ diskoBasedConfiguration = {
({ modulesPath, config, pkgs, ... }: { # generated from disko config
virtualisation.fileSystems = cfg_.disko.devices._config.fileSystems;
boot = cfg_.disko.devices._config.boot or { };
swapDevices = cfg_.disko.devices._config.swapDevices or [ ];
};
in
{
imports = [ imports = [
(modulesPath + "/virtualisation/qemu-vm.nix") (modulesPath + "/virtualisation/qemu-vm.nix")
diskoBasedConfiguration
]; ];
virtualisation.useEFIBoot = config.disko.tests.efi; virtualisation.useEFIBoot = config.disko.tests.efi;
@ -72,13 +78,4 @@ in nixosConfig.extendModules {
set +f set +f
${config.system.build.vm}/bin/run-*-vm ${config.system.build.vm}/bin/run-*-vm
''; '';
})
{
# generated from disko config
virtualisation.fileSystems = cfg_.disko.devices._config.fileSystems;
boot = cfg_.disko.devices._config.boot or { };
swapDevices = cfg_.disko.devices._config.swapDevices or [ ];
}
nixosConfig.config.disko.tests.extraConfig
];
} }

View file

@ -8,9 +8,12 @@ let
}; };
cfg = config.disko; cfg = config.disko;
vmVariantWithDisko = diskoLib.makeVMRunner { vmVariantWithDisko = extendModules {
inherit pkgs; modules = [
nixosConfig = args; ./lib/interactive-vm.nix
{ _module.args = { inherit diskoLib; }; }
config.disko.tests.extraConfig
];
}; };
in in
{ {