2024-07-31 23:43:50 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Install nixos to specified drive. To be run from Live ISO.
|
|
|
|
# Usage: ./Bootstrap.sh <DRIVE> [HOST]
|
2024-11-15 06:32:44 +03:00
|
|
|
cfg="$(realpath .)"
|
2024-07-31 23:43:50 +03:00
|
|
|
target="${1}"
|
|
|
|
host="${2}"
|
|
|
|
|
2024-12-18 09:46:54 +03:00
|
|
|
if [[ ${target} == "" ]]; then
|
2024-11-15 06:32:44 +03:00
|
|
|
printf "Usage: ./.Bootstrap.sh <DRIVE> [HOST]\n"
|
|
|
|
exit 2
|
2024-07-31 23:43:50 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Create partitions.
|
|
|
|
parted -s "${target}" mktable gpt
|
|
|
|
parted -s "${target}" mkpart primary 0% 512MB
|
|
|
|
parted -s "${target}" mkpart primary 512MB 100%
|
|
|
|
parted -s "${target}" name 1 NIXBOOT
|
|
|
|
parted -s "${target}" name 2 NIXROOT
|
|
|
|
parted -s "${target}" set 1 esp on
|
|
|
|
|
|
|
|
# Format.
|
|
|
|
mkfs.fat -F 32 /dev/disk/by-partlabel/NIXBOOT
|
|
|
|
mkfs.ext4 -F /dev/disk/by-partlabel/NIXROOT
|
|
|
|
|
|
|
|
# Mount.
|
|
|
|
mount /dev/disk/by-partlabel/NIXROOT /mnt
|
|
|
|
mkdir /mnt/boot
|
|
|
|
mount /dev/disk/by-partlabel/NIXBOOT /mnt/boot
|
|
|
|
|
|
|
|
# Generate config.
|
|
|
|
nixos-generate-config --root /mnt
|
|
|
|
|
|
|
|
# Install.
|
|
|
|
cd /mnt
|
2024-12-18 09:46:54 +03:00
|
|
|
if [[ ${host} == "" ]]; then
|
2024-07-31 23:43:50 +03:00
|
|
|
printf "Warning: Installing basic system.\n"
|
|
|
|
nixos-install
|
|
|
|
else
|
|
|
|
printf "Installing ${host}...\n"
|
2024-11-15 06:32:44 +03:00
|
|
|
nixos-install --no-root-password --no-channel-copy --flake "${cfg}#${host}"
|
2024-07-31 23:43:50 +03:00
|
|
|
fi
|