feature(wip): Adds installer.

This commit is contained in:
greysoh 2024-07-19 12:15:07 -04:00
parent 94facdb5fe
commit 3c291b8a95
Signed by: imterah
GPG key ID: 8FA7DD57BA6CEA37
10 changed files with 72 additions and 112 deletions

3
.gitignore vendored
View file

@ -1,4 +1,5 @@
out
build.log
secrets.nix
meta
meta
hardware-configuration.nix

View file

@ -1,17 +0,0 @@
#!/usr/bin/env bash
set -e
echo "Building '$1'..."
nix --extra-experimental-features nix-command run github:nix-community/nixos-generators -- --format proxmox --configuration "$1.nix" | tee build.log
if [ ! -d "out/" ]; then
mkdir out/
fi
echo "Copying file to the output directory..."
# Hacky!
mkdir -p out/$1
rm -rf out/$1 out/$1.vma.zst
OUT_FILE="$(sed -n '$p' build.log)"
cp -r $OUT_FILE out/$1.vma.zst

View file

@ -1,32 +0,0 @@
#!/usr/bin/env bash
mkdir meta > /dev/null 2> /dev/null
touch meta/tagged_for_upload
for FILE in kitteh-node-*/*; do
FILE_NO_EXTENSION="${FILE/".nix"/""}"
# Hacky!
mkdir -p meta/$FILE
rm -rf meta/$FILE
sha512sum $FILE > /tmp/kt-clusterbuild_sha512sum
if [ ! -f "meta/$FILE.sha" ] || ! diff -q "/tmp/kt-clusterbuild_sha512sum" "meta/$FILE.sha" > /dev/null; then
./build.sh $FILE_NO_EXTENSION
if [ $? -ne 0 ]; then
echo "Failed to build, skipping..."
continue
fi
if ! grep -q "out/$FILE_NO_EXTENSION.vma.zst" meta/tagged_for_upload; then
echo "out/$FILE_NO_EXTENSION.vma.zst" >> meta/tagged_for_upload
fi
else
echo "Not building '$FILE_NO_EXTENSION'."
fi
mv "/tmp/kt-clusterbuild_sha512sum" "meta/$FILE.sha"
done
echo "Done building."

View file

@ -5,13 +5,6 @@ in {
./commons.nix
];
# This is intentionally defined like this (not using braces) for updating. DO NOT CHANGE THIS.
# - greysoh
proxmox.qemuConf.memory = 8192;
proxmox.qemuConf.cores = 4;
proxmox.qemuConf.name = "k3s-agent";
proxmox.qemuConf.diskSize = pkgs.lib.mkForce "131072";
services.k3s = {
enable = true;
role = "agent";

View file

@ -4,6 +4,7 @@ let
in {
imports = [
./secrets.nix
./hardware-configuration.nix
];
swapDevices = [
@ -13,6 +14,9 @@ in {
}
];
boot.loader.grub.enable = true;
boot.loader.grub.device = "/dev/vda";
systemd.services.kittehclean = {
enable = true;
description = "Cleans up this Kitteh node & runs init tasks";

View file

@ -5,13 +5,6 @@ in {
./commons.nix
];
# This is intentionally defined like this (not using braces) for updating. DO NOT CHANGE THIS.
# - greysoh
proxmox.qemuConf.memory = 4096;
proxmox.qemuConf.cores = 1;
proxmox.qemuConf.name = "k3s-server";
proxmox.qemuConf.diskSize = pkgs.lib.mkForce "32768";
services.k3s = {
enable = true;
role = "server";

View file

@ -0,0 +1,51 @@
#!/usr/bin/env bash
export TERM="xterm-256color"
clear
echo "KittehCluster installer"
echo "Codename 'tundra'"
echo
sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | sudo fdisk /dev/vda
o # dos disk label
n # new partition
p # primary partition
1 # setup boot partition
2048 # align first sector (performance reasons?)
+500M # boot partition size
n # new partition
p # primary partition
2 # partion number 2
# default, start immediately after preceding partition
# default, extend partition to end of disk
a # make a partition bootable
1 # bootable partition is partition 1 -- /dev/vda1
w # write the partition table
q # and we're done
EOF
sudo mkfs.fat -F 32 /dev/vda1
sudo fatlabel /dev/vda1 BOOT
sudo mkfs.ext4 /dev/vda2 -L ROOT
sudo mount /dev/vda2 /mnt
sudo mkdir -p /mnt/boot
sudo mount /dev/vda1 /mnt/boot
sudo nixos-generate-config --root /mnt
sudo mv /mnt/etc/nixos/hardware-configuration.nix /tmp/hardware-configuration.nix
sudo rm -rf /mnt/etc/nixos/* /mnt/etc/nixos/.*
sudo nix-shell -p git --command "git clone $GIT_REPO /mnt/etc/nixos"
if [ ! -f "/mnt/etc/nixos/install-script.sh" ]; then
echo "DEBUG: checking out 'tundra' branch..."
sudo nix-shell -p git --command "cd /mnt/etc/nixos; git checkout tundra"
fi
sudo mv /tmp/hardware-configuration.nix /mnt/etc/nixos/nixinfra/
sudo nixos-install -I /mnt/etc/nixos/nixinfra/$NIX_INSTALL_PATH
sudo umount /mnt/boot
sudo umount /mnt

15
nixinfra/install.sh Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
if [ "$GIT_REPO" == "" ]; then
export GIT_REPO="https://git.hofers.cloud/greysoh/kittehcluster"
fi
if [ "$NIX_INSTALL_PATH" == "" ]; then
echo "ERROR: the environment variable 'NIX_INSTALL_PATH' is not set!"
echo "This can be fixed by setting it to the path of the nix file, i.e:"
echo "$ NIX_INSTALL_PATH=kitteh-node-1/server.nix ./install.sh"
exit 1
fi
echo "Initializing..."
FILE_ENCODED="$(cat install-script.sh | base64)"
ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" nixos@$1 bash -c "'echo -n $FILE_ENCODED | base64 -d > /tmp/install.sh; GIT_REPO=$GIT_REPO NIX_INSTALL_PATH=$NIX_INSTALL_PATH bash /tmp/install.sh'"

View file

@ -8,13 +8,6 @@ in {
../commons.nix
];
# This is intentionally defined like this (not using braces) for updating. DO NOT CHANGE THIS.
# - greysoh
proxmox.qemuConf.memory = 4096;
proxmox.qemuConf.cores = 1;
proxmox.qemuConf.name = "k3s-server";
proxmox.qemuConf.diskSize = pkgs.lib.mkForce "32768";
networking.hostName = "kitteh-node-1-k3s-server";
services.k3s = {

View file

@ -1,41 +0,0 @@
#!/usr/bin/env bash
if [ "$BASE_IP" = "" ]; then
BASE_IP=192.168.0.20
fi
IP_LAST_OCTET="${BASE_IP##*.}"
IP_MAIN_OCTET="${BASE_IP%.*}"
IP_LAST_OCTET=$((IP_LAST_OCTET-1))
BASE_ID=100
cp meta/tagged_for_upload /tmp/upload_cache
while IFS= read -r LINE; do
UPLOAD_PATH="/var/lib/vz/dump/vzdump-qemu-$(basename $LINE .vma.zst)-$(date +"%Y_%m_%d-%H_%M_%S").vma.zst"
echo "Uploading VM dump '$LINE'..."
CURRENT_NODE="$(dirname $LINE)"
CURRENT_NODE="${CURRENT_NODE##*-}"
IP="$IP_MAIN_OCTET.$((IP_LAST_OCTET+CURRENT_NODE))"
rsync --info=progress2 $LINE root@$IP:$UPLOAD_PATH
if [[ "$@" == *"--install"* ]] || [[ "$@" == *"-i"* ]]; then
echo "Installing VM dump '$LINE'..."
ssh -n root@$IP "qmrestore $UPLOAD_PATH $BASE_ID --force --unique"
BASE_ID=$((BASE_ID+1))
fi
if [[ "$@" == *"--delete"* ]] || [[ "$@" == *"-d"* ]]; then
echo "Deleting VM dump '$LINE'..."
ssh -n root@$IP "rm -rf $UPLOAD_PATH"
fi
ESCAPED_LINE=$(printf '%s\n' "$LINE" | sed -e 's/[\/&]/\\&/g')
sed -i "/$ESCAPED_LINE/d" meta/tagged_for_upload
done < /tmp/upload_cache
echo "Done."