panacea/scripts/install.sh

70 lines
2.6 KiB
Bash
Raw Normal View History

2021-08-12 15:50:13 +02:00
#!/bin/sh
partition_disk() {
parted "$DISK" -- mklabel gpt
parted "$DISK" -- mkpart ESP fat32 1MiB 512MiB
parted "$DISK" -- mkpart primary 512MiB 100%
parted "$DISK" -- set 1 boot on
mkfs.fat -F32 -n BOOT "$DISK"p1
}
zfs_setup() {
zpool create -f -o ashift=13 -O acltype=posixacl -O relatime=on \
-O xattr=sa -O dnodesize=legacy -O normalization=formD -O mountpoint=none \
-O canmount=off -O devices=off -R /mnt -O compression=zstd -O encryption=aes-256-gcm \
-O keyformat=passphrase -O keylocation=prompt syscea "$DISK"p2
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=false syscea/ephemeral
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=false syscea/ephemeral/nix
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=false -o sync=disabled -o setuid=off syscea/ephemeral/tmp
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=false syscea/stateful
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=true syscea/stateful/home
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=false syscea/stateful/home/downloads
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=false syscea/stateful/root
zfs create -V 6G -b "$(getconf PAGESIZE)" -o compression=zle -o logbias=throughput -o sync=always \
-o primarycache=metadata -o secondarycache=none -o com.sun:auto-snapshot=false syscea/ephemeral/swap
2021-08-13 10:52:16 +02:00
mkswap -f /dev/zvol/syscea/ephemeral/swap && swapon /dev/zvol/syscea/ephemeral/swap
2021-08-12 15:50:13 +02:00
}
mount_datasets() {
mount -t zfs syscea/stateful/root /mnt
2021-08-13 10:52:16 +02:00
mkdir -p /mnt/boot
mount "$DISK"p1 /mnt/boot
mkdir -p /mnt/home/coolneng
2021-08-12 15:50:13 +02:00
mount -t zfs syscea/stateful/home /mnt/home/coolneng
2021-08-13 10:52:16 +02:00
mkdir -p /mnt/home/coolneng/Downloads
2021-08-12 15:50:13 +02:00
mount -t zfs syscea/stateful/home/downloads /mnt/home/coolneng/Downloads
2021-08-13 10:52:16 +02:00
mkdir -p /mnt/nix
2021-08-12 15:50:13 +02:00
mount -t zfs syscea/ephemeral/nix /mnt/nix
2021-08-13 10:52:16 +02:00
mkdir -p /mnt/tmp
2021-08-12 15:50:13 +02:00
mount -t zfs syscea/ephemeral/tmp /mnt/tmp
}
install_system() {
2021-08-12 23:22:36 +02:00
nixos-generate-config --root /mnt
2021-08-13 10:52:16 +02:00
sed -i "s/\${soundcloud_token}/PLACEHOLDER/" modules/audio.nix
mv /mnt/etc/nixos/hardware-configuration.nix modules/hardware-configuration.nix
nix-shell -p git nixFlakes --command "nixos-install --root /mnt --flake .#panacea"
2021-08-12 15:50:13 +02:00
}
usage() {
echo "Usage: install.sh <disk>"
echo "disk: full path to the disk (e.g. /dev/sda)"
exit 1
}
if [ $# != 1 ]; then
usage
fi
DISK="$1"
echo "Let's start by partitioning the disk"
partition_disk
echo "Starting up the ZFS machinery"
zfs_setup
echo "Mounting the horse"
mount_datasets
echo "Lift off to the NixOS planet"
install_system
echo "All ready, time to rejoice"