2024-03-04 11:33:59 +01:00
|
|
|
#!/usr/bin/env nix-shell
|
2024-01-18 02:28:17 +01:00
|
|
|
#!nix-shell ../devshells/bootstrap/shell.nix
|
2024-01-18 02:27:38 +01:00
|
|
|
#!nix-shell -i bash
|
|
|
|
|
2024-01-18 02:24:34 +01:00
|
|
|
# Check if at least one argument is provided
|
2024-08-26 19:25:44 +02:00
|
|
|
if [ "$#" != "2" ] && [ "$#" != "3" ]; then
|
2024-08-27 13:54:32 +02:00
|
|
|
echo "❓ Usage: $0 <host> <disko-mode> [action]"
|
2024-01-18 02:24:34 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-08-26 19:22:16 +02:00
|
|
|
host=$1
|
|
|
|
mode=$2
|
|
|
|
action=$3
|
|
|
|
|
2024-01-18 02:24:34 +01:00
|
|
|
# Ensure correct first argument type
|
2024-08-26 19:22:16 +02:00
|
|
|
if [ "$mode" != "disko" ] && [ "$mode" != "mount" ]; then
|
2024-08-27 13:54:32 +02:00
|
|
|
echo "❓ Disko action must be either 'disko' or 'mount'"
|
2024-01-18 02:24:34 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure correct second argument type
|
2024-08-26 19:22:16 +02:00
|
|
|
if [ "$#" != "2" ] && [ "$action" != "install" ] && [ "$action" != "enter" ]; then
|
2024-08-27 13:54:32 +02:00
|
|
|
echo "❓ Action must either be empty, 'install' or 'enter'"
|
2024-01-18 02:24:34 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-08-26 19:17:13 +02:00
|
|
|
if mountpoint -q /hermes; then
|
2024-08-27 13:54:32 +02:00
|
|
|
echo "📂 Keys already mounted"
|
2024-01-18 02:37:01 +01:00
|
|
|
else
|
2024-08-27 13:54:32 +02:00
|
|
|
echo "📁 Mounting keys"
|
2024-01-18 02:37:01 +01:00
|
|
|
mkdir -p /hermes
|
|
|
|
mount /dev/disk/by-uuid/7FE7-CA68 /hermes
|
|
|
|
fi
|
2024-01-18 02:24:34 +01:00
|
|
|
|
|
|
|
|
2024-08-26 19:22:16 +02:00
|
|
|
if [ "$mode" = "mount" ] && [ "$host" = "lapetus" ]; then
|
2024-08-27 13:54:32 +02:00
|
|
|
echo "🏊 Importing zpool"
|
2024-01-18 02:32:21 +01:00
|
|
|
zpool import -lfR /mnt zroot
|
2024-01-18 02:24:34 +01:00
|
|
|
fi
|
|
|
|
|
2024-08-27 13:54:32 +02:00
|
|
|
echo "💣 Running disko"
|
2024-08-26 19:27:17 +02:00
|
|
|
nix run disko -- --mode $mode ./hosts/nixos/$host/filesystems/partitions.nix
|
2024-08-26 19:22:16 +02:00
|
|
|
|
|
|
|
if [ "$action" = "install" ]; then
|
2024-08-27 13:54:32 +02:00
|
|
|
echo "🛠️ Generating hardware config"
|
2024-08-26 19:22:16 +02:00
|
|
|
nixos-generate-config --no-filesystems --show-hardware-config \
|
|
|
|
> ./hosts/nixos/$host/hardware/generated.nix
|
|
|
|
git add .
|
2024-01-18 02:24:34 +01:00
|
|
|
|
2024-08-27 13:54:32 +02:00
|
|
|
echo "❄️ Installing nixos"
|
2024-08-26 19:22:16 +02:00
|
|
|
nixos-install --flake ".#$host"
|
2024-08-26 23:30:04 +02:00
|
|
|
|
2024-08-27 13:54:32 +02:00
|
|
|
echo "🔑 Copying user ssh keys"
|
2024-08-26 23:30:04 +02:00
|
|
|
for dir in /mnt/persist/state/home/*; do
|
|
|
|
mkdir -p "$dir/ssh/.ssh"
|
|
|
|
cp /hermes/secrets/$host/id* "$dir/ssh/.ssh"
|
|
|
|
done
|
|
|
|
|
2024-08-27 13:54:32 +02:00
|
|
|
echo "🔑 Copying host ssh keys"
|
2024-08-26 23:30:04 +02:00
|
|
|
mkdir -p /mnt/persist/state/home/
|
|
|
|
cp /hermes/secrets/$host/ssh* /mnt/persist/state/etc/ssh/
|
2024-01-18 02:24:34 +01:00
|
|
|
fi
|
|
|
|
|
2024-08-26 19:22:16 +02:00
|
|
|
if [ "$action" = "enter" ]; then
|
2024-08-27 13:54:32 +02:00
|
|
|
echo "❄️ Entering nixos"
|
2024-01-18 02:32:21 +01:00
|
|
|
nixos-enter --root /mnt
|
2024-01-18 02:24:34 +01:00
|
|
|
fi
|
|
|
|
|
2024-08-27 13:54:32 +02:00
|
|
|
echo "🚀 All done!"
|