# Step 1: Choosing the drive for the installation

## Detect and list the drives.
lsblk -f

## Choice the drive to use :
echo "----------"
echo "Which drive do we want to use for this installation?"
echo "For example /dev/sda or /dev/nvme0n1"

echo ""
read -p "Enter your drive choice: " driveName
echo ""

## Download Disko file
cd /tmp
curl https://gitlab.com/ahoneybun/nix-configs/-/raw/main/partitions/luks-btrfs-subvolumes.nix -o /tmp/disko-config.nix

## Replace drive in Disko file
sudo sed -i "s#/dev/sda#$driveName#g" /tmp/disko-config.nix

# Step 2: Partitioning the drive used for the installation

## Run Disko to partition the disk
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko/latest -- --mode destroy,format,mount /tmp/disko-config.nix --yes-wipe-all-disks

## Generate Nix configuration
sudo nixos-generate-config --no-filesystems --root /mnt

## Copies over the disko file for running `nixos-install`
sudo mv /tmp/disko-config.nix /mnt/etc/nixos

## Downloads and places the predefinded generic flake to use
curl https://gitlab.com/ahoneybun/nix-configs/-/raw/main/flake.nix > flake.nix; sudo mv -f flake.nix /mnt/etc/nixos/

## Downloads and places the predefinded generic configuration and home files to use
curl https://gitlab.com/ahoneybun/nix-configs/-/raw/main/configuration.nix > configuration.nix; sudo mv -f configuration.nix /mnt/etc/nixos/
curl https://gitlab.com/ahoneybun/nix-configs/-/raw/main/home.nix > home.nix; sudo mv -f home.nix /mnt/etc/nixos/

# Step 3: Choosing a predefined system flake file to use

cat << EOF

Which device are you installing to?
   1) Virtual Machine
   2) Lemur Pro 13 (Garrus)
   3) Pixel Slate
   4) nebula49 (Shepard)
   0) Generic
EOF

echo ""
read -p "Enter your device choice: " hostChoice
echo ""

if [ $hostChoice = 1 ]; then
   curl https://gitlab.com/ahoneybun/nix-configs/-/raw/main/hosts/x86_64/vm/configuration.nix > vm.nix; sudo mv -f vm.nix /mnt/etc/nixos/
   sudo nixos-install --flake /mnt/etc/nixos#vm

elif [ $hostChoice = 2 ]; then
   curl https://gitlab.com/ahoneybun/nix-configs/-/raw/main/hosts/x86_64/garrus/configuration.nix > garrus.nix; sudo mv -f garrus.nix /mnt/etc/nixos/
   curl https://gitlab.com/ahoneybun/nix-configs/-/raw/main/desktops/gnome.nix > gnome.nix; sudo mv -f gnome.nix /mnt/etc/nixos/
   sudo nixos-install --flake /mnt/etc/nixos#garrus

elif [ $hostChoice = 3 ]; then
   curl https://gitlab.com/ahoneybun/nix-configs/-/raw/main/hosts/x86_64/pixel-slate.nix > pixel-slate.nix; sudo mv -f pixel-slate.nix /mnt/etc/nixos/
   #curl https://gitlab.com/ahoneybun/nix-configs/-/raw/main/desktops/lomiri.nix > gnome.nix; sudo mv -f gnome.nix /mnt/etc/nixos/
   sudo nixos-install --flake /mnt/etc/nixos#pixel-slate

elif [ $hostChoice = 4 ]; then
   curl https://gitlab.com/ahoneybun/nix-configs/-/raw/main/hosts/x86_64/shepard/configuration.nix > shepard.nix; sudo mv -f shepard.nix /mnt/etc/nixos/
   curl https://gitlab.com/ahoneybun/nix-configs/-/raw/main/desktops/gnome.nix > gnome.nix; sudo mv -f gnome.nix /mnt/etc/nixos/
   sudo nixos-install --flake /mnt/etc/nixos#shepard

elif [ $hostChoice = 0 ]; then
   curl https://gitlab.com/ahoneybun/nix-configs/-/raw/main/flake.nix > flake.nix; sudo mv -f flake.nix /mnt/etc/nixos/
   curl https://gitlab.com/ahoneybun/nix-configs/-/raw/main/desktops/gnome.nix > gnome.nix; sudo mv -f gnome.nix /mnt/etc/nixos/
   sudo nixos-install --flake /mnt/etc/nixos#nixos

fi