Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

krun: init at 0-unstable-2024-06-18 #321359

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions pkgs/by-name/kr/krun/package.nix
Original file line number Diff line number Diff line change
@@ -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";
Aleksanaa marked this conversation as resolved.
Show resolved Hide resolved
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";
};
}
46 changes: 32 additions & 14 deletions pkgs/development/libraries/libkrun/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
})
25 changes: 16 additions & 9 deletions pkgs/development/libraries/libkrunfw/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand All @@ -35,6 +37,8 @@ stdenv.mkDerivation rec {
flex
bison
bc
cpio
perl
python3
python3.pkgs.pyelftools
];
Expand All @@ -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" ];
};
}
})
Loading