diff --git a/lib/config/custom-build-vm.nix b/lib/config/custom-build-vm.nix index 9101d3e..b7d9198 100644 --- a/lib/config/custom-build-vm.nix +++ b/lib/config/custom-build-vm.nix @@ -1,35 +1,46 @@ -{ config, lib, pkgs, ... }: { - config = { - # Replace native `qemu` with `remote-viewer` - system.build = { - vmWithBootLoader = pkgs.writeShellApplication { +{ config, lib, pkgs, ... }: +let + createVmRunner = + vmVariant: + pkgs.writeShellApplication { name = "run-${config.system.name}-vm"; text = '' - ${config.virtualisation.vmVariant.system.build.vm}/bin/run-${config.system.name}-vm + ${vmVariant.system.build.vm}/bin/run-${config.system.name}-vm ''; }; - }; +in + { + config = { + # Replace native `qemu` with `remote-viewer` + system.build = + with { + inherit (config.virtualisation) + vmVariantWithBootLoader + ; + }; + { + vmWithBootLoader = createVmRunner vmVariantWithBootLoader; + }; - virtualisation = - let vmConfig = { - boot.loader.efi.efiSysMountPoint = lib.mkForce "/boot"; + virtualisation = + let vmConfig = { + boot.loader.efi.efiSysMountPoint = lib.mkForce "/boot"; - virtualisation = { - qemu.options = [ - "-display sdl" - ]; + virtualisation = { + qemu.options = [ + "-display sdl" + ]; - sharedDirectories = { - hostKeys = { - source = "/etc/ssh"; - target = "/etc/ssh"; + sharedDirectories = { + hostKeys = { + source = "/etc/ssh"; + target = "/etc/ssh"; + }; }; }; }; - }; - in { - vmVariant = vmConfig; - vmVariantWithBootLoader = vmConfig; - }; - }; -} + in { + vmVariantWithBootLoader = vmConfig; + }; + }; + }