From 539d770d20652a83f47d90dcac778e5cd2163f71 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 1 May 2024 00:50:02 +0200 Subject: [PATCH] Allow running `qemu` in background --- lib/config/custom-build-vm.nix | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/config/custom-build-vm.nix b/lib/config/custom-build-vm.nix index e75180f..4ca0d9a 100644 --- a/lib/config/custom-build-vm.nix +++ b/lib/config/custom-build-vm.nix @@ -5,6 +5,11 @@ type = lib.types.bool; default = false; }; + + qemu.runInBackground = lib.mkOption { + type = lib.types.bool; + default = false; + }; }; }; @@ -46,11 +51,22 @@ vm else let - prefix = lib.concatStringsSep " " (lib.optional config.virtualisation.runAsRoot "sudo"); + prefix = + lib.concatStringsSep " " ( + lib.optionals config.virtualisation.runAsRoot ( + ["sudo"] ++ + lib.optional config.virtualisation.qemu.runInBackground "-b")); + + suffix = + lib.concatStringsSep " " ( + lib.optional + (!config.virtualisation.runAsRoot && config.virtualisation.qemu.runInBackground) + "&"); + wrapped = pkgs.writeShellApplication { name = "run-${config.system.name}-vm"; text = '' - ${prefix} ${vm}/bin/run-${config.system.name}-vm + ${prefix} ${vm}/bin/run-${config.system.name}-vm ${suffix} ''; }; in