diff options
author | Emile <git@emile.space> | 2024-09-19 10:48:16 +0200 |
---|---|---|
committer | Emile <git@emile.space> | 2024-09-19 10:48:16 +0200 |
commit | e833c13c177288b2a7b9168a784e0e6562c025b6 (patch) | |
tree | 1661dad1694989e2d83e6c2fca7b5602a61c574b /nix/modules/vm | |
parent | dcde3882d5460368e3c0499a54330f84a6995d62 (diff) |
big format using nixfmt
Diffstat (limited to 'nix/modules/vm')
-rw-r--r-- | nix/modules/vm/default.nix | 44 |
1 files changed, 26 insertions, 18 deletions
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" '' <domain type="kvm"> <name>${name}</name> <uuid>UUID</uuid> @@ -53,14 +61,13 @@ in with lib; { </features> </domain> ''; - 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; }; } |