nix-setup/install.sh

49 lines
1.2 KiB
Bash
Raw Permalink Normal View History

2024-10-21 17:40:52 +02:00
#!/bin/sh
echo "this is meant to be run from the iso!!!"
if [ $(whoami) = nixos ] ; then
echo "iso detected. continue!"
else
echo "you don't appear to be in the install iso."
echo -n "are you SURE??? (y/N) "
read sure
if ! [ "$sure" = "y" ] ; then
echo "ok. exiting."
exit 0
fi
echo "i will continue."
fi
lsblk
echo -n "> what drive to install on? /dev/"
read drive
2024-10-24 21:15:21 +02:00
sudo fdisk "/dev/$drive" << EOF
2024-10-21 17:40:52 +02:00
o
n
p
1
a
w
2024-10-24 21:15:21 +02:00
EOF
if [ $? != 0 ] ; then exit 1 ; fi
2024-10-24 21:16:40 +02:00
echo "> created DOS partition table on /dev/$drive with one bootable partition."
sudo mkfs.ext4 /dev/$drive*1 || exit 1 # /dev/sda 1 or /dev/nvme0n1 p1 => *1 instead of just 1
2024-10-21 17:40:52 +02:00
echo "> formatted."
2024-10-24 21:16:40 +02:00
sudo mount /dev/$drive*1 /mnt || exit 1
2024-10-21 17:40:52 +02:00
echo "> mounted."
echo "> generating config"
sudo nixos-generate-config --root /mnt
2024-10-21 17:40:52 +02:00
cd /mnt/etc/nixos
echo -n "hostname: "
2024-10-24 21:15:21 +02:00
sudo sed -i -E "s/^}\$/ boot.loader.grub.device = \"\/dev\/$drive\";\n networking.hostName = \"$(head -n1)\";\n}/" hardware-configuration.nix
2024-10-21 17:40:52 +02:00
echo "> installing git"
nix-env -i git > /dev/null || exit 1
echo "> downloading tudbut/nix-setup"
2024-10-21 17:46:02 +02:00
sudo git clone https://git.tudbut.de/tudbut/nix-setup
sudo rm configuration.nix
pushd nix-setup ; sudo mv $(ls -a) .. ; popd
2024-10-21 17:40:52 +02:00
echo "> initializing"
2024-10-21 17:46:02 +02:00
sudo bash init.sh