nixos-cesium/scripts/minimal-install.sh
2026-02-13 21:25:37 +01:00

78 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env sh
sudo -i
loadkeys de
lsblk
# Disk selection
DEFAULT_DISK="/dev/sda"
read -p "Disk to install to [${DEFAULT_DISK}]: " DISK
DISK="${DISK:-$DEFAULT_DISK}"
if [ ! -b "$DISK" ]; then
echo "Error: ${DISK} is not a valid block device."
exit 1
fi
echo "Using disk: ${DISK}"
# Partitioning
read -p "Create partitions table? DELETES ALL DATA! (j/N): " answer
if [ "$answer" = "j" ] || [ "$answer" = "J" ]; then
# GPT-partition table
parted "${DISK}" -- mklabel gpt
# EFI-partition (512 MB)
parted "${DISK}" -- mkpart esp fat32 1MB 512MB
parted "${DISK}" -- set 1 esp on
# Swap-partition (8 GB)
parted "${DISK}" -- mkpart swap linux-swap 512MB 8626MB
# Root-partition (ca. 45 GB)
parted "${DISK}" -- mkpart root ext4 8636MB 40000MB
# Home-partition (Rest)
parted "${DISK}" -- mkpart home ext4 40000MB 100%
fi
# Check results
parted "${DISK}" -- print
mkfs.fat -F 32 -n boot ${DISK}1
mkswap -L swap ${DISK}2
mkfs.ext4 -L nixos ${DISK}3
read -p "Format Home-partition? Deletes all userdata! (j/N): " answer
if [ "$answer" = "j" ] || [ "$answer" = "J" ]; then
# Format home-partition
mkfs.ext4 -L home ${DISK}4
fi
# Mount partitions
mount /dev/disk/by-label/nixos /mnt
mkdir /mnt/boot
mount -o umask=077 /dev/disk/by-label/boot /mnt/boot
mkdir -p /mnt/home
mount /dev/disk/by-label/home /mnt/home
# Activate swap
swapon /dev/disk/by-label/swap
nixos-generate-config --root /mnt
nixos-install
# If root password wasn't set because the installation needed to be restarted.
read -p "Set Root-password with nixos-enter? (j/N): " answer
if [ "$answer" = "j" ] || [ "$answer" = "J" ]; then
nixos-enter --root '/mnt'
passwd
fi