NixOSConfig/lib/config/custom-build-vm.nix

67 lines
1.8 KiB
Nix
Raw Normal View History

2024-04-30 21:22:35 +00:00
{ config, lib, options, pkgs, ... }: {
options = {};
config = {
# Replace native `qemu` with `remote-viewer`
system.build =
{
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 ];
});
};
2024-04-30 21:22:35 +00:00
virtualisation =
let vmConfig = {
boot.loader.efi.efiSysMountPoint = lib.mkForce "/boot";
2024-04-30 21:22:35 +00:00
virtualisation = {
qemu.options = [
"-display sdl"
];
2024-04-30 21:22:35 +00:00
sharedDirectories = {
hostKeys = {
source = "/etc/ssh";
target = "/etc/ssh";
};
};
};
2024-04-30 21:22:35 +00:00
};
in {
vmVariantWithBootLoader = vmConfig;
};
};
}