From 697ceeb0eefab35a1a547acc9e634a2306ddd44d Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Wed, 28 Aug 2024 21:19:13 +0200 Subject: [PATCH] nixos/modules/virtualisation/xen-dom0.nix: remove `with lib;` --- nixos/modules/virtualisation/xen-dom0.nix | 88 +++++++++++------------ 1 file changed, 42 insertions(+), 46 deletions(-) diff --git a/nixos/modules/virtualisation/xen-dom0.nix b/nixos/modules/virtualisation/xen-dom0.nix index 2fb8c6cd456649d..ab97ecc501aef28 100644 --- a/nixos/modules/virtualisation/xen-dom0.nix +++ b/nixos/modules/virtualisation/xen-dom0.nix @@ -1,17 +1,13 @@ # 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 @@ -19,9 +15,9 @@ in 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 @@ -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. ''; @@ -55,9 +51,9 @@ 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. @@ -65,10 +61,10 @@ in }; 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. @@ -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 @@ -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 @@ -117,8 +113,8 @@ 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. @@ -126,8 +122,8 @@ in }; virtualisation.xen.domains = { - extraConfig = mkOption { - type = types.lines; + extraConfig = lib.mkOption { + type = lib.types.lines; default = ""; description = '' @@ -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}"; @@ -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 ]; @@ -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 = '' @@ -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"; }; @@ -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 = '' @@ -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 @@ -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"} ''; }; }; @@ -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}