diff --git a/pkgs/by-name/kr/krun/package.nix b/pkgs/by-name/kr/krun/package.nix new file mode 100644 index 0000000000000..d851203a30fde --- /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"; + }; +} diff --git a/pkgs/development/libraries/libkrun/default.nix b/pkgs/development/libraries/libkrun/default.nix index de0e20d93ff2c..30730d38a6f79 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; }; -} +}) diff --git a/pkgs/development/libraries/libkrunfw/default.nix b/pkgs/development/libraries/libkrunfw/default.nix index 0485c82ffb41e..21b8918d75ece 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" ]; }; -} +})