Allow adding custom options to individual vms

This commit is contained in:
Manuel Thalmann 2024-05-01 00:03:35 +02:00
parent 591ba4e96e
commit 0480f0d4a4

View file

@ -1,66 +1,53 @@
{ config, lib, options, pkgs, ... }: { { config, lib, options, pkgs, ... }:
options = {}; let
vmOptions = { };
config = { in {
# Replace native `qemu` with `remote-viewer` options = {
system.build = virtualisation = {
{ vmVariant = vmOptions;
vm = vmVariantWithBootLoader = vmOptions;
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 ];
});
}; };
};
virtualisation = config = {
let vmConfig = { # Replace native `qemu` with `remote-viewer`
boot.loader.efi.efiSysMountPoint = lib.mkForce "/boot"; system.build =
{
vm =
let
packageName = "custom-nixos-vm";
virtualisation = { mergedSystem =
qemu.options = [ with options.system;
"-display sdl" lib.mergeDefinitions
]; build.loc
build.type
sharedDirectories = { (lib.lists.forEach
hostKeys = { (
source = "/etc/ssh"; builtins.filter
target = "/etc/ssh"; (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 { }
vmVariantWithBootLoader = vmConfig;
};
};
}