From a901dcab93d2cdaaeb2f592894eb16451807d8f7 Mon Sep 17 00:00:00 2001 From: Fernando Rodrigues Date: Thu, 5 Dec 2024 07:40:57 -0300 Subject: [PATCH] nixos/xen: init Domain 0 xl configuration module Signed-off-by: Fernando Rodrigues --- doc/manpage-urls.json | 4 +- nixos/modules/virtualisation/xen/xl.nix | 56 +++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/doc/manpage-urls.json b/doc/manpage-urls.json index d6e9d163c1128c..36dab62a4b0a7c 100644 --- a/doc/manpage-urls.json +++ b/doc/manpage-urls.json @@ -321,5 +321,7 @@ "user@.service(5)": "https://www.freedesktop.org/software/systemd/man/user@.service.html", "userdbctl(1)": "https://www.freedesktop.org/software/systemd/man/userdbctl.html", "vconsole.conf(5)": "https://www.freedesktop.org/software/systemd/man/vconsole.conf.html", - "veritytab(5)": "https://www.freedesktop.org/software/systemd/man/veritytab.html" + "veritytab(5)": "https://www.freedesktop.org/software/systemd/man/veritytab.html", + "xl.cfg(5)": "https://xenbits.xen.org/docs/unstable/man/xl.cfg.5.html", + "xl.conf(5)": "https://xenbits.xen.org/docs/unstable/man/xl.conf.5.html" } diff --git a/nixos/modules/virtualisation/xen/xl.nix b/nixos/modules/virtualisation/xen/xl.nix index e69de29bb2d1d6..55a2ccf500e52c 100644 --- a/nixos/modules/virtualisation/xen/xl.nix +++ b/nixos/modules/virtualisation/xen/xl.nix @@ -0,0 +1,56 @@ +# Xen Project Hypervisor Domain 0 libxenlight configuration +{ + config, + lib, + pkgs, + ... +}: + +let + inherit (lib) mkIf mkOption attrByPath; + + cfg = config.virtualisation.xen; + + settingsFormat = pkgs.formats.xenLight { type = "conf"; }; +in +{ + ## Interface ## + + options.virtualisation.xen = { + settings = mkOption { + inherit (settingsFormat) type; + default = { }; + example = { + autoballoon = "off"; + bootloader_restrict = false; + lockfile = "/run/lock/xen/xl"; + max_grant_version = 256; + "vif.default.bridge" = "xenbr0"; + "vm.hvm.cpumask" = [ + "2" + "3-8,^5" + ]; + }; + description = '' + The contents of the `/etc/xen/xl.conf` file. + See {manpage}`xl.conf(5)` for available configuration options. + ''; + }; + }; + + ## Implementation ## + + config = mkIf cfg.enable { + assertions = [ + { + assertion = + (cfg.dom0Resources.memory != 0) -> ((attrByPath [ "autoballoon" ] "auto" cfg.settings) != "on"); + message = '' + Upstream Xen strongly recommends that autoballoon be set to "off" or "auto" if + virtualisation.xen.dom0Resources.memory is limiting the total Domain 0 memory. + ''; + } + ]; + environment.etc."xen/xl.conf".source = settingsFormat.generate "xl.conf" cfg.settings; + }; +}