Skip to content
Snippets Groups Projects
Commit 01c36340 authored by Jens Nolte's avatar Jens Nolte
Browse files

Add pi installation script (incomplete)

parent 1a0518a6
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env zsh
set -e
set -u
set -x
set -o pipefail
source $DOTFILES_PATH/bin/lib/util.zsh
cmdname=$(basename $0)
usage() {
print "Usage: $cmdname <machine>" >&2
}
readonly machine="$1"
# Update nar-hash of dotfiles repository
nix flake lock --update-input dotfiles "path:$MACHINES_PATH"
readonly nix=(nix --log-format bar-with-logs)
# Installables
readonly system_installable="path:$MACHINES_PATH#nixosConfigurations.$machine.config.system.build.toplevel"
# Build once to catch errors
$nix build --keep-going --no-link $system_installable
# Use cached build to get output path
readonly nixos_config_path=$($nix build --json --no-link $system_installable | jq --raw-output ".[0].outputs.out")
# NOTE: Update if required
readonly target_disk="/dev/disk/by-id/usb-Generic_MassStorageClass_000000001538-0:1"
# NOTE: Update for each new installation
readonly boot_partition_uuid="a305b625-f427-4e64-8d8f-cadb1105ea64"
readonly root_partition_uuid="184a74e1-894b-4319-b9c9-9b0f972a30f8"
# NOTE: Update for each new installation
readonly root_uuid="dec6d7a8-6f97-4f4e-aaeb-98fd1e6bda27"
# NOTE: Update for each new installation
# Unsigned int
readonly disk_id="13000001"
# Derived paths
#readonly boot_partition="/dev/disk/by-partuuid/$boot_partition_uuid"
#readonly root_partition="/dev/disk/by-partuuid/$root_partition_uuid"
readonly boot_partition="/dev/disk/by-partuuid/$disk_id-01"
readonly root_partition="/dev/disk/by-partuuid/$disk_id-02"
sudo wipefs -a $target_disk
# nested gpt/dos doesn't seem to work
#sudo nix shell nixpkgs#util-linux -c sfdisk $target_disk <<EOF
# label: gpt
# unit: sectors
# sector-size: 512
#
# start=2048, size=512MiB, type=0fc63daf-8483-4772-8e79-3d69d8477de4, uuid=$boot_partition_uuid, name="boot"
# type=69dad710-2ce4-4e3c-b16c-21a1d49abed3, uuid=$root_partition_uuid, name="root"
#EOF
#
#sudo nix shell nixpkgs#util-linux -c sfdisk --label-nested dos $target_disk <<EOF
# label: dos
# sector-size: 512
#
# start=2048, size=512MiB, type=0c, bootable
# start=1, size=2047, type=ee
#EOF
sudo nix shell nixpkgs#util-linux -c sfdisk $target_disk <<EOF
label: dos
label-id: 0x$disk_id
unit: sectors
sector-size: 512
start=2048, size=512MiB, type=0c, bootable
type=83
EOF
sleep 2s
sudo wipefs -a $boot_partition
sudo wipefs -a $root_partition
# partprobe doesn't seem to be enough for symlinks to appear?
while [[ ! -b $boot_partition ]] {
print "Waiting for $boot_partition"
sleep 1s
}
sudo mkfs.fat -F32 -n PI_BOOT $boot_partition
# partprobe doesn't seem to be enough for symlinks to appear?
while [[ ! -b $root_partition ]] {
print "Waiting for $root_partition"
sleep 1s
}
sudo mkfs.ext4 -U $root_uuid -L root_$machine $root_partition
mount_point=/mnt/mnt
sudo mount $root_partition $mount_point
sudo mkdir $mount_point/boot
sudo mount $boot_partition $mount_point/boot
sudo $nix copy --no-check-sigs --to "$mount_point" $nixos_config_path
print "Setting system profile"
sudo nix-env --store $mount_point --profile $mount_point/nix/var/nix/profiles/system --set $nixos_config_path
print "Creating /etc/NIXOS"
sudo mkdir -m 0755 -p "$mount_point/etc"
sudo touch "$mount_point/etc/NIXOS"
# Bootloader installation: broken when installing across architectures
#sudo nixos-enter --root $mount_point -c "NIXOS_INSTALL_BOOTLOADER=1 $nixos_config_path/bin/switch-to-configuration boot"
# Manual steps:
# - open switch-to-configuration script
# - look for "Install or update the bootloader."
# - run extlinux-conf-builder.sh:
# /nix/store/[...]-extlinux-conf-builder.sh -d /mnt/mnt/boot -c $nixos_config_path -t 5
echo "Manual bootloader installation required"
echo "- Find bootloader installation in: $nixos_config_path/bin/switch-to-configuration"
echo "- Then run extlinux-builder: sudo /nix/store/[...]-extlinux-conf-builder.sh -d $mount_point/boot -c $nixos_config_path -t 5"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment