86 lines
1.9 KiB
Bash
86 lines
1.9 KiB
Bash
#!/bin/sh
|
|
|
|
DISK=/dev/null
|
|
|
|
set -e
|
|
|
|
if [ $DISK == "/dev/null" ]; then
|
|
return 1
|
|
fi
|
|
|
|
# Create two partitions here: p1 and p2
|
|
fdisk $DISK
|
|
|
|
# Formats the partitions
|
|
mkfs.vfat -n BOOT ${DISK}p1
|
|
mkfs.btrfs -L ROOT ${DISK}p2
|
|
|
|
mount -t btrfs ${DISK}p2 /mnt
|
|
|
|
# Creates btrfs subvolumes
|
|
btrfs subvolume create /mnt/root
|
|
btrfs subvolume create /mnt/home
|
|
btrfs subvolume create /mnt/nix
|
|
btrfs subvolume create /mnt/persist
|
|
btrfs subvolume create /mnt/log
|
|
|
|
# Creates snapshot
|
|
btrfs subvolume snapshot -r /mnt/root /mnt/root-blank
|
|
|
|
umount /mnt
|
|
|
|
|
|
|
|
# Creates the directories for the subvolumes to be mounted to, nixos-install will detect this.
|
|
|
|
mount -o subvol=root,compress=zstd,noatime ${DISK}p2 /mnt
|
|
|
|
mkdir /mnt/home
|
|
mount -o subvol=home,compress=zstd,noatime ${DISK}p2 /mnt/home
|
|
|
|
mkdir /mnt/nix
|
|
mount -o subvol=nix,compress=zstd,noatime ${DISK}p2 /mnt/nix
|
|
|
|
mkdir /mnt/persist
|
|
mount -o subvol=persist,compress=zstd,noatime ${DISK}p2 /mnt/persist
|
|
|
|
mkdir -p /mnt/var/log
|
|
mount -o subvol=log,compress=zstd,noatime ${DISK}p2 /mnt/var/log
|
|
|
|
mkdir /mnt/boot
|
|
mount "$DISK"p1 /mnt/boot
|
|
|
|
|
|
|
|
nixos-generate-config --root /mnt
|
|
|
|
# Add `"compress=zstd" "noatime"` to all btrfs fileSystem entries
|
|
# Add `neededForBoot = true;` to the logging subvolume
|
|
nano /mnt/etc/nixos/hardware-configuration.nix
|
|
|
|
echo "Initial setup complete :D" &&
|
|
echo "Installing in 5" &&
|
|
sleep 1 &&
|
|
echo "Installing in 4" &&
|
|
sleep 1 &&
|
|
echo "Installing in 3" &&
|
|
sleep 1 &&
|
|
echo "Installing in 2" &&
|
|
sleep 1 &&
|
|
echo "Installing in 1" &&
|
|
sleep 1 &&
|
|
echo "Installing now"
|
|
nixos-install &&
|
|
reboot
|
|
|
|
# After the reboot, you should be in the fresh NixOS install
|
|
# You're not completely done yet, however. You need to to run a few more commands:
|
|
|
|
mkdir -p /persist/etc/nixos
|
|
cp -r /etc/nixos /persist/etc
|
|
|
|
cp /etc/machine-id /persist/etc
|
|
|
|
mkdir -p /persist/etc/ssh
|
|
cp /etc/ssh/ssh_host_ed25519_key /persist/etc/ssh
|
|
cp /etc/ssh/ssh_host_ed25519_key.pub /persist/etc/ssh
|