Skip to content

Instantly share code, notes, and snippets.

@ASBaumgarten
Last active January 26, 2023 00:08
Show Gist options
  • Save ASBaumgarten/7b2ba1c3663413e2f6e5d48cd7f0f2bf to your computer and use it in GitHub Desktop.
Save ASBaumgarten/7b2ba1c3663413e2f6e5d48cd7f0f2bf to your computer and use it in GitHub Desktop.
ChatGPT Generated NixOS install script
#!/bin/sh
# Specify the device to install NixOS on
device=/dev/sda
# Get total RAM size
ram_size=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
# Calculate swap partition size
swap_size=$((ram_size * 2))
# Create GPT partition table
sgdisk -o $device
# Create boot/EFI partition
sgdisk -n 1:0:+512M -t 1:ef00 $device
# Create root partition
sgdisk -n 2:0:+20G -t 2:8300 $device
# Create linux-swap partition
sgdisk -n 3:0:+${swap_size}K -t 3:8200 $device
# Format partitions
mkfs.fat -F32 ${device}1
mkfs.btrfs ${device}2
mkswap ${device}3
# Create BTRFS subvolumes
mount ${device}2 /mnt
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@var
btrfs subvolume create /mnt/@snapshots
# Mount subvolumes
mkdir /mnt/boot
mount ${device}1 /mnt/boot
mount -o subvol=@ ${device}2 /mnt
mkdir /mnt/home
mount -o subvol=@home ${device}2 /mnt/home
mkdir /mnt/var
mount -o subvol=@var ${device}2 /mnt/var
mkdir /mnt/.snapshots
mount -o subvol=@snapshots ${device}2 /mnt/.snapshots
# Activate swap
swapon ${device}3
# Generate `configuration.nix`
nixos-generate-config --root /mnt
# Open configuration
# Install NixOS
nixos-install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment