68 lines
1.9 KiB
Nix
68 lines
1.9 KiB
Nix
{
|
|
pkgs ? import <nixpkgs> {},
|
|
system ? builtins.currentSystem,
|
|
nixvirt,
|
|
}: let
|
|
inherit (nixvirt) lib;
|
|
vm = import ./lib/vm.nix { inherit pkgs nixvirt; };
|
|
osdb = import ./db.nix { inherit pkgs system; };
|
|
volumeFn = { name, size }: nixvirt.lib.volume.writeXML {
|
|
name = name + ".qcow2";
|
|
capacity = { count = size; unit = "GB"; };
|
|
target = {
|
|
format.type = "qcow2";
|
|
};
|
|
};
|
|
in {
|
|
inherit osdb;
|
|
|
|
mkVM = {
|
|
name,
|
|
uuid,
|
|
arch,
|
|
isos,
|
|
}: rec {
|
|
base = {
|
|
inherit name uuid arch;
|
|
volume.index = 0;
|
|
volume.bus = "sata";
|
|
volume.file = "/var/lib/libvirt/images/${name}.qcow2";
|
|
};
|
|
idxToDev = i: builtins.substring i 1 "abcdefg";
|
|
|
|
volume = volumeFn { size = 16; inherit name; };
|
|
|
|
beforeInstall = isos.beforeInstall; # Required attribute.
|
|
afterInstall = if builtins.hasAttr "afterInstall" isos then isos.afterInstall else [];
|
|
beforeBoot = if builtins.hasAttr "beforeBoot" isos then isos.beforeBoot else [];
|
|
afterBoot = if builtins.hasAttr "afterBoot" isos then isos.afterBoot else [];
|
|
beforeInstallDrv = lib.domain.writeXML (vm.genericVM (base // {
|
|
cdroms = map (x: {
|
|
inherit (x) index file;
|
|
bus = "sata";
|
|
dev = "sd" + idxToDev x.index;
|
|
}) (beforeInstall);
|
|
}));
|
|
afterInstallDrv = lib.domain.writeXML (vm.genericVM (base // {
|
|
cdroms = map (x: {
|
|
inherit (x) index file;
|
|
bus = "sata";
|
|
dev = "sd" + idxToDev x.index;
|
|
}) (afterInstall);
|
|
}));
|
|
beforeBootDrv = lib.domain.writeXML (vm.genericVM (base // {
|
|
cdroms = map (x: {
|
|
inherit (x) index file;
|
|
bus = "sata";
|
|
dev = "sd" + idxToDev x.index;
|
|
}) (beforeBoot);
|
|
}));
|
|
afterBootDrv = lib.domain.writeXML (vm.genericVM (base // {
|
|
cdroms = map (x: {
|
|
inherit (x) index file;
|
|
bus = "sata";
|
|
dev = "sd" + idxToDev x.index;
|
|
}) (afterBoot);
|
|
}));
|
|
};
|
|
}
|