|
| 1 | +# Xen Project Hypervisor {#module-virtualisation-xen} |
| 2 | + |
| 3 | +## Introduction {#module-virtualisation-xen-introduction} |
| 4 | + |
| 5 | +The [**Xen Project Hypervisor**](https://xenproject.org/) is an open-source |
| 6 | +type-1 virtual machine manager which allows multiple virtual machines, known as |
| 7 | +*domains*, to run concurrently with the host on the physical machine. This is |
| 8 | +unlike a typical type-2 hypervisor, such as QEMU, where the virtual machines run |
| 9 | +as applications on top of the host. NixOS runs as the privileged *Domain 0*, and |
| 10 | +can paravirtualise (PV Mode) or fully virtualise (HVM Mode) unprivileged domains |
| 11 | +(`domUs`). |
| 12 | + |
| 13 | +Xen is security-supported in NixOS. All |
| 14 | +[Xen Security Advisories](https://xenbits.xenproject.org/xsa) are patched within |
| 15 | +hours of release, and generally reach the binary cache channels within a couple |
| 16 | +of days. |
| 17 | + |
| 18 | +## Domain 0 Installation {#module-virtualisation-xen-installation-dom0} |
| 19 | + |
| 20 | +Xen may be used as a Domain 0 since |
| 21 | +[NixOS 24.11](#sec-release-24.11-highlights), using the |
| 22 | +{option}`virtualisation.xen.enable` option. There are various hardware and |
| 23 | +software requirements to running a Xen Domain 0; the module is configured to |
| 24 | +prevent running Xen on a NixOS system that does not meet the software |
| 25 | +requirements. (i.e. a NixOS system that uses the legacy, scripted initial |
| 26 | +ramdisk.) The module does not yet check if the hardware requirements are met: |
| 27 | +please manually ensure that the target machine supports |
| 28 | +[SLAT](Second_Level_Address_Translation) and |
| 29 | +[IOMMU](https://en.wikipedia.org/wiki/Input%E2%80%93output_memory_management_unit), |
| 30 | +the latter being required only for non-PV domains to be virtualised. |
| 31 | + |
| 32 | +The boot menu on a Xen-enabled NixOS system will show duplicate entries for each |
| 33 | +generation: one boots a normal NixOS system, and the other boots into the Xen |
| 34 | +Project Hypervisor. The [`systemd-boot`](#opt-boot.loader.systemd-boot.enable) |
| 35 | +and [Limine](#opt-boot.loader.limine.enable) bootloaders are the only supported |
| 36 | +boot methods at this time. |
| 37 | + |
| 38 | +Xen may be managed through various frontend configuration systems. `libxenlight` |
| 39 | +is one such configuration system, and is built into all Xen systems. The `xl` |
| 40 | +command is the primary command-line interface to `libxenlight`, and is capable |
| 41 | +of managing a NixOS Domain 0. |
| 42 | + |
| 43 | +## Unprivileged Domain Installation {#module-virtualisation-xen-installation-domU} |
| 44 | + |
| 45 | +Known generically as guests, unprivileged domains running NixOS may import the |
| 46 | +[`xen-domU.nix`](https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/xen-domU.nix) |
| 47 | +profile in their configurations to automatically enable various recommended |
| 48 | +optimisations which are relevant for unprivileged domains. |
| 49 | + |
| 50 | +:::{.example} |
| 51 | + |
| 52 | +# Import the Xen Unprivileged Domain profile into a NixOS configuration |
| 53 | + |
| 54 | +```nix |
| 55 | +{ |
| 56 | + imports = [ |
| 57 | + <nixpkgs/nixos/modules/virtualisation/xen-domU.nix> |
| 58 | + ]; |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +::: |
0 commit comments