nixos-config/install/i15.sh

64 lines
1.9 KiB
Bash
Raw Permalink Normal View History

2022-12-20 00:47:24 -03:00
#!/bin/sh
2022-12-20 08:47:26 -03:00
set -xe
2022-12-20 00:47:24 -03:00
2022-12-20 09:32:20 -03:00
settle() {
udevadm trigger --subsystem-match=block
udevadm settle
}
2022-12-20 00:47:24 -03:00
lsblk
echo 'Enter the name of the device to WIPE and install (something like "sda"):'
read DRIVE_ID
echo 'Enter a passphrase to encrypt the disk:'
read -s DRIVE_PASSPHRASE
echo "Creating partition table..."
2022-12-20 08:47:26 -03:00
parted -s "/dev/${DRIVE_ID}" -- mklabel gpt
2022-12-20 00:47:24 -03:00
echo "Creating EFI system partition..."
2022-12-20 08:47:26 -03:00
parted -s "/dev/${DRIVE_ID}" -- mkpart ESP 1MiB 1GiB
parted -s "/dev/${DRIVE_ID}" -- set 1 boot on
mkfs.fat -F32 "/dev/${DRIVE_ID}1" -n NIX_BOOT
2022-12-20 00:47:24 -03:00
echo "Creating encrypted root partition..."
2022-12-20 08:47:26 -03:00
parted -s "/dev/${DRIVE_ID}" -- mkpart luks 1GiB 100%
echo "$DRIVE_PASSPHRASE" | cryptsetup --batch-mode luksFormat --label CRYPT_ROOT "/dev/${DRIVE_ID}2"
2022-12-20 09:32:20 -03:00
settle
2022-12-20 08:47:26 -03:00
echo "$DRIVE_PASSPHRASE" | cryptsetup luksOpen /dev/disk/by-label/CRYPT_ROOT "crypt_root"
echo "Creating btrfs partition..."
mkfs.btrfs --quiet --label NIX_ROOT /dev/mapper/"crypt_root"
MNTPOINT=$(mktemp -d)
mount /dev/mapper/"crypt_root" "$MNTPOINT"
echo "Creating subvolumes..."
2022-12-20 09:32:20 -03:00
btrfs subvolume create "$MNTPOINT"/@nixos
btrfs subvolume create "$MNTPOINT"/@home
btrfs subvolume create "$MNTPOINT"/@swap
2022-12-20 08:47:26 -03:00
echo "Closing btrfs partition..."
umount -Rl "$MNTPOINT"
rm -rf "$MNTPOINT"
echo "Mounting root btrfs submodule to '$MNTPOINT' ..."
MNTPOINT=$(mktemp -d)
2022-12-20 09:32:20 -03:00
mount /dev/disk/by-label/NIX_ROOT "$MNTPOINT" -o subvol=@nixos,noatime,compress=zstd
2022-12-20 08:47:26 -03:00
echo "Creating and mounting EFI system partition mountpoint..."
2022-12-20 09:32:20 -03:00
mkdir -p "$MNTPOINT/boot"
mount /dev/disk/by-label/NIX_BOOT "$MNTPOINT/boot"
2022-12-20 08:47:26 -03:00
echo "Creating home partition mountpoint..."
mkdir -p "$MNTPOINT/home"
2022-12-20 09:32:20 -03:00
mount /dev/disk/by-label/NIX_ROOT "$MNTPOINT/home" -o subvol=@home,noatime,compress=zstd
2022-12-20 08:47:26 -03:00
echo "Swapfile"
mkdir -p "$MNTPOINT/swap"
2022-12-20 09:32:20 -03:00
mount /dev/disk/by-label/NIX_ROOT "$MNTPOINT/swap" -o subvol=@swap,noatime
2022-12-20 08:47:26 -03:00
2022-12-20 09:32:20 -03:00
# echo "Installing system..."
2022-12-20 08:47:26 -03:00
nixos-generate-config --root "$MNTPOINT"
2022-12-20 09:32:20 -03:00
# nixos-install --root "$MNTPOINT"