From b9449748fc42475b58c47c318515b25c755d9fa0 Mon Sep 17 00:00:00 2001 From: coolneng Date: Wed, 17 Mar 2021 17:50:01 +0100 Subject: [PATCH] Launch SICA VM as a systemd service --- modules/virtualization.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/virtualization.nix b/modules/virtualization.nix index fc495cb..6165b7a 100644 --- a/modules/virtualization.nix +++ b/modules/virtualization.nix @@ -8,4 +8,19 @@ onShutdown = "shutdown"; qemuPackage = pkgs.qemu_kvm; }; + + # Declarative configuration of the VMs + systemd.services.sica = { + description = "SICA database"; + wantedBy = [ "default.target" ]; + script = '' + disk=/vault/VMs/sica.qcow2 + sock=/run/qemu-sica.mon.sock + ${pkgs.qemu_kvm}/bin/qemu-kvm -m 1G -nic user,hostfwd=tcp::2222-:22 -hda $disk -monitor unix:$sock,server,nowait -nographic + ''; + preStop = '' + echo 'system_powerdown' | ${pkgs.socat}/bin/socat - UNIX-CONNECT:/run/qemu-sica.mon.sock + sleep 10 + ''; + }; }