make mkFlake at root of flake
This commit is contained in:
parent
8a816b5e85
commit
1531a79212
5 changed files with 276 additions and 126 deletions
89
os/lib.nix
89
os/lib.nix
|
@ -13,15 +13,12 @@
|
|||
format.type = "qcow2";
|
||||
};
|
||||
};
|
||||
in {
|
||||
inherit osdb;
|
||||
|
||||
mkVM = {
|
||||
name,
|
||||
uuid,
|
||||
arch,
|
||||
isos,
|
||||
}: let
|
||||
}: rec {
|
||||
base = {
|
||||
inherit name uuid arch;
|
||||
volume.index = 0;
|
||||
|
@ -64,70 +61,24 @@ in {
|
|||
dev = "sd" + idxToDev x.index;
|
||||
}) (afterBoot);
|
||||
}));
|
||||
in derivation {
|
||||
inherit name system;
|
||||
builder = "${pkgs.fish}/bin/fish";
|
||||
args = [ ./lib/mkvm.fish ];
|
||||
|
||||
start-vm = pkgs.writeScript "start-vm"
|
||||
''
|
||||
#!/usr/bin/env fish
|
||||
|
||||
function quickExit
|
||||
virsh destroy ${name}
|
||||
exit
|
||||
end
|
||||
|
||||
function interrupt_handler --on-signal INT
|
||||
echo Got INT signal, cleaning up and exiting...
|
||||
quickExit
|
||||
end
|
||||
|
||||
echo "moving to beforeInstall stage"
|
||||
# rm /var/lib/libvirt/images/${name}.qcow2
|
||||
# virsh vol-delete --pool default '${name}.qcow2'
|
||||
virsh vol-create default ${volume}
|
||||
virsh define ${beforeInstallDrv}
|
||||
virsh start '${name}'
|
||||
|
||||
fish -c 'virsh console ${name} 2>/dev/null | while read -l out; if test $out = "$(string unescape ready\r\n)"; sleep 60; exit; end; end'
|
||||
|
||||
# virsh console '${name}' 2>/dev/null | while read -l out
|
||||
# # echo out: $out (string unescape \r)
|
||||
# if test $out = "$(string unescape ready\r\n)"
|
||||
# echo "waiting 60 seconds"
|
||||
# sleep 60
|
||||
# virsh shutdown '${name}'
|
||||
# end
|
||||
# end
|
||||
|
||||
echo "moving to afterInstall stage"
|
||||
virsh define ${afterInstallDrv}
|
||||
virsh snapshot-create-as '${name}' '${builtins.baseNameOf afterInstallDrv}'
|
||||
|
||||
virsh console '${name}' 2>/dev/null | while read -l out
|
||||
if test $out = "$(string unescape ready\r\n)"
|
||||
echo "waiting 60 seconds"
|
||||
sleep 60
|
||||
virsh shutdown '${name}'
|
||||
end
|
||||
end
|
||||
|
||||
echo "moving to beforeBoot stage"
|
||||
virsh define ${beforeBootDrv}
|
||||
virsh snapshot-create-as '${name}' '${builtins.baseNameOf beforeBootDrv}'
|
||||
|
||||
virsh console '${name}' 2>/dev/null | while read -l out
|
||||
if test $out = "$(string unescape ready\r\n)"
|
||||
echo "waiting 60 seconds"
|
||||
sleep 60
|
||||
virsh shutdown '${name}'
|
||||
end
|
||||
end
|
||||
|
||||
echo "moving to afterBoot stage"
|
||||
virsh define ${afterBootDrv}
|
||||
virsh snapshot-create-as '${name}' '${builtins.baseNameOf afterBootDrv}'
|
||||
'';
|
||||
};
|
||||
in {
|
||||
inherit osdb;
|
||||
|
||||
mkFlake = config: let
|
||||
vm = mkVM {
|
||||
inherit (config) name uuid;
|
||||
beforeInstall = [
|
||||
{ index = 1; file = "${osdb.${config.os.name}.${config.os.version}.${config.os.edition}.${config.os.arch}.installer}/out.iso"; }
|
||||
{ index = 2; file = "${osdb.${config.os.name}.${config.os.version}.${config.os.edition}.${config.os.arch}.unattend}/out.iso"; }
|
||||
];
|
||||
};
|
||||
in {
|
||||
packages.volume = vm.volume;
|
||||
packages.beforeInstall = vm.beforeInstallDrv;
|
||||
packages.afterInstall = vm.afterInstallDrv;
|
||||
packages.beforeBoot = vm.beforeBootDrv;
|
||||
packages.afterBoot = vm.afterBootDrv;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue