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