From 3f6aa2017aa8a61a173b343dc4a551182488e1f9 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 20 Jun 2024 15:18:28 -0700 Subject: [PATCH 1/3] libkrunfw: 4.0.0 -> 4.0.0-unstable-2024-06-10, build on aarch64 --- .../libraries/libkrunfw/default.nix | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/pkgs/development/libraries/libkrunfw/default.nix b/pkgs/development/libraries/libkrunfw/default.nix index 0485c82ffb41..21b8918d75ec 100644 --- a/pkgs/development/libraries/libkrunfw/default.nix +++ b/pkgs/development/libraries/libkrunfw/default.nix @@ -5,25 +5,27 @@ , flex , bison , bc +, cpio +, perl , elfutils , python3 , sevVariant ? false }: -stdenv.mkDerivation rec { +stdenv.mkDerivation (finalAttrs: { pname = "libkrunfw"; - version = "4.0.0"; + version = "4.0.0-unstable-2024-06-10"; src = fetchFromGitHub { owner = "containers"; repo = "libkrunfw"; - rev = "refs/tags/v${version}"; - hash = "sha256-9oVl4mlJE7QHeehG86pbh7KdShZNUGwlnO75k/F/PQ0="; + rev = "12236fa4caa42423ff3081b6179aa0a5f37c67c9"; + hash = "sha256-Vcbg2zBVMQsiAQF/cEEIRMqppMBVGnqUBlDquGzRBsc="; }; kernelSrc = fetchurl { - url = "https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.4.7.tar.xz"; - hash = "sha256-3hQ8th3Kp1bAX1b/NRRDFtgQYVgZUYoz40dU8GTEp9g="; + url = "https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.6.32.tar.xz"; + hash = "sha256-qqgk6vB/YZEdIrdf8JCkA8PdC9c+I5M+C7qLWXFDbOE="; }; postPatch = '' @@ -35,6 +37,8 @@ stdenv.mkDerivation rec { flex bison bc + cpio + perl python3 python3.pkgs.pyelftools ]; @@ -49,13 +53,16 @@ stdenv.mkDerivation rec { "SEV=1" ]; + # Fixes https://github.com/containers/libkrunfw/issues/55 + NIX_CFLAGS_COMPILE = lib.optionalString stdenv.targetPlatform.isAarch64 "-march=armv8-a+crypto"; + enableParallelBuilding = true; meta = with lib; { description = "Dynamic library bundling the guest payload consumed by libkrun"; homepage = "https://github.com/containers/libkrunfw"; license = with licenses; [ lgpl2Only lgpl21Only ]; - maintainers = with maintainers; [ nickcao ]; - platforms = [ "x86_64-linux" ]; + maintainers = with maintainers; [ nickcao RossComputerGuy ]; + platforms = [ "x86_64-linux" "aarch64-linux" ]; }; -} +}) From 0d44d96f5b9b838358fbdead146ddee8d551c858 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 20 Jun 2024 15:40:14 -0700 Subject: [PATCH 2/3] libkrun: 1.9.2 -> 1.9.3, add more options --- .../development/libraries/libkrun/default.nix | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/pkgs/development/libraries/libkrun/default.nix b/pkgs/development/libraries/libkrun/default.nix index de0e20d93ff2..30730d38a6f7 100644 --- a/pkgs/development/libraries/libkrun/default.nix +++ b/pkgs/development/libraries/libkrun/default.nix @@ -6,54 +6,72 @@ , pkg-config , glibc , openssl +, libepoxy +, libdrm +, pipewire +, virglrenderer , libkrunfw +, llvmPackages , rustc +, withGpu ? false +, withSound ? false +, withNet ? false , sevVariant ? false }: -stdenv.mkDerivation rec { +stdenv.mkDerivation (finalAttrs: { pname = "libkrun"; version = "1.9.3"; src = fetchFromGitHub { owner = "containers"; repo = "libkrun"; - rev = "refs/tags/v${version}"; + rev = "refs/tags/v${finalAttrs.version}"; hash = "sha256-LIp2/794gbHPweBJcHCjbF0m+bJAs0SPF7WivW7fxLI="; }; + outputs = [ "out" "dev" ]; + cargoDeps = rustPlatform.fetchCargoTarball { - inherit pname version src; + inherit (finalAttrs) pname version src; hash = "sha256-g4ceYi16mjEgvWTAQEW8ShT/e5IKnlgLgk49Mg0N2fQ="; }; nativeBuildInputs = [ + llvmPackages.clang rustPlatform.cargoSetupHook cargo rustc - ] ++ lib.optionals sevVariant [ - pkg-config - ]; + ] ++ lib.optional (sevVariant || withGpu) pkg-config; buildInputs = [ (libkrunfw.override { inherit sevVariant; }) glibc glibc.static - ] ++ lib.optionals sevVariant [ - openssl - ]; + ] ++ lib.optionals withGpu [ libepoxy libdrm virglrenderer ] + ++ lib.optional withSound pipewire + ++ lib.optional sevVariant openssl; + + env.LIBCLANG_PATH = "${llvmPackages.clang-unwrapped.lib}/lib/libclang.so"; makeFlags = [ "PREFIX=${placeholder "out"}" - ] ++ lib.optionals sevVariant [ - "SEV=1" - ]; + ] ++ lib.optional withGpu "GPU=1" + ++ lib.optional withSound "SND=1" + ++ lib.optional withNet "NET=1" + ++ lib.optional sevVariant "SEV=1"; + + postInstall = '' + mkdir -p $dev/lib/pkgconfig + mv $out/lib64/pkgconfig $dev/lib/pkgconfig + mv $out/include $dev/include + ''; meta = with lib; { description = "Dynamic library providing Virtualization-based process isolation capabilities"; homepage = "https://github.com/containers/libkrun"; license = licenses.asl20; - maintainers = with maintainers; [ nickcao ]; + maintainers = with maintainers; [ nickcao RossComputerGuy ]; platforms = libkrunfw.meta.platforms; }; -} +}) From ab4247be8c8dd04b8bd49057e0fdd64a95f8937c Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 20 Jun 2024 15:40:41 -0700 Subject: [PATCH 3/3] krun: init at 0-unstable-2024-06-18 --- pkgs/by-name/kr/krun/package.nix | 70 ++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 pkgs/by-name/kr/krun/package.nix diff --git a/pkgs/by-name/kr/krun/package.nix b/pkgs/by-name/kr/krun/package.nix new file mode 100644 index 000000000000..d851203a30fd --- /dev/null +++ b/pkgs/by-name/kr/krun/package.nix @@ -0,0 +1,70 @@ +{ lib +, stdenv +, fetchFromGitHub +, fetchpatch +, rustPlatform +, libiconv +, libkrun +, makeWrapper +, passt +, sommelier +, mesa +, opengl-driver ? mesa.drivers +, withSommelier ? false +}: + +rustPlatform.buildRustPackage rec { + pname = "krun"; + version = "0-unstable-2024-06-18"; + + src = fetchFromGitHub { + owner = "slp"; + repo = pname; + rev = "912afa5c6525b7c8f83dffd65ec4b1425b3f7521"; + hash = "sha256-rDuxv3UakAemDnj4Nsbpqsykts2IcseuQmDwO24L+u8="; + }; + + patches = [ + (fetchpatch { + url = "https://github.com/slp/krun/pull/39.diff"; + hash = "sha256-CV69L+VDDLRcWgpgDCAYKLlTU9ytFcHhzNgOibWD8KY="; + }) + (fetchpatch { + url = "https://github.com/slp/krun/pull/38.diff"; + hash = "sha256-cK3iDhh+33H16V65lWUXahjmpSxI1HhiLUmkjfkRB7A="; + }) + ]; + + cargoHash = "sha256-NahnigxJaY2QwWnySCRrnf3JyqZ+7jRA1CpE7ON0OOE="; + + nativeBuildInputs = [ + rustPlatform.bindgenHook + makeWrapper + ]; + + buildInputs = [ + (libkrun.override { + withGpu = true; + withNet = true; + }) + ]; + + # Allow for sommelier to be disabled as it can cause problems. + wrapArgs = [ + "--prefix PATH : ${lib.makeBinPath (lib.optional withSommelier [ sommelier ] ++ [ passt ])}" + ]; + + postFixup = '' + wrapProgram $out/bin/krun $wrapArgs \ + --set-default OPENGL_DRIVER ${opengl-driver} + ''; + + meta = { + description = "Run programs from your system in a microVM"; + homepage = "https://github.com/slp/krun"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ RossComputerGuy ]; + platforms = libkrun.meta.platforms; + mainProgram = "krun"; + }; +}