From e833c13c177288b2a7b9168a784e0e6562c025b6 Mon Sep 17 00:00:00 2001 From: Emile Date: Thu, 19 Sep 2024 10:48:16 +0200 Subject: big format using nixfmt --- nix/modules/vm/default.nix | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'nix/modules/vm') diff --git a/nix/modules/vm/default.nix b/nix/modules/vm/default.nix index 0f65765..6352c80 100644 --- a/nix/modules/vm/default.nix +++ b/nix/modules/vm/default.nix @@ -1,8 +1,15 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: let cfg = config.services.emile.r2wars-web; -in with lib; { +in +with lib; +{ options.services.emile.r2wars-web = { enable = mkEnableOption "Enable r2wars-web"; @@ -16,18 +23,19 @@ in with lib; { }; config = mkIf cfg.enable { - systemd.services = lib.mapAttrs' (name: guest: lib.nameValuePair "libvirtd-guest-${name}" { - after = [ "libvirtd.service" ]; - requires = [ "libvirtd.service" ]; - wantedBy = [ "multi-user.target" ]; - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = "yes"; - }; - script = - let - xml = pkgs.writeText "libvirt-guest-${name}.xml" - '' + systemd.services = lib.mapAttrs' ( + name: guest: + lib.nameValuePair "libvirtd-guest-${name}" { + after = [ "libvirtd.service" ]; + requires = [ "libvirtd.service" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = "yes"; + }; + script = + let + xml = pkgs.writeText "libvirt-guest-${name}.xml" '' ${name} UUID @@ -53,14 +61,13 @@ in with lib; { ''; - in + in '' uuid="$(${pkgs.libvirt}/bin/virsh domuuid '${name}' || true)" ${pkgs.libvirt}/bin/virsh define <(sed "s/UUID/$uuid/" '${xml}') ${pkgs.libvirt}/bin/virsh start '${name}' ''; - preStop = - '' + preStop = '' ${pkgs.libvirt}/bin/virsh shutdown '${name}' let "timeout = $(date +%s) + 10" while [ "$(${pkgs.libvirt}/bin/virsh list --name | grep --count '^${name}$')" -gt 0 ]; do @@ -73,6 +80,7 @@ in with lib; { fi done ''; - }) guests; + } + ) guests; }; } -- cgit 1.4.1