biglybt: 3.5.0.0 -> 3.6.0.0
[NixPkgs.git] / pkgs / applications / virtualization / qemu / default.nix
blobe7da99d561f6b41c2456b43c0d4a1d7a529d420b
1 { lib, stdenv, fetchurl, fetchpatch, python3Packages, zlib, pkg-config, glib, buildPackages
2 , pixman, vde2, alsa-lib, texinfo, flex
3 , bison, lzo, snappy, libaio, libtasn1, gnutls, nettle, curl, dtc, ninja, meson
4 , sigtool
5 , makeWrapper, removeReferencesTo
6 , attr, libcap, libcap_ng, socat, libslirp
7 , CoreServices, Cocoa, Hypervisor, rez, setfile, vmnet
8 , guestAgentSupport ? (with stdenv.hostPlatform; isLinux || isNetBSD || isOpenBSD || isSunOS || isWindows) && !toolsOnly
9 , numaSupport ? stdenv.isLinux && !stdenv.isAarch32 && !toolsOnly, numactl
10 , seccompSupport ? stdenv.isLinux && !toolsOnly, libseccomp
11 , alsaSupport ? lib.hasSuffix "linux" stdenv.hostPlatform.system && !nixosTestRunner && !toolsOnly
12 , pulseSupport ? !stdenv.isDarwin && !nixosTestRunner && !toolsOnly, libpulseaudio
13 , pipewireSupport ? !stdenv.isDarwin && !nixosTestRunner && !toolsOnly, pipewire
14 , sdlSupport ? !stdenv.isDarwin && !nixosTestRunner && !toolsOnly, SDL2, SDL2_image
15 , jackSupport ? !stdenv.isDarwin && !nixosTestRunner && !toolsOnly, libjack2
16 , gtkSupport ? !stdenv.isDarwin && !xenSupport && !nixosTestRunner && !toolsOnly, gtk3, gettext, vte, wrapGAppsHook
17 , vncSupport ? !nixosTestRunner && !toolsOnly, libjpeg, libpng
18 , smartcardSupport ? !nixosTestRunner && !toolsOnly, libcacard
19 , spiceSupport ? true && !nixosTestRunner && !toolsOnly, spice, spice-protocol
20 , ncursesSupport ? !nixosTestRunner && !toolsOnly, ncurses
21 , usbredirSupport ? spiceSupport, usbredir
22 , xenSupport ? false, xen
23 , cephSupport ? false, ceph
24 , glusterfsSupport ? false, glusterfs, libuuid
25 , openGLSupport ? sdlSupport, mesa, libepoxy, libdrm
26 , rutabagaSupport ? openGLSupport && !toolsOnly && lib.meta.availableOn stdenv.hostPlatform rutabaga_gfx, rutabaga_gfx
27 , virglSupport ? openGLSupport, virglrenderer
28 , libiscsiSupport ? !toolsOnly, libiscsi
29 , smbdSupport ? false, samba
30 , tpmSupport ? !toolsOnly
31 , uringSupport ? stdenv.isLinux, liburing
32 , canokeySupport ? false, canokey-qemu
33 , capstoneSupport ? !toolsOnly, capstone
34 , enableDocs ? true
35 , hostCpuOnly ? false
36 , hostCpuTargets ? (if toolsOnly
37                     then [ ]
38                     else if hostCpuOnly
39                     then (lib.optional stdenv.isx86_64 "i386-softmmu"
40                           ++ ["${stdenv.hostPlatform.qemuArch}-softmmu"])
41                     else null)
42 , nixosTestRunner ? false
43 , toolsOnly ? false
44 , gitUpdater
45 , qemu-utils # for tests attribute
48 let
49   hexagonSupport = hostCpuTargets == null || lib.elem "hexagon" hostCpuTargets;
52 stdenv.mkDerivation (finalAttrs: {
53   pname = "qemu"
54     + lib.optionalString xenSupport "-xen"
55     + lib.optionalString hostCpuOnly "-host-cpu-only"
56     + lib.optionalString nixosTestRunner "-for-vm-tests"
57     + lib.optionalString toolsOnly "-utils";
58   version = "8.2.2";
60   src = fetchurl {
61     url = "https://download.qemu.org/qemu-${finalAttrs.version}.tar.xz";
62     hash = "sha256-hHNGwbgsGlSyw49u29hVSe3rF0MLfU09oSYg4pYrxPM=";
63   };
65   depsBuildBuild = [ buildPackages.stdenv.cc ]
66     ++ lib.optionals hexagonSupport [ pkg-config ];
68   nativeBuildInputs = [
69     makeWrapper removeReferencesTo
70     pkg-config flex bison dtc meson ninja
72     # Don't change this to python3 and python3.pkgs.*, breaks cross-compilation
73     python3Packages.python python3Packages.sphinx python3Packages.sphinx-rtd-theme
74   ]
75     ++ lib.optionals gtkSupport [ wrapGAppsHook ]
76     ++ lib.optionals hexagonSupport [ glib ]
77     ++ lib.optionals stdenv.isDarwin [ sigtool ];
79   buildInputs = [ zlib glib pixman
80     vde2 texinfo lzo snappy libtasn1
81     gnutls nettle curl libslirp
82   ]
83     ++ lib.optionals ncursesSupport [ ncurses ]
84     ++ lib.optionals stdenv.isDarwin [ CoreServices Cocoa Hypervisor rez setfile vmnet ]
85     ++ lib.optionals seccompSupport [ libseccomp ]
86     ++ lib.optionals numaSupport [ numactl ]
87     ++ lib.optionals alsaSupport [ alsa-lib ]
88     ++ lib.optionals pulseSupport [ libpulseaudio ]
89     ++ lib.optionals pipewireSupport [ pipewire ]
90     ++ lib.optionals sdlSupport [ SDL2 SDL2_image ]
91     ++ lib.optionals jackSupport [ libjack2 ]
92     ++ lib.optionals gtkSupport [ gtk3 gettext vte ]
93     ++ lib.optionals vncSupport [ libjpeg libpng ]
94     ++ lib.optionals smartcardSupport [ libcacard ]
95     ++ lib.optionals spiceSupport [ spice-protocol spice ]
96     ++ lib.optionals usbredirSupport [ usbredir ]
97     ++ lib.optionals stdenv.isLinux [ libaio libcap_ng libcap attr ]
98     ++ lib.optionals xenSupport [ xen ]
99     ++ lib.optionals cephSupport [ ceph ]
100     ++ lib.optionals glusterfsSupport [ glusterfs libuuid ]
101     ++ lib.optionals openGLSupport [ mesa libepoxy libdrm ]
102     ++ lib.optionals rutabagaSupport [ rutabaga_gfx ]
103     ++ lib.optionals virglSupport [ virglrenderer ]
104     ++ lib.optionals libiscsiSupport [ libiscsi ]
105     ++ lib.optionals smbdSupport [ samba ]
106     ++ lib.optionals uringSupport [ liburing ]
107     ++ lib.optionals canokeySupport [ canokey-qemu ]
108     ++ lib.optionals capstoneSupport [ capstone ];
110   dontUseMesonConfigure = true; # meson's configurePhase isn't compatible with qemu build
112   outputs = [ "out" ] ++ lib.optional guestAgentSupport "ga";
113   # On aarch64-linux we would shoot over the Hydra's 2G output limit.
114   separateDebugInfo = !(stdenv.isAarch64 && stdenv.isLinux);
116   patches = [
117     ./fix-qemu-ga.patch
119     # QEMU upstream does not demand compatibility to pre-10.13, so 9p-darwin
120     # support on nix requires utimensat fallback. The patch adding this fallback
121     # set was removed during the process of upstreaming this functionality, and
122     # will still be needed in nix until the macOS SDK reaches 10.13+.
123     ./provide-fallback-for-utimensat.patch
124     # Cocoa clipboard support only works on macOS 10.14+
125     ./revert-ui-cocoa-add-clipboard-support.patch
126     # Standard about panel requires AppKit and macOS 10.13+
127     (fetchpatch {
128       url = "https://gitlab.com/qemu-project/qemu/-/commit/99eb313ddbbcf73c1adcdadceba1423b691c6d05.diff";
129       sha256 = "sha256-gTRf9XENAfbFB3asYCXnw4OV4Af6VE1W56K2xpYDhgM=";
130       revert = true;
131     })
132     # Workaround for upstream issue with nested virtualisation: https://gitlab.com/qemu-project/qemu/-/issues/1008
133     (fetchpatch {
134       url = "https://gitlab.com/qemu-project/qemu/-/commit/3e4546d5bd38a1e98d4bd2de48631abf0398a3a2.diff";
135       sha256 = "sha256-oC+bRjEHixv1QEFO9XAm4HHOwoiT+NkhknKGPydnZ5E=";
136       revert = true;
137     })
138   ]
139   ++ lib.optional nixosTestRunner ./force-uid0-on-9p.patch;
141   postPatch = ''
142     # Otherwise tries to ensure /var/run exists.
143     sed -i "/install_emptydir(get_option('localstatedir') \/ 'run')/d" \
144         qga/meson.build
145   '';
147   preConfigure = ''
148     unset CPP # intereferes with dependency calculation
149     # this script isn't marked as executable b/c it's indirectly used by meson. Needed to patch its shebang
150     chmod +x ./scripts/shaderinclude.py
151     patchShebangs .
152     # avoid conflicts with libc++ include for <version>
153     mv VERSION QEMU_VERSION
154     substituteInPlace configure \
155       --replace '$source_path/VERSION' '$source_path/QEMU_VERSION'
156     substituteInPlace meson.build \
157       --replace "'VERSION'" "'QEMU_VERSION'"
158   '';
160   configureFlags = [
161     "--disable-strip" # We'll strip ourselves after separating debug info.
162     (lib.enableFeature enableDocs "docs")
163     "--enable-tools"
164     "--localstatedir=/var"
165     "--sysconfdir=/etc"
166     "--cross-prefix=${stdenv.cc.targetPrefix}"
167     (lib.enableFeature guestAgentSupport "guest-agent")
168   ] ++ lib.optional numaSupport "--enable-numa"
169     ++ lib.optional seccompSupport "--enable-seccomp"
170     ++ lib.optional smartcardSupport "--enable-smartcard"
171     ++ lib.optional spiceSupport "--enable-spice"
172     ++ lib.optional usbredirSupport "--enable-usb-redir"
173     ++ lib.optional (hostCpuTargets != null) "--target-list=${lib.concatStringsSep "," hostCpuTargets}"
174     ++ lib.optionals stdenv.isDarwin [ "--enable-cocoa" "--enable-hvf" ]
175     ++ lib.optional stdenv.isLinux "--enable-linux-aio"
176     ++ lib.optional gtkSupport "--enable-gtk"
177     ++ lib.optional xenSupport "--enable-xen"
178     ++ lib.optional cephSupport "--enable-rbd"
179     ++ lib.optional glusterfsSupport "--enable-glusterfs"
180     ++ lib.optional openGLSupport "--enable-opengl"
181     ++ lib.optional virglSupport "--enable-virglrenderer"
182     ++ lib.optional tpmSupport "--enable-tpm"
183     ++ lib.optional libiscsiSupport "--enable-libiscsi"
184     ++ lib.optional smbdSupport "--smbd=${samba}/bin/smbd"
185     ++ lib.optional uringSupport "--enable-linux-io-uring"
186     ++ lib.optional canokeySupport "--enable-canokey"
187     ++ lib.optional capstoneSupport "--enable-capstone";
189   dontWrapGApps = true;
191   # QEMU attaches entitlements with codesign and strip removes those,
192   # voiding the entitlements and making it non-operational.
193   # The alternative is to re-sign with entitlements after stripping:
194   # * https://github.com/qemu/qemu/blob/v6.1.0/scripts/entitlement.sh#L25
195   dontStrip = stdenv.isDarwin;
197   postFixup = ''
198     # the .desktop is both invalid and pointless
199     rm -f $out/share/applications/qemu.desktop
200   '' + lib.optionalString guestAgentSupport ''
201     # move qemu-ga (guest agent) to separate output
202     mkdir -p $ga/bin
203     mv $out/bin/qemu-ga $ga/bin/
204     ln -s $ga/bin/qemu-ga $out/bin
205     remove-references-to -t $out $ga/bin/qemu-ga
206   '' + lib.optionalString gtkSupport ''
207     # wrap GTK Binaries
208     for f in $out/bin/qemu-system-*; do
209       wrapGApp $f
210     done
211   '';
212   preBuild = "cd build";
214   # tests can still timeout on slower systems
215   doCheck = false;
216   nativeCheckInputs = [ socat ];
217   preCheck = ''
218     # time limits are a little meagre for a build machine that's
219     # potentially under load.
220     substituteInPlace ../tests/unit/meson.build \
221       --replace 'timeout: slow_tests' 'timeout: 50 * slow_tests'
222     substituteInPlace ../tests/qtest/meson.build \
223       --replace 'timeout: slow_qtests' 'timeout: 50 * slow_qtests'
224     substituteInPlace ../tests/fp/meson.build \
225       --replace 'timeout: 90)' 'timeout: 300)'
227     # point tests towards correct binaries
228     substituteInPlace ../tests/unit/test-qga.c \
229       --replace '/bin/bash' "$(type -P bash)" \
230       --replace '/bin/echo' "$(type -P echo)"
231     substituteInPlace ../tests/unit/test-io-channel-command.c \
232       --replace '/bin/socat' "$(type -P socat)"
234     # combined with a long package name, some temp socket paths
235     # can end up exceeding max socket name len
236     substituteInPlace ../tests/qtest/bios-tables-test.c \
237       --replace 'qemu-test_acpi_%s_tcg_%s' '%s_%s'
239     # get-fsinfo attempts to access block devices, disallowed by sandbox
240     sed -i -e '/\/qga\/get-fsinfo/d' -e '/\/qga\/blacklist/d' \
241       ../tests/unit/test-qga.c
242   '' + lib.optionalString stdenv.isDarwin ''
243     # skip test that stalls on darwin, perhaps due to subtle differences
244     # in fifo behaviour
245     substituteInPlace ../tests/unit/meson.build \
246       --replace "'test-io-channel-command'" "#'test-io-channel-command'"
247   '';
249   # Add a ‘qemu-kvm’ wrapper for compatibility/convenience.
250   postInstall = lib.optionalString (!toolsOnly) ''
251     ln -s $out/bin/qemu-system-${stdenv.hostPlatform.qemuArch} $out/bin/qemu-kvm
252   '';
254   passthru = {
255     qemu-system-i386 = "bin/qemu-system-i386";
256     tests = lib.optionalAttrs (!toolsOnly) {
257       qemu-tests = finalAttrs.finalPackage.overrideAttrs (_: { doCheck = true; });
258       qemu-utils-builds = qemu-utils;
259     };
260     updateScript = gitUpdater {
261       # No nicer place to find latest release.
262       url = "https://gitlab.com/qemu-project/qemu.git";
263       rev-prefix = "v";
264       ignoredVersions = "(alpha|beta|rc).*";
265     };
266   };
268   # Builds in ~3h with 2 cores, and ~20m with a big-parallel builder.
269   requiredSystemFeatures = [ "big-parallel" ];
271   meta = with lib; {
272     homepage = "https://www.qemu.org/";
273     description = "A generic and open source machine emulator and virtualizer";
274     license = licenses.gpl2Plus;
275     maintainers = with maintainers; [ eelco qyliss ];
276     platforms = platforms.unix;
277   }
278   # toolsOnly: Does not have qemu-kvm and there's no main support tool
279   // lib.optionalAttrs (!toolsOnly) {
280     mainProgram = "qemu-kvm";
281   };