-
-
Notifications
You must be signed in to change notification settings - Fork 18k
nixos/binfmt: Add support for using statically-linked QEMU #160802
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
Changes from all commits
b9dd79b
33ef59b
f8b7781
b429fd2
8287b57
ca5b9dc
472b1d4
1a95845
07d3563
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| diff --git a/meson.build b/meson.build | ||
| index 96de1a6ef9..908d841f6a 100644 | ||
| --- a/meson.build | ||
| +++ b/meson.build | ||
| @@ -420,8 +420,7 @@ zlib = dependency('zlib', required: true, kwargs: static_kwargs) | ||
| libaio = not_found | ||
| if not get_option('linux_aio').auto() or have_block | ||
| libaio = cc.find_library('aio', has_headers: ['libaio.h'], | ||
| - required: get_option('linux_aio'), | ||
| - kwargs: static_kwargs) | ||
| + required: get_option('linux_aio')) | ||
| endif | ||
| linux_io_uring = not_found | ||
| if not get_option('linux_io_uring').auto() or have_block |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,10 @@ | |
| , uringSupport ? stdenv.isLinux, liburing | ||
| , canokeySupport ? false, canokey-qemu | ||
| , capstoneSupport ? true, capstone | ||
| , pluginsSupport ? !stdenv.hostPlatform.isStatic | ||
| , enableDocs ? true | ||
| , enableTools ? true | ||
| , enableBlobs ? true | ||
| , hostCpuOnly ? false | ||
| , hostCpuTargets ? (if hostCpuOnly | ||
| then (lib.optional stdenv.isx86_64 "i386-softmmu" | ||
|
|
@@ -63,8 +66,9 @@ stdenv.mkDerivation rec { | |
| pkg-config flex bison meson ninja | ||
|
|
||
| # Don't change this to python3 and python3.pkgs.*, breaks cross-compilation | ||
| python3Packages.python python3Packages.sphinx python3Packages.sphinx-rtd-theme | ||
| python3Packages.python | ||
| ] | ||
| ++ lib.optionals enableDocs [ python3Packages.sphinx python3Packages.sphinx-rtd-theme ] | ||
| ++ lib.optionals gtkSupport [ wrapGAppsHook ] | ||
| ++ lib.optionals hexagonSupport [ glib ] | ||
| ++ lib.optionals stdenv.isDarwin [ sigtool ]; | ||
|
|
@@ -99,6 +103,7 @@ stdenv.mkDerivation rec { | |
| ++ lib.optionals capstoneSupport [ capstone ]; | ||
|
|
||
| dontUseMesonConfigure = true; # meson's configurePhase isn't compatible with qemu build | ||
| dontAddStaticConfigureFlags = true; | ||
|
|
||
| outputs = [ "out" ] ++ lib.optional guestAgentSupport "ga"; | ||
| # On aarch64-linux we would shoot over the Hydra's 2G output limit. | ||
|
|
@@ -127,7 +132,10 @@ stdenv.mkDerivation rec { | |
| revert = true; | ||
| }) | ||
| ] | ||
| ++ lib.optional nixosTestRunner ./force-uid0-on-9p.patch; | ||
| ++ lib.optional nixosTestRunner ./force-uid0-on-9p.patch | ||
|
|
||
| # Remove for QEMU 8.1 | ||
| ++ lib.optional stdenv.hostPlatform.isStatic ./aio-find-static-library.patch; | ||
zhaofengli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| postPatch = '' | ||
| # Otherwise tries to ensure /var/run exists. | ||
|
|
@@ -151,7 +159,7 @@ stdenv.mkDerivation rec { | |
| configureFlags = [ | ||
| "--disable-strip" # We'll strip ourselves after separating debug info. | ||
| (lib.enableFeature enableDocs "docs") | ||
| "--enable-tools" | ||
| (lib.enableFeature enableTools "tools") | ||
| "--localstatedir=/var" | ||
| "--sysconfdir=/etc" | ||
| # Always use our Meson, not the bundled version, which doesn't | ||
|
|
@@ -178,7 +186,12 @@ stdenv.mkDerivation rec { | |
| ++ lib.optional smbdSupport "--smbd=${samba}/bin/smbd" | ||
| ++ lib.optional uringSupport "--enable-linux-io-uring" | ||
| ++ lib.optional canokeySupport "--enable-canokey" | ||
| ++ lib.optional capstoneSupport "--enable-capstone"; | ||
| ++ lib.optional capstoneSupport "--enable-capstone" | ||
| ++ lib.optional (!pluginsSupport) "--disable-plugins" | ||
| ++ lib.optional (!enableBlobs) "--disable-install-blobs" | ||
|
|
||
| # FIXME: "multiple definition of `strtoll'" with libnbcompat | ||
| ++ lib.optional stdenv.hostPlatform.isStatic "--static --extra-ldflags=-Wl,--allow-multiple-definition"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice if we could figure out why this is happening. One definition is from libnbcompat — where's the other from?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems to be a conflict between libnbcompat and musl: Also it appears that there are many more build dependencies that we can remove. I'll play around and see how much further we can reduce the input closure.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I wonder why we don't see this on other packages. I'd like to take a look, but don't know when I'll have the capacity… |
||
|
|
||
| dontWrapGApps = true; | ||
|
|
||
|
|
@@ -241,7 +254,9 @@ stdenv.mkDerivation rec { | |
|
|
||
| # Add a ‘qemu-kvm’ wrapper for compatibility/convenience. | ||
| postInstall = '' | ||
| ln -s $out/bin/qemu-system-${stdenv.hostPlatform.qemuArch} $out/bin/qemu-kvm | ||
| if [ -f $out/bin/qemu-system-${stdenv.hostPlatform.qemuArch} ]; then | ||
| ln -s $out/bin/qemu-system-${stdenv.hostPlatform.qemuArch} $out/bin/qemu-kvm | ||
| fi | ||
| ''; | ||
|
|
||
| passthru = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| { lib, pkgsStatic }: | ||
|
|
||
| let | ||
| qemuUserPlatforms = [ | ||
| "aarch64-linux" | ||
| "armv7l-linux" | ||
| "i386-linux" | ||
| "powerpc-linux" | ||
| "powerpc64-linux" | ||
| "powerpc64le-linux" | ||
| "riscv32-linux" | ||
| "riscv64-linux" | ||
| "x86_64-linux" | ||
| ]; | ||
|
|
||
| qemuTargets = map (system: (lib.systems.elaborate { inherit system; }).qemuArch + "-linux-user") qemuUserPlatforms; | ||
alyssais marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| static = (pkgsStatic.qemu.override { | ||
| guestAgentSupport = false; | ||
| numaSupport = false; | ||
| seccompSupport = false; | ||
| alsaSupport = false; | ||
| pulseSupport = false; | ||
| sdlSupport = false; | ||
| jackSupport = false; | ||
| gtkSupport = false; | ||
| vncSupport = false; | ||
| smartcardSupport = false; | ||
| spiceSupport = false; | ||
| ncursesSupport = false; | ||
| libiscsiSupport = false; | ||
| smbdSupport = false; | ||
| tpmSupport = false; | ||
| uringSupport = false; | ||
| capstoneSupport = false; | ||
| enableDocs = false; | ||
| enableTools = false; | ||
| enableBlobs = false; | ||
| hostCpuTargets = qemuTargets; | ||
| }).overrideAttrs (old: { | ||
| # HACK: Otherwise the result will have the entire buildinput closure | ||
| # injected by the pkgsStatic stdenv | ||
| # <https://github.com/NixOS/nixpkgs/issues/83667> | ||
| postFixup = (old.postFixup or "") + '' | ||
| rm -f $out/nix-support/propagated-build-inputs | ||
| ''; | ||
| }); | ||
| in static // { | ||
| passthru = (static.passthru or {}) // { | ||
| inherit qemuUserPlatforms; | ||
| }; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason to check and return null, rather than just always returning qemu-user-static and letting the meta checks produce an error if its an unsupported platform?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to check whether the emulated platform is supported instead of the host platform. Could you elaborate on what the change would look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change would be to have
emulatorandstaticEmulatorhave a consistent interface. So likeemulator,staticEmulatorwould throw if unsupported, and there'd be astaticEmulatorAvailableto mirroremulatorAvailable. I just want to make sure we don't have two interfaces that work differently for such similar concepts.