···1{
2+ lib,
3+ stdenv,
4+ testers,
5+ fetchgit,
6+ fetchpatch,
7+ replaceVars,
8+9+ # Xen
10+ acpica-tools,
11+ autoPatchelfHook,
12+ binutils-unwrapped-all-targets,
13+ bison,
14+ bzip2,
15+ cmake,
16+ dev86,
17+ e2fsprogs,
18+ flex,
19+ libnl,
20+ libuuid,
21+ lzo,
22+ ncurses,
23+ ocamlPackages,
24+ perl,
25+ pkg-config,
26 python3Packages,
27+ systemd,
28+ xz,
29+ yajl,
30+ zlib,
31+ zstd,
32+33+ # Optional Components
34+ withFlask ? false,
35+ checkpolicy,
36+ withIPXE ? true,
37+ ipxe,
38+ withOVMF ? true,
39+ OVMF,
40+ withSeaBIOS ? true,
41+ seabios-qemu,
42+43+ # Documentation
44+ pandoc,
45+46+ # Scripts
47+ bridge-utils,
48+ coreutils,
49+ diffutils,
50+ drbd,
51+ gawk,
52+ gnugrep,
53+ gnused,
54+ inetutils,
55+ iproute2,
56+ iptables,
57+ kmod,
58+ multipath-tools,
59+ nbd,
60+ openiscsi,
61+ openvswitch,
62+ psmisc,
63+ util-linux,
64+ which,
65}:
6667+let
68+ inherit (lib)
69+ enableFeature
70+ genAttrs
71+ getExe
72+ getExe'
73+ licenses
74+ optionalString
75+ optionals
76+ systems
77+ teams
78+ versionOlder
79+ versions
80+ warn
81+ ;
82+ inherit (systems.inspect.patterns) isLinux isAarch64;
83+ inherit (licenses)
84+ cc-by-40
85+ gpl2Only
86+ lgpl21Only
87+ mit
88+ ;
89+90+ # Mark versions older than minSupportedVersion as EOL.
91+ minSupportedVersion = "4.17";
92+93+ scriptDeps =
94+ let
95+ mkTools = pkg: tools: genAttrs tools (tool: getExe' pkg tool);
96+ in
97+ (genAttrs [
98+ "CONFIG_DIR"
99+ "CONFIG_LEAF_DIR"
100+ "LIBEXEC_BIN"
101+ "XEN_LOG_DIR"
102+ "XEN_RUN_DIR"
103+ "XEN_SCRIPT_DIR"
104+ "qemu_xen_systemd"
105+ "sbindir"
106+ ] (_: null))
107+ // (mkTools coreutils [
108+ "basename"
109+ "cat"
110+ "cp"
111+ "cut"
112+ "dirname"
113+ "head"
114+ "ls"
115+ "mkdir"
116+ "mktemp"
117+ "readlink"
118+ "rm"
119+ "seq"
120+ "sleep"
121+ "stat"
122+ ])
123+ // (mkTools drbd [
124+ "drbdadm"
125+ "drbdsetup"
126+ ])
127+ // (mkTools gnugrep [
128+ "egrep"
129+ "grep"
130+ ])
131+ // (mkTools iproute2 [
132+ "bridge"
133+ "ip"
134+ "tc"
135+ ])
136+ // (mkTools iptables [
137+ "arptables"
138+ "ip6tables"
139+ "iptables"
140+ ])
141+ // (mkTools kmod [
142+ "modinfo"
143+ "modprobe"
144+ "rmmod"
145+ ])
146+ // (mkTools libnl [
147+ "nl-qdisc-add"
148+ "nl-qdisc-delete"
149+ "nl-qdisc-list"
150+ ])
151+ // (mkTools util-linux [
152+ "flock"
153+ "logger"
154+ "losetup"
155+ "prlimit"
156+ ])
157+ // {
158+ awk = getExe' gawk "awk";
159+ brctl = getExe bridge-utils;
160+ diff = getExe' diffutils "diff";
161+ ifconfig = getExe' inetutils "ifconfig";
162+ iscsiadm = getExe' openiscsi "iscsiadm";
163+ killall = getExe' psmisc "killall";
164+ multipath = getExe' multipath-tools "multipath";
165+ nbd-client = getExe' nbd "nbd-client";
166+ ovs-vsctl = getExe' openvswitch "ovs-vsctl";
167+ sed = getExe gnused;
168+ systemd-notify = getExe' systemd "systemd-notify";
169+ which = getExe which;
170+ };
171+in
172+173+stdenv.mkDerivation (finalAttrs: {
174 pname = "xen";
175 version = "4.20.0";
176+177+ # This attribute can be overriden to correct the file paths in
178+ # `passthru` when building an unstable Xen.
179+ upstreamVersion = finalAttrs.version;
180+ # Useful for further identifying downstream Xen variants. (i.e. Qubes)
181+ vendor = "nixos";
182+183 patches = [
184+ ./0001-makefile-efi-output-directory.patch
185+186+ (replaceVars ./0002-scripts-external-executable-calls.patch scriptDeps)
187+188+ # XSA #469
189 (fetchpatch {
190 url = "https://xenbits.xenproject.org/xsa/xsa469/xsa469-4.20-01.patch";
191 hash = "sha256-go743oBhYDuxsK0Xc6nK/WxutQQwc2ERtLKhCU9Dnng=";
···214 url = "https://xenbits.xenproject.org/xsa/xsa469/xsa469-4.20-07.patch";
215 hash = "sha256-+BsCJa01R2lrbu7tEluGrYSAqu2jJcrpFNUoLMY466c=";
216 })
217+218+ # XSA #470
219 (fetchpatch {
220 url = "https://xenbits.xenproject.org/xsa/xsa470.patch";
221 hash = "sha256-zhMZ6pCZtt0ocgsMFVqthMaof46lMMTaYmlepMXVJqM=";
222 })
223 ];
224+225+ outputs = [
226+ "out"
227+ "man"
228+ "doc"
229+ "dev"
230+ "boot"
231+ ];
232+233+ src = fetchgit {
234+ url = "https://xenbits.xenproject.org/git-http/xen.git";
235+ rev = "3ad5d648cda5add395f49fc3704b2552aae734f7";
236+ hash = "sha256-v2DRJv+1bym8zAgU74lo1HQ/9rUcyK3qc4Eec4RpcEY=";
237+ };
238+239+ strictDeps = true;
240+241+ nativeBuildInputs =
242+ [
243+ acpica-tools
244+ autoPatchelfHook
245+ bison
246+ cmake
247+ dev86
248+ flex
249+ pandoc
250+ perl
251+ pkg-config
252+253+ # oxenstored
254+ ocamlPackages.findlib
255+ ocamlPackages.ocaml
256+ ]
257+ ++ (with python3Packages; [
258+ python
259+ setuptools
260+ wrapPython
261+ ]);
262+263+ buildInputs =
264+ [
265+ bzip2
266+ e2fsprogs.dev
267+ libnl
268+ libuuid
269+ lzo
270+ ncurses
271+ xz
272+ yajl
273+ zlib
274+ zstd
275+ ]
276+ ++ optionals withFlask [ checkpolicy ]
277+ ++ optionals (versionOlder finalAttrs.version "4.19") [ systemd ];
278+279+ configureFlags = [
280+ "--enable-systemd"
281+ "--disable-qemu-traditional"
282+ "--with-system-qemu"
283+ (if withSeaBIOS then "--with-system-seabios=${seabios-qemu.firmware}" else "--disable-seabios")
284+ (if withOVMF then "--with-system-ovmf=${OVMF.mergedFirmware}" else "--disable-ovmf")
285+ (if withIPXE then "--with-system-ipxe=${ipxe.firmware}" else "--disable-ipxe")
286+ (enableFeature withFlask "xsmpolicy")
287+ ];
288+289+ makeFlags =
290+ [
291+ "SUBSYSTEMS=${toString finalAttrs.buildFlags}"
292+293+ "PREFIX=$(out)"
294+ "BASH_COMPLETION_DIR=$(PREFIX)/share/bash-completion/completions"
295+296+ "XEN_WHOAMI=${finalAttrs.pname}"
297+ "XEN_DOMAIN=${finalAttrs.vendor}"
298+299+ "GIT=${getExe' coreutils "false"}"
300+ "WGET=${getExe' coreutils "false"}"
301+ "EFI_VENDOR=${finalAttrs.vendor}"
302+ "INSTALL_EFI_STRIP=1"
303+ "LD=${getExe' binutils-unwrapped-all-targets "ld"}"
304+ ]
305+ # These flags set the CONFIG_* options in /boot/xen.config
306+ # and define if the default policy file is built. However,
307+ # the Flask binaries always get compiled by default.
308+ ++ optionals withFlask [
309+ "XSM_ENABLE=y"
310+ "FLASK_ENABLE=y"
311+ ];
312+313+ buildFlags = [
314+ "xen"
315+ "tools"
316+ "docs"
317+ ];
318+319+ enableParallelBuilding = true;
320+321+ env.NIX_CFLAGS_COMPILE = toString [
322+ "-Wno-error=maybe-uninitialized"
323+ "-Wno-error=array-bounds"
324+ ];
325+326+ dontUseCmakeConfigure = true;
327+328+ # Remove in-tree QEMU sources, we don't need them in any circumstance.
329+ prePatch = "rm -rf tools/qemu-xen tools/qemu-xen-traditional";
330+331+ installPhase = ''
332+ runHook preInstall
333+334+ mkdir -p $out $out/share $boot
335+ cp -prvd dist/install/nix/store/*/* $out/
336+ cp -prvd dist/install/etc $out
337+ cp -prvd dist/install/boot $boot
338+339+ runHook postInstall
340+ '';
341+342+ postInstall =
343+ # Wrap xencov_split, xenmon and xentrace_format.
344+ # We also need to wrap pygrub, which lies in $out/libexec/xen/bin.
345+ ''
346+ wrapPythonPrograms
347+ wrapPythonProgramsIn "$out/libexec/xen/bin" "$out $pythonPath"
348+ '';
349+350+ postFixup =
351+ ''
352+ addAutoPatchelfSearchPath $out/lib
353+ autoPatchelf $out/libexec/xen/bin
354+ ''
355+ # Flask is particularly hard to disable. Even after
356+ # setting the make flags to `n`, it still gets compiled.
357+ # If withFlask is disabled, delete the extra binaries.
358+ + optionalString (!withFlask) ''
359+ rm -f $out/bin/flask-*
360+ '';
361+362+ passthru = {
363+ efi = "boot/xen-${finalAttrs.upstreamVersion}.efi";
364+ flaskPolicy =
365+ if withFlask then
366+ warn "This Xen was compiled with FLASK support, but the FLASK file may not match the Xen version number. Please hardcode the path to the FLASK file instead." "boot/xenpolicy-${finalAttrs.upstreamVersion}"
367+ else
368+ throw "This Xen was compiled without FLASK support.";
369+ # This test suite is very simple, as Xen's userspace
370+ # utilities require the hypervisor to be booted.
371+ tests = {
372+ pkg-config = testers.hasPkgConfigModules {
373+ package = finalAttrs.finalPackage;
374+ moduleNames = [
375+ "xencall"
376+ "xencontrol"
377+ "xendevicemodel"
378+ "xenevtchn"
379+ "xenforeignmemory"
380+ "xengnttab"
381+ "xenguest"
382+ "xenhypfs"
383+ "xenlight"
384+ "xenstat"
385+ "xenstore"
386+ "xentoolcore"
387+ "xentoollog"
388+ "xenvchan"
389+ "xlutil"
390+ ];
391+ };
392+ };
393+ };
394+395+ meta = {
396+ branch = versions.majorMinor finalAttrs.version;
397+398+ description = "Type-1 hypervisor intended for embedded and hyperscale use cases";
399+ longDescription =
400+ ''
401+ The Xen Project Hypervisor is a virtualisation technology defined as a *type-1
402+ hypervisor*, which allows multiple virtual machines, known as domains, to run
403+ concurrently with the host on the physical machine. On a typical *type-2
404+ hypervisor*, the virtual machines run as applications on top of the
405+ host. NixOS runs as the privileged **Domain 0**, and can paravirtualise or fully
406+ virtualise **Unprivileged Domains**.
407+408+ Use with the `qemu_xen` package.
409+ ''
410+ + "\nIncludes:\n* `xen.efi`: The Xen Project's [EFI binary](https://xenbits.xenproject.org/docs/${finalAttrs.meta.branch}-testing/misc/efi.html), available on the `boot` output of this package."
411+ + optionalString withFlask "\n* `xsm-flask`: The [FLASK Xen Security Module](https://wiki.xenproject.org/wiki/Xen_Security_Modules_:_XSM-FLASK). The `xenpolicy` file is available on the `boot` output of this package."
412+ + optionalString withSeaBIOS "\n* `seabios`: Support for the SeaBIOS boot firmware on HVM domains."
413+ + optionalString withOVMF "\n* `ovmf`: Support for the OVMF UEFI boot firmware on HVM domains."
414+ + optionalString withIPXE "\n* `ipxe`: Support for the iPXE boot firmware on HVM domains.";
415+416+ homepage = "https://xenproject.org/";
417+ downloadPage = "https://downloads.xenproject.org/release/xen/${finalAttrs.version}/";
418+ changelog = "https://wiki.xenproject.org/wiki/Xen_Project_${finalAttrs.meta.branch}_Release_Notes";
419+420+ license = [
421+ # Documentation.
422+ cc-by-40
423+ # Most of Xen is licensed under the GPL v2.0.
424+ gpl2Only
425+ # Xen Libraries and the `xl` command-line utility.
426+ lgpl21Only
427+ # Development headers in $dev/include.
428+ mit
429+ ];
430+431+ teams = [ teams.xen ];
432+ knownVulnerabilities = optionals (versionOlder finalAttrs.version minSupportedVersion) [
433+ "The Xen Project Hypervisor version ${finalAttrs.version} is no longer supported by the Xen Project Security Team. See https://xenbits.xenproject.org/docs/unstable/support-matrix.html"
434+ ];
435+436+ mainProgram = "xl";
437+438+ platforms = [ isLinux ];
439+ badPlatforms = [ isAarch64 ];
440+ };
441+})
+1
pkgs/top-level/aliases.nix
···373 buildBarebox = throw "buildBarebox has been removed due to lack of interest in maintaining it in nixpkgs"; # Added 2025-04-19
374 buildGo122Module = throw "Go 1.22 is end-of-life, and 'buildGo122Module' has been removed. Please use a newer builder version."; # Added 2025-03-28
375 buildGoPackage = throw "`buildGoPackage` has been deprecated and removed, see the Go section in the nixpkgs manual for details"; # Added 2024-11-18
0376377 inherit (libsForQt5.mauiPackages) buho; # added 2022-05-17
378 bwidget = tclPackages.bwidget; # Added 2024-10-02
···373 buildBarebox = throw "buildBarebox has been removed due to lack of interest in maintaining it in nixpkgs"; # Added 2025-04-19
374 buildGo122Module = throw "Go 1.22 is end-of-life, and 'buildGo122Module' has been removed. Please use a newer builder version."; # Added 2025-03-28
375 buildGoPackage = throw "`buildGoPackage` has been deprecated and removed, see the Go section in the nixpkgs manual for details"; # Added 2024-11-18
376+ buildXenPackage = throw "'buildXenPackage' has been removed as a custom Xen build can now be achieved by simply overriding 'xen'."; # Added 2025-05-12
377378 inherit (libsForQt5.mauiPackages) buho; # added 2022-05-17
379 bwidget = tclPackages.bwidget; # Added 2024-10-02