nixos-configuration/install.sh

50 lines
2 KiB
Bash
Executable file

#! /usr/bin/env nix-shell
#! nix-shell -i bash -p git
if [ "$#" -ne 3 ]; then
cat << EOF
usage: sudo ./install.sh <disk> <swap> <encrypted: true/false>
EOF
exit
fi
# Download disko config
curl https://gitlab.com/SpoodyTheOne/nixos-config/-/raw/master/modules/disko/disko-luks.nix -o /tmp/disko.nix
curl https://gitlab.com/SpoodyTheOne/nixos-config/-/raw/master/modules/disko/disko-btrfs-impermanence.nix -o /tmp/disko-btrfs-impermanence.nix
echo "During partitioning you will be asked for a password. This password is used when booting. It will be asked for twice"
sudo nix --experimental-features "nix-command flakes" \
run github:nix-community/disko -- \
--mode disko /tmp/disko.nix \
--arg device "\"$1\"" \
--arg swap-size "\"$2\""
--arg swap-size "\"$3\""
sudo nixos-generate-config --no-filesystems --root /mnt
sudo mv /mnt/etc/nixos/hardware-configuration.nix /tmp # Move configuration away
sudo rm -rf /mnt/etc/nixos # Nuke config folder so we can clone
sudo git clone https://gitlab.com/SpoodyTheOne/nixos-config.git /mnt/etc/nixos # Clone config
# Move hardware configuration
sudo mv /tmp/hardware-configuration.nix /mnt/etc/nixos/hosts/bootstrap
# go to /etc/nixos
cd /mnt/etc/nixos
# Add hardware configuration to git for nix to recognize it
sudo git add .
echo -n
echo -e "\x1b[33mYou will now be placed in vim, Please edit the bootstrap config to match the arguments given to the script\x1b[37m"
sleep 5
sudo vim /mnt/etc/nixos/flake.nix +63
echo -n
echo -e "\x1b[31mThe system will install in 5 seconds. If you think you misconfigured flake.nix please press ctrl-c now to cancel\x1b[37m"
sleep 5
# Copy configuration to permanent storage so its not nuked on reboot
sudo cp -r /mnt/etc/nixos /mnt/persist
sudo nixos-install --root /mnt --flake /mnt/etc/nixos#bootstrap
echo -e "\x1b[32mIf no errors occured please reboot and follow the 'After reboot' section at https://gitlab.com/SpoodyTheOne/nixos-config";