working build-vm tooling
This commit is contained in:
parent
404f360fbf
commit
974418bf8c
|
@ -114,6 +114,7 @@
|
|||
# Required for containers under podman-compose to be able to talk to each other.
|
||||
defaultNetwork.settings.dns_enabled = true;
|
||||
};
|
||||
diskSize = 262144;
|
||||
};
|
||||
|
||||
services.tailscale.enable = true;
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
build_dir="${build_dir:-/tmp/nixos-vm}"
|
||||
mount_point="${mount_point:-/tmp/fs}"
|
||||
qcow2="${qcow2:-${build_dir}/$(hostname -s).qcow2}"
|
||||
|
||||
echo "[+] configuration:"
|
||||
echo " build dir: ${build_dir}"
|
||||
echo " mount point: ${mount_point}"
|
||||
echo " image: ${qcow2}"
|
||||
|
||||
sleep 5
|
||||
|
||||
echo "[+] updating NixOS config"
|
||||
cd /etc/nixos
|
||||
doas git pull --rebase local master
|
||||
|
||||
if [[ -d "${build_dir}" ]]
|
||||
then
|
||||
echo "[+] removing ${build_dir}"
|
||||
sleep 2
|
||||
rm -r "${build_dir}"
|
||||
fi
|
||||
|
||||
mkdir "${build_dir}"
|
||||
cd "${build_dir}"
|
||||
nixos-rebuild build-vm
|
||||
|
||||
echo "[+] Spinning up VM; kill it when you see the line"
|
||||
echo " 'Virtualisation disk image created.'"
|
||||
"${build_dir}/result/bin/run-$(hostname -s)-vm"
|
||||
doas qemu-img resize "${qcow2}" 256G
|
||||
|
||||
doas modprobe nbd max_part=8
|
||||
|
||||
echo "[+] connecting to network block driver"
|
||||
echo " note: on failure, you may need to manually run"
|
||||
echo " doas qemu-nbd --disconnect /dev/nbd0"
|
||||
doas qemu-nbd --connect=/dev/nbd0 ${qcow2}
|
||||
|
||||
if [[ -d "${mount_point}" ]]
|
||||
then
|
||||
echo "[+] removing ${mount_point}"
|
||||
sleep 2
|
||||
rm -r "${mount_point}"
|
||||
fi
|
||||
|
||||
mkdir -p "${mount_point}"
|
||||
doas mount /dev/nbd0 "${mount_point}"
|
||||
|
||||
rsync --progress -auvz "${HOME}/" "${mount_point}/home/kyle/"
|
||||
|
||||
echo "[+] finished, cleaning up"
|
||||
doas unmount "${mount_point}"
|
||||
doas qemu-nbd --disconnect /dev/nbd0
|
||||
doas rmdir "${mount_point}"
|
||||
doas rm -r "${build_dir}"
|
Loading…
Reference in New Issue