From 951726c6ee34d3b9733d739dba3c4ee3c873bc7b Mon Sep 17 00:00:00 2001 From: Emile Date: Tue, 11 Feb 2025 00:01:35 +0100 Subject: corrino: libvirtnix, formatted --- nix/modules/libvirtnix/default.nix | 87 ++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 40 deletions(-) (limited to 'nix/modules/libvirtnix/default.nix') diff --git a/nix/modules/libvirtnix/default.nix b/nix/modules/libvirtnix/default.nix index 4689979..a998966 100644 --- a/nix/modules/libvirtnix/default.nix +++ b/nix/modules/libvirtnix/default.nix @@ -7,31 +7,36 @@ let cfg = config.services.emile.libvirtnix; -in { +in +{ options.services.emile.libvirtnix = with lib; { enable = mkEnableOption "enable libvirtnix"; - instances = - mkOption { - type = types.attrsOf (types.submodule ({ name, ... }: { - options = { - enable = mkEnableOption "enable this instance"; - domain = mkOption { - type = types.submodule (import ./domain.nix); - }; - }; - })); - default = {}; - description = '' - A full libvirt config, statically defined using nix. - ''; - example = '' + instances = mkOption { + type = types.attrsOf ( + types.submodule ( + { name, ... }: { - domain = { - name = "vm"; + options = { + enable = mkEnableOption "enable this instance"; + domain = mkOption { + type = types.submodule (import ./domain.nix); + }; }; } - ''; - }; + ) + ); + default = { }; + description = '' + A full libvirt config, statically defined using nix. + ''; + example = '' + { + domain = { + name = "vm"; + }; + } + ''; + }; }; config = lib.mkIf cfg.enable { @@ -47,8 +52,8 @@ in { }; script = let - xml = pkgs.writeText "libvirt-guest-${name}.xml" '' - '' @@ -57,26 +62,28 @@ in { + (lib.optionalString (guest.domain.uuid != "") "${guest.domain.uuid}") + (lib.optionalString (guest.domain.genid != "") "${guest.domain.genid}") + (lib.optionalString (guest.domain.title != "") "${guest.domain.title}") - + (lib.optionalString (guest.domain.description != "") "${guest.domain.description}") + + (lib.optionalString ( + guest.domain.description != "" + ) "${guest.domain.description}") + (lib.optionalString (guest.domain.metadata != "") "${guest.domain.metadata}") + '' - - hvm - - ${toString guest.domain.memory} - - - - - - - - - - - - - ''; + + hvm + + ${toString guest.domain.memory} + + + + + + + + + + + + + ''; in '' uuid="$(${pkgs.libvirt}/bin/virsh domuuid '${name}' || true)" -- cgit 1.4.1