Last active
September 25, 2021 15:25
-
-
Save johnrichardrinehart/dbd1668d9c2281f70141ef5149f56f04 to your computer and use it in GitHub Desktop.
NixOS UEFI automated install
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Run with `sudo` | |
# Environment variables: | |
# NIXOS_INSTALL_SWAP_SIZE (default: "8GiB") | |
# NIXOS_INSTALL_ROOT_DRIVE (default: "/dev/sda") | |
# NIXOS_INSTALL_EDIT_CONFIGURATION_FILE (default: "yes", accepted value: "no") | |
# https://stackoverflow.com/a/2013589 | |
NIXOS_INSTALL_SWAP_SIZE="${NIXOS_INSTALL_SWAP_SIZE:=8GiB}" | |
NIXOS_INSTALL_ROOT_DRIVE="${NIXOS_INSTALL_ROOT_DRIVE:=/dev/sda}" | |
NIXOS_INSTALL_EDIT_CONFIGURATION_FILE="${NIXOS_INSTALL_EDIT_CONFIGURATION_FILE:=yes}" | |
parted "${NIXOS_INSTALL_ROOT_DRIVE}" -- mklabel gpt | |
parted "${NIXOS_INSTALL_ROOT_DRIVE}" -- mkpart primary 512MiB -"${NIXOS_INSTALL_SWAP_SIZE}" | |
parted "${NIXOS_INSTALL_ROOT_DRIVE}" -- mkpart primary linux-swap -"${NIXOS_INSTALL_SWAP_SIZE}" 100% | |
parted "${NIXOS_INSTALL_ROOT_DRIVE}" -- mkpart ESP fat32 1MiB 512MiB | |
parted "${NIXOS_INSTALL_ROOT_DRIVE}" -- set 3 esp on | |
mkfs.ext4 -L nixos "${NIXOS_INSTALL_ROOT_DRIVE}"1 # /dev/sda1 | |
sleep 1 | |
mkswap -L swap "${NIXOS_INSTALL_ROOT_DRIVE}"2 # /dev/sda2 | |
sleep 1 | |
mkfs.fat -F 32 -n boot "${NIXOS_INSTALL_ROOT_DRIVE}"3 # /dev/sda3 | |
sleep 1 | |
mount /dev/disk/by-label/nixos /mnt | |
mkdir -p /mnt/boot | |
mount /dev/disk/by-label/boot /mnt/boot | |
swapon "${NIXOS_INSTALL_ROOT_DRIVE}"2 | |
sleep 1 | |
nixos-generate-config --root /mnt | |
if [ "${NIXOS_INSTALL_EDIT_CONFIGURATION_FILE}" == "yes" ]; then | |
printf "You are about to enter vim to edit /mnt/etc/nix/configuration.nix\nPress any key to continue..." | |
read | |
vim /mnt/etc/nixos/configuration.nix | |
fi | |
printf "Installation will continue after this. Press any key to continue..." | |
read | |
nixos-install # now, wait a while |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment