nixos-config/install.sh
Luke Else 3353717da7
Some checks failed
NixOS Configuration Check / nixos-check (push) Failing after 22s
Added missing mkdir in install script
2025-04-24 21:09:26 +01:00

53 lines
1.5 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
# Replace with your actual repo
REPO_URL="https://git.luke-else.co.uk/luke-else/nixos-config.git"
HOSTNAME="vm" # Change to desktop/laptop/vm if needed
TARGET_DISK="/dev/sda"
MOUNT_POINT="/mnt"
# Confirm before wiping the disk
echo "WARNING: This will erase ALL data on ${TARGET_DISK}!"
read -p "Type YES to continue: " confirm
[[ "$confirm" == "YES" ]] || { echo "Aborting."; exit 1; }
# 1. Wipe the disk and create new GPT partition table
wipefs -a "$TARGET_DISK"
parted -s "$TARGET_DISK" mklabel gpt
# 2. Create partitions
# - EFI (512M)
# - Root (rest of the disk)
parted -s "$TARGET_DISK" mkpart primary fat32 1MiB 513MiB
parted -s "$TARGET_DISK" set 1 esp on
parted -s "$TARGET_DISK" mkpart primary ext4 513MiB 100%
EFI_PART="${TARGET_DISK}1"
CRYPT_PART="${TARGET_DISK}2"
# 3. Format the EFI partition
mkfs.fat -F32 "$EFI_PART"
# 4. Set up LUKS encryption for root
echo "Setting up LUKS encryption on ${CRYPT_PART}"
cryptsetup luksFormat "$CRYPT_PART"
cryptsetup open "$CRYPT_PART" cryptroot
# 5. Format root and mount
mkfs.ext4 /dev/mapper/cryptroot
mount /dev/mapper/cryptroot "$MOUNT_POINT"
# 6. Create and mount boot directory
mkdir -p "$MOUNT_POINT/boot"
mount "$EFI_PART" "$MOUNT_POINT/boot"
# 7. Clone your NixOS config
mkdir "$MOUNT_POINT/etc/nixos"
git clone "$REPO_URL" "$MOUNT_POINT/etc/nixos"
# 8. Install NixOS
nixos-install --flake "/etc/nixos#${HOSTNAME}" --no-root-passwd
echo "✅ NixOS installation complete! You may now reboot."