Skip to content

Commit

Permalink
nixos/modules/virtualisation/xen-dom0.nix: remove with lib;
Browse files Browse the repository at this point in the history
  • Loading branch information
Stunkymonkey committed Aug 28, 2024
1 parent 6d57e0b commit 697ceeb
Showing 1 changed file with 42 additions and 46 deletions.
88 changes: 42 additions & 46 deletions nixos/modules/virtualisation/xen-dom0.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
# Xen hypervisor (Dom0) support.

{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.virtualisation.xen;
in

{
imports = [
(mkRemovedOptionModule [ "virtualisation" "xen" "qemu" ] "You don't need this option anymore, it will work without it.")
(mkRenamedOptionModule [ "virtualisation" "xen" "qemu-package" ] [ "virtualisation" "xen" "package-qemu" ])
(lib.mkRemovedOptionModule [ "virtualisation" "xen" "qemu" ] "You don't need this option lib.anymore, it will work without it.")
(lib.mkRenamedOptionModule [ "virtualisation" "xen" "qemu-package" ] [ "virtualisation" "xen" "package-qemu" ])
];

###### interface

options = {

virtualisation.xen.enable =
mkOption {
lib.mkOption {
default = false;
type = types.bool;
type = lib.types.bool;
description = ''
Setting this option enables the Xen hypervisor, a
virtualisation technology that allows multiple virtual
Expand All @@ -32,20 +28,20 @@ in
'';
};

virtualisation.xen.package = mkOption {
type = types.package;
defaultText = literalExpression "pkgs.xen";
example = literalExpression "pkgs.xen-light";
virtualisation.xen.package = lib.mkOption {
type = lib.types.package;
defaultText = lib.literalExpression "pkgs.xen";
example = lib.literalExpression "pkgs.xen-light";
description = ''
The package used for Xen binary.
'';
relatedPackages = [ "xen" "xen-light" ];
};

virtualisation.xen.package-qemu = mkOption {
type = types.package;
defaultText = literalExpression "pkgs.xen";
example = literalExpression "pkgs.qemu_xen-light";
virtualisation.xen.package-qemu = lib.mkOption {
type = lib.types.package;
defaultText = lib.literalExpression "pkgs.xen";
example = lib.literalExpression "pkgs.qemu_xen-light";
description = ''
The package with qemu binaries for dom0 qemu and xendomains.
'';
Expand All @@ -55,20 +51,20 @@ in
};

virtualisation.xen.bootParams =
mkOption {
lib.mkOption {
default = [];
type = types.listOf types.str;
type = lib.types.listOf lib.types.str;
description =
''
Parameters passed to the Xen hypervisor at boot time.
'';
};

virtualisation.xen.domain0MemorySize =
mkOption {
lib.mkOption {
default = 0;
example = 512;
type = types.addCheck types.int (n: n >= 0);
type = lib.types.addCheck lib.types.int (n: n >= 0);
description =
''
Amount of memory (in MiB) allocated to Domain 0 on boot.
Expand All @@ -77,24 +73,24 @@ in
};

virtualisation.xen.bridge = {
name = mkOption {
name = lib.mkOption {
default = "xenbr0";
type = types.str;
type = lib.types.str;
description = ''
Name of bridge the Xen domUs connect to.
'';
};

address = mkOption {
type = types.str;
address = lib.mkOption {
type = lib.types.str;
default = "172.16.0.1";
description = ''
IPv4 address of the bridge.
'';
};

prefixLength = mkOption {
type = types.addCheck types.int (n: n >= 0 && n <= 32);
prefixLength = lib.mkOption {
type = lib.types.addCheck lib.types.int (n: n >= 0 && n <= 32);
default = 16;
description = ''
Subnet mask of the bridge interface, specified as the number of
Expand All @@ -104,8 +100,8 @@ in
'';
};

forwardDns = mkOption {
type = types.bool;
forwardDns = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
If set to `true`, the DNS queries from the
Expand All @@ -117,17 +113,17 @@ in
};

virtualisation.xen.stored =
mkOption {
type = types.path;
lib.mkOption {
type = lib.types.path;
description =
''
Xen Store daemon to use. Defaults to oxenstored of the xen package.
'';
};

virtualisation.xen.domains = {
extraConfig = mkOption {
type = types.lines;
extraConfig = lib.mkOption {
type = lib.types.lines;
default = "";
description =
''
Expand All @@ -138,14 +134,14 @@ in
};
};

virtualisation.xen.trace = mkEnableOption "Xen tracing";
virtualisation.xen.trace = lib.mkEnableOption "Xen tracing";

};


###### implementation

config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
assertions = [ {
assertion = pkgs.stdenv.isx86_64;
message = "Xen currently not supported on ${pkgs.stdenv.hostPlatform.system}";
Expand All @@ -154,9 +150,9 @@ in
message = "Xen currently does not support EFI boot";
} ];

virtualisation.xen.package = mkDefault pkgs.xen;
virtualisation.xen.package-qemu = mkDefault pkgs.xen;
virtualisation.xen.stored = mkDefault "${cfg.package}/bin/oxenstored";
virtualisation.xen.package = lib.mkDefault pkgs.xen;
virtualisation.xen.package-qemu = lib.mkDefault pkgs.xen;
virtualisation.xen.stored = lib.mkDefault "${cfg.package}/bin/oxenstored";

environment.systemPackages = [ cfg.package ];

Expand Down Expand Up @@ -186,8 +182,8 @@ in
'';

virtualisation.xen.bootParams = [] ++
optionals cfg.trace [ "loglvl=all" "guest_loglvl=all" ] ++
optional (cfg.domain0MemorySize != 0) "dom0_mem=${toString cfg.domain0MemorySize}M";
lib.optionals cfg.trace [ "loglvl=all" "guest_loglvl=all" ] ++
lib.optional (cfg.domain0MemorySize != 0) "dom0_mem=${toString cfg.domain0MemorySize}M";

system.extraSystemBuilderCmds =
''
Expand Down Expand Up @@ -236,7 +232,7 @@ in
${cfg.domains.extraConfig}
'';
}
// optionalAttrs (builtins.compareVersions cfg.package.version "4.10" >= 0) {
// lib.optionalAttrs (builtins.compareVersions cfg.package.version "4.10" >= 0) {
# in V 4.10 oxenstored requires /etc/xen/oxenstored.conf to start
"xen/oxenstored.conf".source = "${cfg.package}/etc/xen/oxenstored.conf";
};
Expand All @@ -262,7 +258,7 @@ in
'';
serviceConfig = if (builtins.compareVersions cfg.package.version "4.8" < 0) then
{ ExecStart = ''
${cfg.stored}${optionalString cfg.trace " -T /var/log/xen/xenstored-trace.log"} --no-fork
${cfg.stored}${lib.optionalString cfg.trace " -T /var/log/xen/xenstored-trace.log"} --no-fork
'';
} else {
ExecStart = ''
Expand All @@ -273,7 +269,7 @@ in
NotifyAccess = "all";
};
postStart = ''
${optionalString (builtins.compareVersions cfg.package.version "4.8" < 0) ''
${lib.optionalString (builtins.compareVersions cfg.package.version "4.8" < 0) ''
time=0
timeout=30
# Wait for xenstored to actually come up, timing out after 30 seconds
Expand Down Expand Up @@ -312,14 +308,14 @@ in
requires = [ "xen-store.service" ];
preStart = ''
mkdir -p /var/run/xen
${optionalString cfg.trace "mkdir -p /var/log/xen"}
${lib.optionalString cfg.trace "mkdir -p /var/log/xen"}
grep -q control_d /proc/xen/capabilities
'';
serviceConfig = {
ExecStart = ''
${cfg.package}/bin/xenconsoled\
${optionalString ((builtins.compareVersions cfg.package.version "4.8" >= 0)) " -i"}\
${optionalString cfg.trace " --log=all --log-dir=/var/log/xen"}
${lib.optionalString ((builtins.compareVersions cfg.package.version "4.8" >= 0)) " -i"}\
${lib.optionalString cfg.trace " --log=all --log-dir=/var/log/xen"}
'';
};
};
Expand Down Expand Up @@ -384,7 +380,7 @@ in
strict-order
no-hosts
bogus-priv
${optionalString (!cfg.bridge.forwardDns) ''
${lib.optionalString (!cfg.bridge.forwardDns) ''
no-resolv
no-poll
auth-server=dns.xen.local,${cfg.bridge.name}
Expand Down

0 comments on commit 697ceeb

Please sign in to comment.