From 55e075e01b6671d3f46bd01fcd583c493864efb9 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 1 May 2024 01:22:21 +0200 Subject: [PATCH] Allow hooking local ssh keys into the vm --- lib/config/custom-build-vm.nix | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/config/custom-build-vm.nix b/lib/config/custom-build-vm.nix index 4ca0d9a..8582ddd 100644 --- a/lib/config/custom-build-vm.nix +++ b/lib/config/custom-build-vm.nix @@ -6,6 +6,11 @@ default = false; }; + sharedHostKeys = lib.mkOption { + type = lib.types.bool; + default = false; + }; + qemu.runInBackground = lib.mkOption { type = lib.types.bool; default = false; @@ -16,12 +21,27 @@ config = { virtualisation = let - vmConfig = { - boot.loader.efi.efiSysMountPoint = lib.mkVMOverride "/boot"; - }; + extendVMConfig = + vmVariant: { + boot.loader.efi.efiSysMountPoint = lib.mkVMOverride "/boot"; + + virtualisation.sharedDirectories = lib.optionalAttrs (vmVariant.virtualisation.sharedHostKeys) { + hostKeys = + let + path = "/etc/ssh"; + in { + source = path; + target = path; + }; + }; + }; + + virtualisation = config.virtualisation; in { - vmVariant = vmConfig; - vmVariantWithBootLoader = vmConfig; + + vmVariant = extendVMConfig virtualisation.vmVariant; + vmVariantWithBootLoader = extendVMConfig virtualisation.vmVariantWithBootLoader; + runAsRoot = lib.mkIf config.virtualisation.sharedHostKeys true; }; # Replace native `qemu` with `remote-viewer`