Apply the wrapper to the default vm

This commit is contained in:
Manuel Thalmann 2024-04-30 23:22:35 +02:00
parent 20f1bdaa13
commit 591ba4e96e

View file

@ -1,46 +1,66 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }: {
let options = {};
createVmRunner =
vmVariant: config = {
pkgs.writeShellApplication { # Replace native `qemu` with `remote-viewer`
name = "run-${config.system.name}-vm"; system.build =
text = '' {
${vmVariant.system.build.vm}/bin/run-${config.system.name}-vm vm =
''; let
packageName = "custom-nixos-vm";
mergedSystem =
with options.system;
lib.mergeDefinitions
build.loc
build.type
(lib.lists.forEach
(
builtins.filter
(item:
!(lib.path.hasPrefix ./. (/. + item.file)))
build.definitionsWithLocations)
(item: { inherit (item) file value; }));
in
lib.mkForce (
if (mergedSystem.mergedValue.vm.name == packageName)
then
mergedSystem.mergedValue.vm
else
let
wrapped = pkgs.writeShellApplication {
name = "run-${config.system.name}-vm";
text = ''
${mergedSystem.mergedValue.vm}/bin/run-${config.system.name}-vm
'';
};
in
# Rename package to `nixos-vm`
pkgs.symlinkJoin {
name = packageName;
paths = [ wrapped ];
});
}; };
in
{
config = {
# Replace native `qemu` with `remote-viewer`
system.build =
with {
inherit (config.virtualisation)
vmVariantWithBootLoader
;
};
{
vmWithBootLoader = createVmRunner vmVariantWithBootLoader;
};
virtualisation = virtualisation =
let vmConfig = { let vmConfig = {
boot.loader.efi.efiSysMountPoint = lib.mkForce "/boot"; boot.loader.efi.efiSysMountPoint = lib.mkForce "/boot";
virtualisation = { virtualisation = {
qemu.options = [ qemu.options = [
"-display sdl" "-display sdl"
]; ];
sharedDirectories = { sharedDirectories = {
hostKeys = { hostKeys = {
source = "/etc/ssh"; source = "/etc/ssh";
target = "/etc/ssh"; target = "/etc/ssh";
};
}; };
}; };
}; };
in { };
vmVariantWithBootLoader = vmConfig; in {
}; vmVariantWithBootLoader = vmConfig;
}; };
} };
}