From 60e3a11e1ea74f2608dcb439b6675af3a9e5b987 Mon Sep 17 00:00:00 2001 From: Adam Stephens Date: Sun, 30 Jul 2023 13:07:44 -0400 Subject: [PATCH] lxd: add dependencies to wrapper for VM support --- pkgs/tools/admin/lxd/wrapper.nix | 61 ++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/pkgs/tools/admin/lxd/wrapper.nix b/pkgs/tools/admin/lxd/wrapper.nix index 55b721ed24b3..8052484ce7c4 100644 --- a/pkgs/tools/admin/lxd/wrapper.nix +++ b/pkgs/tools/admin/lxd/wrapper.nix @@ -1,6 +1,8 @@ { lib , lxd-unwrapped +, linkFarm , makeWrapper +, stdenv , symlinkJoin , writeShellScriptBin , acl @@ -12,13 +14,18 @@ , criu , dnsmasq , gnutar +, gptfdisk , gzip , iproute2 , iptables +, OVMF +, qemu_kvm +, qemu-utils , rsync +, spice-gtk , squashfsTools +, virtiofsd , xz -, }: let binPath = lib.makeBinPath [ @@ -29,17 +36,63 @@ let criu dnsmasq gnutar + gptfdisk gzip iproute2 iptables + qemu_kvm + qemu-utils rsync squashfsTools + virtiofsd xz (writeShellScriptBin "apparmor_parser" '' exec '${apparmor-parser}/bin/apparmor_parser' -I '${apparmor-profiles}/etc/apparmor.d' "$@" '') ]; + + clientBinPath = [ + spice-gtk + ]; + + ovmf-2mb = OVMF.override { + secureBoot = true; + csmSupport = false; + fdSize2MB = true; + }; + + ovmf-4mb = OVMF.override { + secureBoot = true; + csmSupport = false; + fdSize4MB = true; + }; + + ovmf-4mb-csm = OVMF.override { + secureBoot = true; + csmSupport = false; + fdSize2MB = false; + fdSize4MB = true; + }; + + ovmf-prefix = if stdenv.hostPlatform.isAarch64 then "AAVMF" else "OVMF"; + + # mimic ovmf from https://github.com/canonical/lxd-pkg-snap/blob/3abebe1dfeb20f9b7729556960c7e9fe6ad5e17c/snapcraft.yaml#L378 + # also found in /snap/lxd/current/share/qemu/ on a snap install + ovmf = linkFarm "lxd-ovmf" [ + { name = "OVMF_CODE.2MB.fd"; path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_CODE.fd"; } + { name = "OVMF_CODE.4MB.CSM.fd"; path = "${ovmf-4mb-csm.fd}/FV/${ovmf-prefix}_CODE.fd"; } + { name = "OVMF_CODE.4MB.fd"; path = "${ovmf-4mb.fd}/FV/${ovmf-prefix}_CODE.fd"; } + { name = "OVMF_CODE.fd"; path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_CODE.fd"; } + + { name = "OVMF_VARS.2MB.fd"; path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd"; } + { name = "OVMF_VARS.2MB.ms.fd"; path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd"; } + { name = "OVMF_VARS.4MB.CSM.fd"; path = "${ovmf-4mb-csm.fd}/FV/${ovmf-prefix}_VARS.fd"; } + { name = "OVMF_VARS.4MB.fd"; path = "${ovmf-4mb.fd}/FV/${ovmf-prefix}_VARS.fd"; } + { name = "OVMF_VARS.4MB.ms.fd"; path = "${ovmf-4mb.fd}/FV/${ovmf-prefix}_VARS.fd"; } + { name = "OVMF_VARS.fd"; path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd"; } + { name = "OVMF_VARS.ms.fd"; path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd"; } + ]; in symlinkJoin { name = "lxd-${lxd-unwrapped.version}"; @@ -49,11 +102,13 @@ symlinkJoin { nativeBuildInputs = [ makeWrapper ]; postBuild = '' - wrapProgram $out/bin/lxd --prefix PATH : ${lib.escapeShellArg binPath} + wrapProgram $out/bin/lxd --prefix PATH : ${lib.escapeShellArg binPath}:${qemu_kvm}/libexec:$out/bin --set LXD_OVMF_PATH ${ovmf} + + wrapProgram $out/bin/lxc --prefix PATH : ${lib.makeBinPath clientBinPath} ''; passthru = { - inherit (lxd-unwrapped) tests; + inherit (lxd-unwrapped) tests ui; }; inherit (lxd-unwrapped) meta pname version;