nixos/zeta/install.txt

161 lines
3.2 KiB
Text

#
# preparation of installer on NixOS machine
# details see https://github.com/nix-community/nixos-apple-silicon/blob/main/docs/uefi-standalone.md
#
# get the Apple Silicon support git
git clone https://github.com/nix-community/nixos-apple-silicon.git
cd nixos-apple-silicon
# build m1n1
nix build .#m1n1 -o m1n1
# build uboot
nix build .#uboot-asahi -o u-boot
# build installer ISO
nix build .#installer-bootstrap -o installer -j4 -L
# write to USB stick
doas dd if=result/iso/nixos-*-x86_64-linux.iso of=/dev/sda bs=4M conv=fsync
#
# enable ssh for root
#
sudo bash
systemctl start sshd
passwd
# get wlan
nmtui
#
# install script below
#
# host name to use
HOST=zeta
# disks to use
DISK=/dev/disk/by-id/nvme-SAMSUNG_MZVLB1T0HBLR-000L2_S4DZNX0R362286
DISKS="$DISK"
# create partition table on all disks and EFI partition
RAID=""
for D in $DISKS; do
# kill old data
sgdisk --zap-all $D
blkdiscard -v -f $D
wipefs -a $D
sleep 5
# Create partition table
parted $D -- mklabel gpt
# Create a /boot as $D-part1
parted $D -- mkpart ESP fat32 1MiB 1024MiB
parted $D -- set 1 boot on
# Create a /nix as $D-part2
parted $D -- mkpart NIX 1024MiB 100%
# boot partition after short sleep, needed on some machines
sleep 5
mkfs.vfat $D-part1
# add part2 to raid
RAID="$RAID $D-part2"
done
# take a look at the partitions
lsblk
# ZFS zpool creation with compression and encryption
zpool create \
-o ashift=13 \
-o autotrim=off \
-O acltype=posixacl \
-O atime=off \
-O canmount=off \
-O checksum=blake3 \
-O compression=lz4 \
-O dnodesize=auto \
-O utf8only=on \
-O normalization=none \
-O xattr=sa \
-O mountpoint=none \
-O encryption=on \
-O keylocation=prompt \
-O keyformat=passphrase \
zpool $RAID
sleep 5
# take a look at the partitions
lsblk
# show the pool
zpool status
sleep 5
# create all the volumes
zfs create -o recordsize=64K -o mountpoint=legacy zpool/data
zfs create -o recordsize=64K -o mountpoint=legacy zpool/nix
zfs create -o recordsize=64K -o mountpoint=legacy zpool/root
sleep 5
# show the pool
zpool status
sleep 5
# create ZFS snapshot that we'll rollback to on boot
# see https://ryanseipp.com/post/nixos-encrypted-root/
zfs snapshot zpool/root@blank
sleep 5
# prepare install, root
mount -t zfs zpool/root /mnt
# Create directories to mount file systems on
mkdir -p /mnt/{data,nix,boot,root,etc/nixos}
# mount the ESP
mount $DISK-part1 /mnt/boot
# mount volumes
mount -t zfs zpool/data /mnt/data
mount -t zfs zpool/nix /mnt/nix
# bind mount persistent stuff to data
mkdir -p /mnt/data/{root,nixos/$HOST}
mount --bind /mnt/data/root /mnt/root
mount --bind /mnt/data/nixos/$HOST /mnt/etc/nixos
# create fake /data to have the right paths
mkdir -p /data
mount --bind /mnt/data /data
# take a look
mount
# configure
nixos-generate-config --root /mnt
# copy config data from another machine including secrets
doas scp -r /data/nixos root@192.168.13.102:/mnt/data
# install
nixos-install --option experimental-features 'nix-command flakes' --no-root-passwd --root /mnt
# unmount all stuff and sync
umount -Rl /data /mnt
zpool export -a
sync
# shutdown once
shutdown now