From 8271210aaae3b6f2cc59530b147dcbebf6e56164 Mon Sep 17 00:00:00 2001 From: Paul Meyer <49727155+katexochen@users.noreply.github.com> Date: Tue, 22 Aug 2023 10:17:21 +0200 Subject: [PATCH] mkosi: add qemu for starting vms Adding the option to build mkosi with qemu support, which enables the usage of 'mkosi qemu' to boot the previously built image as VM. This will only work for host=target right now, further effort is required to allow target with different arch. Co-authored-by: Malte Poll Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> --- pkgs/tools/virtualization/mkosi/default.nix | 27 +++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pkgs/tools/virtualization/mkosi/default.nix b/pkgs/tools/virtualization/mkosi/default.nix index 608d60387f5f..79a34b15fd4a 100644 --- a/pkgs/tools/virtualization/mkosi/default.nix +++ b/pkgs/tools/virtualization/mkosi/default.nix @@ -1,15 +1,22 @@ { lib , fetchFromGitHub +, stdenv , python3 +, bubblewrap +, systemd + + # Python packages , setuptools , setuptools-scm , wheel , buildPythonApplication , pytestCheckHook , pefile -, bubblewrap -, systemd -, stdenv + + # Optional dependencies +, withQemu ? false +, qemu +, OVMF }: let # For systemd features used by mkosi, see @@ -43,10 +50,14 @@ buildPythonApplication rec { # Fix ctypes finding library # https://github.com/NixOS/nixpkgs/issues/7307 patchPhase = lib.optionalString stdenv.isLinux '' - substituteInPlace mkosi/run.py --replace \ - 'ctypes.util.find_library("c")' "'${stdenv.cc.libc}/lib/libc.so.6'" - substituteInPlace mkosi/__init__.py --replace \ - '/usr/lib/systemd/ukify' "${systemdForMkosi}/lib/systemd/ukify" + substituteInPlace mkosi/run.py \ + --replace 'ctypes.util.find_library("c")' "'${stdenv.cc.libc}/lib/libc.so.6'" + substituteInPlace mkosi/__init__.py \ + --replace '/usr/lib/systemd/ukify' "${systemdForMkosi}/lib/systemd/ukify" + '' + lib.optionalString withQemu '' + substituteInPlace mkosi/qemu.py \ + --replace '/usr/share/ovmf/x64/OVMF_VARS.fd' "${OVMF.variables}" \ + --replace '/usr/share/ovmf/x64/OVMF_CODE.fd' "${OVMF.firmware}" ''; nativeBuildInputs = [ @@ -62,6 +73,8 @@ buildPythonApplication rec { propagatedBuildInputs = [ systemdForMkosi bubblewrap + ] ++ lib.optional withQemu [ + qemu ]; postInstall = ''