spotlights-macbook-air: Initialize muvm

This commit is contained in:
Spotlight 2025-02-27 23:44:20 -06:00
parent 05a7847913
commit b428477394
Signed by: spotlight
GPG key ID: 874AA355B3209BDC
6 changed files with 248 additions and 2 deletions

View file

@ -0,0 +1,75 @@
{ lib
, fetchFromGitHub
, rustPlatform
, dhcpcd
, libkrun
, makeWrapper
, passt
, pkg-config
, mesa
, replaceVars
, systemd
, opengl-driver ? mesa.drivers
,
}:
rustPlatform.buildRustPackage rec {
pname = "muvm";
version = "0.3.1";
src = fetchFromGitHub {
owner = "AsahiLinux";
repo = pname;
rev = "muvm-${version}";
hash = "sha256-vacWhCiDwcRT1fNZ0oD2b1Ei2JiZSYEk3f6Mm/2jLmI=";
};
useFetchCargoVendor = true;
cargoHash = "sha256-E6p4xVdGF/ec91SE6B981IqhTQ0pNkqWozVYcY4a+tM=";
patches = [
(replaceVars ./replace-udevd.patch {
systemd-udevd = "${systemd}/lib/systemd/systemd-udevd";
})
./replace-sysctl.patch
./run-passthru.patch
];
nativeBuildInputs = [
rustPlatform.bindgenHook
makeWrapper
pkg-config
];
buildInputs = [
(libkrun.override {
withBlk = true;
withGpu = true;
withNet = true;
})
systemd
];
wrapArgs = [
"--prefix PATH : ${
lib.makeBinPath [
passt
dhcpcd
]
}"
];
postFixup = ''
wrapProgram $out/bin/muvm $wrapArgs \
--set-default OPENGL_DRIVER ${opengl-driver}
'';
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 = "krun";
};
}

View file

@ -0,0 +1,13 @@
diff --git a/crates/muvm/src/monitor.rs b/crates/muvm/src/monitor.rs
index 836acd5..a7cee1c 100644
--- a/crates/muvm/src/monitor.rs
+++ b/crates/muvm/src/monitor.rs
@@ -49,7 +49,7 @@ fn set_guest_pressure(pressure: GuestPressure) -> Result<()> {
let wsf: u32 = pressure.into();
debug!("setting watermark_scale_factor to {wsf}");
- let command = PathBuf::from("/sbin/sysctl");
+ let command = PathBuf::from("sysctl");
let command_args = vec![format!("vm.watermark_scale_factor={}", wsf)];
let env = HashMap::new();
request_launch(command, command_args, env, 0, false, true)

View file

@ -0,0 +1,11 @@
--- a/crates/muvm/src/guest/bin/muvm-guest.rs
+++ b/crates/muvm/src/guest/bin/muvm-guest.rs
@@ -50,7 +50,7 @@ fn main() -> Result<()> {
rustix::stdio::dup2_stdout(console.as_fd())?;
rustix::stdio::dup2_stderr(console.as_fd())?;
- Command::new("/usr/lib/systemd/systemd-udevd").spawn()?;
+ Command::new("@systemd-udevd@").spawn()?;
setup_fex()?;

View file

@ -0,0 +1,32 @@
diff --git a/crates/muvm/src/guest/mount.rs b/crates/muvm/src/guest/mount.rs
index 02c507d..232299b 100644
--- a/crates/muvm/src/guest/mount.rs
+++ b/crates/muvm/src/guest/mount.rs
@@ -14,6 +14,13 @@ use rustix::mount::{
use rustix::path::Arg;
use serde_json::json;
+/// A list of directories in /run to be passed through from the host.
+const RUN_PASSTHRU: [&str; 2] = [
+ // NixOS-specific directories.
+ "current-system",
+ "opengl-driver",
+];
+
fn make_tmpfs(dir: &str) -> Result<()> {
mount2(
Some("tmpfs"),
@@ -313,6 +320,13 @@ pub fn mount_filesystems(merged_rootfs: bool) -> Result<()> {
)
.context("Failed to mount `/dev/shm`")?;
+ for dir in RUN_PASSTHRU {
+ let src = Path::new("/run/muvm-host/run").join(dir);
+ if src.exists() {
+ symlink(src, Path::new("/run").join(dir))?;
+ }
+ }
+
// Do this last so it can pick up all the submounts made above.
if let Err(e) = mount_fex_rootfs(merged_rootfs) {
println!("Failed to mount FEX rootfs, carrying on without. Error: {e}");