unit/modules/virtualization.nix

27 lines
726 B
Nix
Raw Normal View History

2021-03-15 12:08:59 +01:00
{ config, lib, pkgs, ... }:
{
# Enable virtualisation
virtualisation.libvirtd = {
enable = true;
onBoot = "ignore";
onShutdown = "shutdown";
qemuPackage = pkgs.qemu_kvm;
};
2021-03-17 17:50:01 +01:00
# 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
2021-03-18 13:49:00 +01:00
${pkgs.qemu_kvm}/bin/qemu-kvm -m 1G -nic user,hostfwd=tcp::2222-:22,hostfwd=tcp::5000-:5000 -hda $disk -monitor unix:$sock,server,nowait -nographic
2021-03-17 17:50:01 +01:00
'';
preStop = ''
echo 'system_powerdown' | ${pkgs.socat}/bin/socat - UNIX-CONNECT:/run/qemu-sica.mon.sock
sleep 10
'';
};
2021-03-15 12:08:59 +01:00
}