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

muvm: init from krun as 0.2.0 #347792

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 0 additions & 70 deletions pkgs/by-name/kr/krun/package.nix

This file was deleted.

2 changes: 2 additions & 0 deletions pkgs/by-name/li/libkrun/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
virglrenderer,
libkrunfw,
rustc,
withBlk ? false,
withGpu ? false,
withSound ? false,
withNet ? false,
Expand Down Expand Up @@ -65,6 +66,7 @@ stdenv.mkDerivation (finalAttrs: {
[
"PREFIX=${placeholder "out"}"
]
++ lib.optional withBlk "BLK=1"
++ lib.optional withGpu "GPU=1"
++ lib.optional withSound "SND=1"
++ lib.optional withNet "NET=1"
Expand Down
91 changes: 91 additions & 0 deletions pkgs/by-name/mu/muvm/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
lib,
stdenv,
fetchFromGitHub,
fetchpatch,
rustPlatform,
libkrun,
makeWrapper,
passt,
dhcpcd,
sommelier,
systemd,
udev,
pkg-config,
fex,
coreutils,
procps,
substituteAll,
withSommelier ? false,
}:

rustPlatform.buildRustPackage rec {
pname = "muvm";
version = "0.2.0";

src = fetchFromGitHub {
owner = "AsahiLinux";
repo = pname;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
repo = pname;
repo = "muvm";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change really necessary? pname is already muvm.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purely cosmetic now, but can be problematic in combination with finalAttrs in the future: #310373

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok but we're using buildRustPackage which doesn't support finalAttrs, is there plans to make buildRustPackage support finalAttrs or has that already happened?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It SHOULD happen I guess? Not aware of the progress though.

rev = "muvm-${version}";
hash = "sha256-eB60LjI1Qr85MPtQh0Fb5ihzBahz95tXaozNe8q6o3o=";
};

useFetchCargoVendor = true;
cargoHash = "sha256-B3klydX4xlop0pZUzMoxMjeRV7ZqWfKY+LhL+wFS4kM=";

postPatch = ''
substituteAll crates/muvm/src/guest/bin/muvm-guest.rs \
--replace-fail "/usr/lib/systemd/systemd-udevd" "${systemd}/lib/systemd/systemd-udevd"
'';

patches = [
(substituteAll {
src = ./paths.patch.in;
env = {
inherit procps coreutils fex;
};
})
];

nativeBuildInputs = [
rustPlatform.bindgenHook
makeWrapper
pkg-config
];

buildInputs = [
(libkrun.override {
withBlk = true;
withGpu = true;
withNet = true;
})
udev
];

# Allow for sommelier to be disabled as it can cause problems.
wrapArgs = [
"--prefix PATH : ${
lib.makeBinPath (
lib.optional withSommelier [ sommelier ]
++ [
dhcpcd
passt
(placeholder "out")
]
)
}"
];

postFixup = ''
wrapProgram $out/bin/muvm $wrapArgs
'';

meta = {
description = "Run programs from your system in a microVM";
homepage = "https://github.com/AsahiLinux/muvm";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ RossComputerGuy ];
platforms = libkrun.meta.platforms;
mainProgram = "muvm";
};
}
40 changes: 40 additions & 0 deletions pkgs/by-name/mu/muvm/paths.patch.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
diff --git a/crates/muvm/src/guest/mount.rs b/crates/muvm/src/guest/mount.rs
index 3126ca0..35472d6 100644
--- a/crates/muvm/src/guest/mount.rs
+++ b/crates/muvm/src/guest/mount.rs
@@ -84,7 +84,7 @@ fn mount_fex_rootfs() -> Result<()> {
// Now we need to tell FEX about this. One of the FEX share directories has an unmounted rootfs
// and a Config.json telling FEX to use FUSE. Neither should be visible to the guest. Instead,
// we want to replace the folders and tell FEX to use our mounted rootfs
- for base in ["/usr/share/fex-emu", "/usr/local/share/fex-emu"] {
+ for base in ["@fex@/share/fex-emu"] {
if Path::new(base).exists() {
let json = format!("{{\"Config\":{{\"RootFS\":\"{dir_rootfs}\"}}}}\n");
let path = base.to_string() + "/Config.json";
diff --git a/crates/muvm/src/monitor.rs b/crates/muvm/src/monitor.rs
index 7628d83..bc43a5c 100644
--- a/crates/muvm/src/monitor.rs
+++ b/crates/muvm/src/monitor.rs
@@ -50,7 +50,7 @@ fn set_guest_pressure(server_port: u32, cookie: Uuid, pressure: GuestPressure) -
let wsf: u32 = pressure.into();
debug!("setting watermark_scale_factor to {wsf}");

- let command = PathBuf::from("/sbin/sysctl");
+ let command = PathBuf::from("@procps@/bin/sysctl");
let command_args = vec![format!("vm.watermark_scale_factor={}", wsf)];
let env = HashMap::new();
request_launch(server_port, cookie, command, command_args, env, 0, false)
diff --git a/crates/muvm/src/server/bin/muvm-server.rs b/crates/muvm/src/server/bin/muvm-server.rs
index b538091..dae8895 100644
--- a/crates/muvm/src/server/bin/muvm-server.rs
+++ b/crates/muvm/src/server/bin/muvm-server.rs
@@ -36,7 +36,7 @@ async fn tokio_main(cookie: String) -> Result<()> {
};
(
server_port,
- PathBuf::from("/bin/sleep"),
+ PathBuf::from("@coreutils@/bin/sleep"),
vec!["inf".to_string()],
)
} else {