33 systemSeaBIOS ? seabios-qemu,
37 binutils-unwrapped-all-targets,
60 branch ? lib.versions.majorMinor version,
88 inherit (systems.inspect.patterns) isLinux isAarch64;
96 # Mark versions older than minSupportedVersion as EOL.
97 minSupportedVersion = "4.16";
99 #TODO: fix paths instead.
100 scriptEnvPath = makeSearchPathOutput "out" "bin" [
119 stdenv.mkDerivation (finalAttrs: {
120 inherit pname version patches;
131 url = "https://xenbits.xenproject.org/git-http/xen.git";
135 nativeBuildInputs = [
142 python3Packages.setuptools
155 python3Packages.python
162 ocamlPackages.findlib
166 python3Packages.wrapPython
167 ] ++ optional withFlask checkpolicy ++ optional (versionOlder version "4.19") systemdMinimal;
171 "--disable-qemu-traditional"
173 (if withSeaBIOS then "--with-system-seabios=${systemSeaBIOS.firmware}" else "--disable-seabios")
174 (if withOVMF then "--with-system-ovmf=${OVMF.firmware}" else "--disable-ovmf")
175 (if withIPXE then "--with-system-ipxe=${ipxe.firmware}" else "--disable-ipxe")
176 (enableFeature withFlask "xsmpolicy")
181 "SUBSYSTEMS=${toString finalAttrs.buildFlags}"
184 "BASH_COMPLETION_DIR=$(PREFIX)/share/bash-completion/completions"
186 "XEN_WHOAMI=${pname}"
187 "XEN_DOMAIN=${vendor}"
189 "GIT=${coreutils}/bin/false"
190 "WGET=${coreutils}/bin/false"
191 "EFI_VENDOR=${vendor}"
192 "INSTALL_EFI_STRIP=1"
193 "LD=${getExe' binutils-unwrapped-all-targets "ld"}"
195 # These flags set the CONFIG_* options in /boot/xen.config
196 # and define if the default policy file is built. However,
197 # the Flask binaries always get compiled by default.
198 ++ optionals withFlask [
209 enableParallelBuilding = true;
211 env.NIX_CFLAGS_COMPILE = toString [
212 "-Wno-error=maybe-uninitialized"
213 "-Wno-error=array-bounds"
216 dontUseCmakeConfigure = true;
218 # Remove in-tree QEMU sources, we don't need them in any circumstance.
219 prePatch = "rm --recursive --force tools/qemu-xen tools/qemu-xen-traditional";
222 # The following patch forces Xen to install xen.efi on $out/boot
223 # instead of $out/boot/efi/efi/nixos, as the latter directory
224 # would otherwise need to be created manually. This also creates
225 # a more consistent output for downstreams who override the
226 # vendor attribute above.
228 substituteInPlace xen/Makefile \
229 --replace-fail "\$(D)\$(EFI_MOUNTPOINT)/efi/\$(EFI_VENDOR)/\$(T)-\$(XEN_FULLVERSION).efi" \
230 "\$(D)\$(BOOT_DIR)/\$(T)-\$(XEN_FULLVERSION).efi"
233 # The following patch fixes the call to /bin/mkdir on the
234 # launch_xenstore.sh helper script.
236 substituteInPlace tools/hotplug/Linux/launch-xenstore.in \
237 --replace-fail "/bin/mkdir" "${coreutils}/bin/mkdir"
240 # The following expression fixes the paths called by Xen's systemd
241 # units, so we can use them in the NixOS module.
244 tools/hotplug/Linux/systemd/{xen-init-dom0,xen-qemu-dom0-disk-backend,xenconsoled,xendomains,xenstored}.service.in \
245 --replace-fail /bin/grep ${gnugrep}/bin/grep
247 tools/hotplug/Linux/systemd/{xen-qemu-dom0-disk-backend,xenconsoled}.service.in \
248 --replace-fail "/bin/mkdir" "${coreutils}/bin/mkdir"
254 mkdir --parents $out $out/share $boot
255 cp -prvd dist/install/nix/store/*/* $out/
256 cp -prvd dist/install/etc $out
257 cp -prvd dist/install/boot $boot
263 # Wrap xencov_split, xenmon and xentrace_format.
268 # We also need to wrap pygrub, which lies in $out/libexec/xen/bin.
270 wrapPythonProgramsIn "$out/libexec/xen/bin" "$out $pythonPath"
273 # Fix shebangs in Xen's various scripts.
274 #TODO: Remove any and all usage of `sed` and replace these complicated magic runes with readable code.
277 for i in $out/etc/xen/scripts/!(*.sh); do
278 sed --in-place "2s@^@export PATH=$out/bin:${scriptEnvPath}\n@" $i
284 addAutoPatchelfSearchPath $out/lib
285 autoPatchelf $out/libexec/xen/bin
287 # Flask is particularly hard to disable. Even after
288 # setting the make flags to `n`, it still gets compiled.
289 # If withFlask is disabled, delete the extra binaries.
290 + optionalString (!withFlask) ''
291 rm -f $out/bin/flask-*
295 efi = "boot/xen-${upstreamVersion}.efi";
298 warn "This Xen was compiled with FLASK support, but the FLASK file does not match the Xen version number. Please hardcode the path to the FLASK file instead." "boot/xenpolicy-${version}"
300 throw "This Xen was compiled without FLASK support.";
301 # This test suite is very simple, as Xen's userspace
302 # utilities require the hypervisor to be booted.
304 pkg-config = testers.hasPkgConfigModules {
305 package = finalAttrs.finalPackage;
330 description = "Type-1 hypervisor intended for embedded and hyperscale use cases";
333 The Xen Project Hypervisor is a virtualisation technology defined as a *type-1
334 hypervisor*, which allows multiple virtual machines, known as domains, to run
335 concurrently with the host on the physical machine. On a typical *type-2
336 hypervisor*, the virtual machines run as applications on top of the
337 host. NixOS runs as the privileged **Domain 0**, and can paravirtualise or fully
338 virtualise **Unprivileged Domains**.
340 Use with the `qemu_xen` package.
342 + "\nIncludes:\n* `xen.efi`: The Xen Project's [EFI binary](https://xenbits.xenproject.org/docs/${branch}-testing/misc/efi.html), available on the `boot` output of this package."
343 + optionalString withFlask "\n* `xsm-flask`: The [FLASK Xen Security Module](https://wiki.xenproject.org/wiki/Xen_Security_Modules_:_XSM-FLASK). The `xenpolicy-${upstreamVersion}` file is available on the `boot` output of this package."
344 + optionalString withSeaBIOS "\n* `seabios`: Support for the SeaBIOS boot firmware on HVM domains."
345 + optionalString withOVMF "\n* `ovmf`: Support for the OVMF UEFI boot firmware on HVM domains."
346 + optionalString withIPXE "\n* `ipxe`: Support for the iPXE boot firmware on HVM domains.";
348 homepage = "https://xenproject.org/";
349 downloadPage = "https://downloads.xenproject.org/release/xen/${version}/";
350 changelog = "https://wiki.xenproject.org/wiki/Xen_Project_${branch}_Release_Notes";
355 # Most of Xen is licensed under the GPL v2.0.
357 # Xen Libraries and the `xl` command-line utility.
359 # Development headers in $dev/include.
363 maintainers = teams.xen.members;
364 knownVulnerabilities = optional (versionOlder version minSupportedVersion) "The Xen Project Hypervisor version ${version} is no longer supported by the Xen Project Security Team. See https://xenbits.xenproject.org/docs/unstable/support-matrix.html";
368 platforms = [ isLinux ];
369 badPlatforms = [ isAarch64 ];