nixos-config/install.sh

43 lines
1019 B
Bash

# Define the disk to partition
DISK="/dev/sda"
# Create a new partition table
parted $DISK -- mklabel gpt
# Create the root partition
parted $DISK -- mkpart root ext4 512MiB 100%
parted $DISK -- mkpart ESP fat32 1MB 512MiB
parted $DISK -- set 2 esp on
# DO NOT FORMAT the root partition before encryption!
# cryptsetup will fail if the partition is already formatted
# Encrypt the root partition
cryptsetup luksFormat ${DISK}1
cryptsetup open ${DISK}1 root
# Now format the encrypted partition
mkfs.ext4 /dev/mapper/root
# Mount the partitions
mount /dev/mapper/root /mnt
# Format
mkfs.fat -F 32 -n BOOT ${DISK}2
# Mount the partitions
mkdir -p /mnt/boot
mount -o umask=077 /dev/disk/by-label/BOOT /mnt/boot
# Clone the configuration repository
mkdir -p /mnt/etc/nixos
git clone https://git.luke-else.co.uk/luke-else/nixos-config.git /mnt/etc/nixos
# Install NixOS using the cloned configuration
nixos-install --flake /mnt/etc/nixos#vm
# Reboot the system
echo "Installation complete. Rebooting..."
reboot