2022-06-05 13:24:46 +00:00
|
|
|
{ pkgs, ... }: {
|
|
|
|
|
|
|
|
# Inspired by https://github.com/cleverca22/nix-tests/blob/master/kexec/justdoit.nix
|
2022-06-05 13:32:42 +00:00
|
|
|
# This script will partition and format drives; use at your own risk!
|
2022-06-05 13:24:46 +00:00
|
|
|
|
|
|
|
type = "app";
|
|
|
|
|
2022-08-08 00:32:11 +00:00
|
|
|
program = builtins.toString (pkgs.writeShellScript "installer" ''
|
2022-06-05 13:24:46 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
DISK=$1
|
|
|
|
FLAKE=$2
|
2022-06-05 13:32:42 +00:00
|
|
|
PARTITION_PREFIX=""
|
2022-06-05 13:24:46 +00:00
|
|
|
|
|
|
|
if [ -z "$DISK" ] || [ -z "$FLAKE" ]; then
|
2022-09-25 04:19:46 +00:00
|
|
|
${pkgs.gum}/bin/gum style --width 50 --margin "1 2" --padding "2 4" \
|
|
|
|
--foreground "#fb4934" \
|
|
|
|
"Missing required parameter." \
|
|
|
|
"Usage: installer -- <disk> <host>" \
|
2023-08-06 00:06:03 +00:00
|
|
|
"Example: installer -- nvme0n1 tempest" \
|
|
|
|
"Flake example: nix run github:nmasur/dotfiles#installer -- nvme0n1 tempest"
|
2022-06-05 13:32:42 +00:00
|
|
|
echo "(exiting)"
|
2022-06-05 13:24:46 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-06-05 13:32:42 +00:00
|
|
|
case "$DISK" in nvme*)
|
|
|
|
PARTITION_PREFIX="p"
|
|
|
|
esac
|
|
|
|
|
2022-09-25 04:19:46 +00:00
|
|
|
${pkgs.gum}/bin/gum confirm \
|
|
|
|
"This will ERASE ALL DATA on the disk /dev/''${DISK}. Are you sure you want to continue?" \
|
|
|
|
--default=false
|
|
|
|
|
|
|
|
${pkgs.parted}/bin/parted /dev/''${DISK} -- mklabel gpt
|
|
|
|
${pkgs.parted}/bin/parted /dev/''${DISK} -- mkpart primary 512MiB 100%
|
|
|
|
${pkgs.parted}/bin/parted /dev/''${DISK} -- mkpart ESP fat32 1MiB 512MiB
|
|
|
|
${pkgs.parted}/bin/parted /dev/''${DISK} -- set 3 esp on
|
2022-06-05 13:32:42 +00:00
|
|
|
mkfs.ext4 -L nixos /dev/''${DISK}''${PARTITION_PREFIX}1
|
|
|
|
mkfs.fat -F 32 -n boot /dev/''${DISK}''${PARTITION_PREFIX}2
|
2022-06-05 13:24:46 +00:00
|
|
|
|
|
|
|
mount /dev/disk/by-label/nixos /mnt
|
|
|
|
mkdir --parents /mnt/boot
|
|
|
|
mount /dev/disk/by-label/boot /mnt/boot
|
|
|
|
|
2022-09-25 04:19:46 +00:00
|
|
|
${pkgs.nixos-install-tools}/bin/nixos-install --flake github:nmasur/dotfiles#''${FLAKE}
|
2022-08-08 00:32:11 +00:00
|
|
|
'');
|
2022-06-05 13:24:46 +00:00
|
|
|
|
|
|
|
}
|