#!/usr/bin/env bash
set -euo pipefail

disk=/dev/nvme0n1

# Create GPT + partitions:
# 1: EFI (1G)
# 2: SWAP (16G)
# 3: ROOT (rest)
parted -s "$disk" mklabel gpt
parted -s "$disk" mkpart EFI fat32 1MiB 1025MiB
parted -s "$disk" set 1 esp on
parted -s "$disk" mkpart SWAP linux-swap 1025MiB 17409MiB
parted -s "$disk" mkpart MAIN ext4 17409MiB 100%

# Names for NVMe partitions:
efi_part=${disk}p1
swap_part=${disk}p2
root_part=${disk}p3

# Format
mkfs.ext4 "$root_part"
mkswap "$swap_part"
mkfs.fat -F32 "$efi_part"

# Mount
mount "$root_part" /mnt
mount --mkdir "$efi_part" /mnt/boot
swapon "$swap_part"

# Install base system
pacstrap -K /mnt base linux linux-firmware