Skip to content

Commit b991116

Browse files
nixos/xen: general module improvements (NixOS#483205)
2 parents 597edd5 + 863d930 commit b991116

1 file changed

Lines changed: 61 additions & 52 deletions

File tree

nixos/modules/virtualisation/xen-dom0.nix

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Xen Project Hypervisor (Dom0) support.
2-
31
{
42
config,
53
lib,
@@ -8,35 +6,40 @@
86
}:
97

108
let
11-
inherit (builtins) readFile;
12-
inherit (lib.meta) hiPrio;
13-
inherit (lib.modules) mkRemovedOptionModule mkRenamedOptionModule mkIf;
14-
inherit (lib.options)
15-
mkOption
16-
mkEnableOption
9+
inherit (lib)
10+
boolToString
11+
getExe
12+
hasSuffix
13+
hiPrio
1714
literalExpression
15+
mkEnableOption
16+
mkIf
17+
mkOption
1818
mkPackageOption
19+
mkRemovedOptionModule
20+
mkRenamedOptionModule
21+
optional
22+
optionalAttrs
23+
optionalString
24+
optionals
25+
singleton
26+
teams
27+
types
1928
;
20-
inherit (lib.types)
21-
listOf
22-
str
23-
ints
24-
lines
25-
enum
26-
path
27-
submodule
29+
inherit (types)
2830
addCheck
29-
float
3031
bool
32+
enum
33+
float
3134
int
35+
ints
36+
lines
37+
listOf
3238
nullOr
39+
path
40+
str
41+
submodule
3342
;
34-
inherit (lib.lists) optional optionals;
35-
inherit (lib.strings) hasSuffix optionalString;
36-
inherit (lib.meta) getExe;
37-
inherit (lib.attrsets) optionalAttrs;
38-
inherit (lib.trivial) boolToString;
39-
inherit (lib.teams.xen) members;
4043

4144
cfg = config.virtualisation.xen;
4245

@@ -59,14 +62,12 @@ let
5962
diffutils
6063
]
6164
);
62-
runtimeEnv = {
63-
efiMountPoint = config.boot.loader.efi.efiSysMountPoint;
64-
};
65+
runtimeEnv.efiMountPoint = config.boot.loader.efi.efiSysMountPoint;
6566

6667
# We disable SC2016 because we don't want to expand the regexes in the sed commands.
6768
excludeShellChecks = [ "SC2016" ];
6869

69-
text = readFile ./xen-boot-builder.sh;
70+
text = builtins.readFile ./xen-boot-builder.sh;
7071
};
7172
in
7273

@@ -224,7 +225,7 @@ in
224225
boot = {
225226
params = mkOption {
226227
default = [ ];
227-
example = ''
228+
example = literalExpression ''
228229
[
229230
"iommu=force:true,qinval:true,debug:true"
230231
"noreboot=true"
@@ -234,8 +235,11 @@ in
234235
type = listOf str;
235236
description = ''
236237
Xen Command Line parameters passed to Domain 0 at boot time.
237-
Note: these are different from `boot.kernelParams`. See
238+
239+
::: {.note}
240+
Note: these are different from {option}`boot.kernelParams`. See
238241
the [Xen documentation](https://xenbits.xenproject.org/docs/unstable/misc/xen-command-line.html) for more information.
242+
:::
239243
'';
240244
};
241245
builderVerbosity = mkOption {
@@ -267,7 +271,7 @@ in
267271
type = path;
268272
default = "${cfg.package.boot}/${cfg.package.multiboot}";
269273
defaultText = literalExpression "\${config.virtualisation.xen.package.boot}/\${config.virtualisation.xen.package.multiboot}";
270-
example = literalExpression "\${config.virtualisation.xen.package}/boot/xen-\${config.virtualisation.xen.package.version}";
274+
example = literalExpression "\${config.virtualisation.xen.package}/boot/xen-\${config.virtualisation.xen.package.upstreamVersion}";
271275
description = ''
272276
Path to the Xen `multiboot` binary used for BIOS booting.
273277
Unless you're building your own Xen derivation, you should leave this
@@ -280,7 +284,7 @@ in
280284
type = path;
281285
default = "${cfg.package.boot}/${cfg.package.efi}";
282286
defaultText = literalExpression "\${config.virtualisation.xen.package.boot}/\${config.virtualisation.xen.package.efi}";
283-
example = literalExpression "\${config.virtualisation.xen.package}/boot/efi/efi/nixos/xen-\${config.virtualisation.xen.package.version}.efi";
287+
example = literalExpression "\${config.virtualisation.xen.package}/boot/efi/efi/nixos/xen-\${config.virtualisation.xen.package.upstreamVersion}.efi";
284288
description = ''
285289
Path to xen.efi. `pkgs.xen` is patched to install the xen.efi file
286290
on `$boot/boot/xen.efi`, but an unpatched Xen build may install it
@@ -333,7 +337,7 @@ in
333337
extraConfig = mkOption {
334338
type = lines;
335339
default = "";
336-
example = ''
340+
example = literalExpression ''
337341
XENDOMAINS_SAVE=/persist/xen/save
338342
XENDOMAINS_RESTORE=false
339343
XENDOMAINS_CREATE_USLEEP=10000000
@@ -674,12 +678,15 @@ in
674678
}
675679
{
676680
assertion = config.boot.initrd.systemd.enable;
677-
message = "Xen does not support the legacy script-based Stage 1 initrd.";
681+
message = ''
682+
Xen does not support the legacy script-based stage 1 initial ramdisk.
683+
Please set 'boot.initrd.systemd.enable' to 'true'.
684+
'';
678685
}
679686
{
680687
assertion = cfg.dom0Resources.maxMemory >= cfg.dom0Resources.memory;
681688
message = ''
682-
You have allocated more memory to dom0 than virtualisation.xen.dom0Resources.maxMemory
689+
You have allocated more memory to dom0 than 'virtualisation.xen.dom0Resources.maxMemory'
683690
allows for. Please increase the maximum memory limit, or decrease the default memory allocation.
684691
'';
685692
}
@@ -690,12 +697,19 @@ in
690697
{
691698
assertion = cfg.store.settings.quota.maxWatchEvents >= cfg.store.settings.quota.maxOutstanding;
692699
message = ''
693-
Upstream Xen recommends that maxWatchEvents be equal to or greater than maxOutstanding,
700+
Upstream Xen recommends that 'virtualisation.xen.store.settings.quota.maxWatchEvents'
701+
be equal to or greater than 'virtualisation.xen.store.settings.quota.maxOutstanding',
694702
in order to mitigate denial of service attacks from malicious frontends.
695703
'';
696704
}
697705
];
698706

707+
warnings = lib.optional ((config.boot ? lanzaboote) && config.boot.lanzaboote.enable) ''
708+
Xen support has not yet been merged into Lanzaboote.
709+
Ensure that your Lanzaboote configuration includes PR #387:
710+
https://github.com/nix-community/lanzaboote/pull/387
711+
'';
712+
699713
virtualisation.xen.boot.params =
700714
optionals cfg.trace [
701715
"loglvl=all"
@@ -752,9 +766,7 @@ in
752766
};
753767

754768
# See the `xenBootBuilder` script in the main `let...in` statement of this file.
755-
loader.systemd-boot.extraInstallCommands = ''
756-
${getExe xenBootBuilder} ${cfg.boot.builderVerbosity}
757-
'';
769+
loader.systemd-boot.extraInstallCommands = "${getExe xenBootBuilder} ${cfg.boot.builderVerbosity}";
758770
};
759771

760772
# Domain 0 requires a pvops-enabled kernel.
@@ -854,21 +866,18 @@ in
854866
# Xen provides systemd units.
855867
packages = [ cfg.package ];
856868

857-
mounts = [
858-
{
859-
description = "Mount /proc/xen files";
860-
what = "xenfs";
861-
where = "/proc/xen";
862-
type = "xenfs";
863-
unitConfig = {
864-
ConditionPathExists = "/proc/xen";
865-
RefuseManualStop = "true";
866-
};
867-
}
868-
];
869+
mounts = singleton {
870+
description = "Mount /proc/xen files";
871+
what = "xenfs";
872+
where = "/proc/xen";
873+
type = "xenfs";
874+
unitConfig = {
875+
ConditionPathExists = "/proc/xen";
876+
RefuseManualStop = "true";
877+
};
878+
};
869879

870880
services = {
871-
872881
# While this service is installed by the `xen` package, it shouldn't be used in dom0.
873882
xendriverdomain.enable = false;
874883

@@ -926,5 +935,5 @@ in
926935
};
927936
};
928937
};
929-
meta.maintainers = members;
938+
meta.maintainers = teams.xen.members;
930939
}

0 commit comments

Comments
 (0)