Skip to content

Commit 16263fc

Browse files
muvm: init from krun as 0.4.1
Co-authored-by: Tristan Ross <[email protected]>
1 parent 4f4753e commit 16263fc

2 files changed

Lines changed: 110 additions & 70 deletions

File tree

pkgs/by-name/kr/krun/package.nix

Lines changed: 0 additions & 70 deletions
This file was deleted.

pkgs/by-name/mu/muvm/package.nix

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
lib,
3+
stdenv,
4+
fetchFromGitHub,
5+
rustPlatform,
6+
libkrun,
7+
passt,
8+
dhcpcd,
9+
systemd,
10+
udev,
11+
pkg-config,
12+
procps,
13+
fex,
14+
writeShellApplication,
15+
coreutils,
16+
makeBinaryWrapper,
17+
# TODO: Enable again when sommelier is not broken.
18+
# For now, don't give false impression of sommelier being supported.
19+
# sommelier,
20+
# withSommelier ? false,
21+
}:
22+
let
23+
# TODO: Setup setuid wrappers.
24+
# E.g. FEX needs fusermount for rootfs functionality
25+
initScript = writeShellApplication {
26+
name = "muvm-init";
27+
runtimeInputs = [
28+
coreutils
29+
];
30+
text = ''
31+
if [[ ! -f /etc/NIXOS ]]; then exit; fi
32+
33+
ln -s /run/muvm-host/run/current-system /run/current-system
34+
# Only create the symlink if that path exists on the host and is a directory.
35+
if [[ -d /run/muvm-host/run/opengl-driver ]]; then ln -s /run/muvm-host/run/opengl-driver /run/opengl-driver; fi
36+
'';
37+
};
38+
binPath = [
39+
dhcpcd
40+
passt
41+
(placeholder "out")
42+
] ++ lib.optionals stdenv.isAarch64 [ fex ];
43+
wrapArgs = lib.escapeShellArgs [
44+
"--prefix"
45+
"PATH"
46+
":"
47+
(lib.makeBinPath binPath)
48+
"--add-flags"
49+
"--execute-pre=${lib.getExe initScript}"
50+
];
51+
in
52+
rustPlatform.buildRustPackage rec {
53+
pname = "muvm";
54+
version = "0.4.1";
55+
56+
src = fetchFromGitHub {
57+
owner = "AsahiLinux";
58+
repo = pname;
59+
rev = "muvm-${version}";
60+
hash = "sha256-1XPhVEj7iqTxdWyYwNk6cbb9VRGuhpvvowYDPJb1cWU=";
61+
};
62+
63+
useFetchCargoVendor = true;
64+
cargoHash = "sha256-fkvdS0c1Ib8Kto44ou06leXy731cpMHXevyFR5RROt4=";
65+
66+
postPatch =
67+
''
68+
substituteInPlace crates/muvm/src/guest/bin/muvm-guest.rs \
69+
--replace-fail "/usr/lib/systemd/systemd-udevd" "${systemd}/lib/systemd/systemd-udevd"
70+
71+
substituteInPlace crates/muvm/src/monitor.rs \
72+
--replace-fail "/sbin/sysctl" "${lib.getExe' procps "sysctl"}"
73+
''
74+
# Only patch FEX path if we're aarch64, otherwise we don't want the derivation to pull in FEX in any way
75+
+ lib.optionalString stdenv.isAarch64 ''
76+
substituteInPlace crates/muvm/src/guest/mount.rs \
77+
--replace-fail "/usr/share/fex-emu" "${fex}/share/fex-emu"
78+
'';
79+
80+
nativeBuildInputs = [
81+
rustPlatform.bindgenHook
82+
makeBinaryWrapper
83+
pkg-config
84+
];
85+
86+
buildInputs = [
87+
(libkrun.override {
88+
withBlk = true;
89+
withGpu = true;
90+
withNet = true;
91+
})
92+
udev
93+
];
94+
95+
postFixup = ''
96+
wrapProgram $out/bin/muvm ${wrapArgs}
97+
'';
98+
99+
meta = {
100+
description = "Run programs from your system in a microVM";
101+
homepage = "https://github.com/AsahiLinux/muvm";
102+
license = lib.licenses.mit;
103+
maintainers = with lib.maintainers; [
104+
RossComputerGuy
105+
nrabulinski
106+
];
107+
inherit (libkrun.meta) platforms;
108+
mainProgram = "muvm";
109+
};
110+
}

0 commit comments

Comments
 (0)