Handle initial install from ISO with disko, swap, and tmpfs expansion

This commit is contained in:
2026-04-07 08:19:35 +02:00
parent 0264d47ecb
commit 5976c858d7

View File

@@ -169,25 +169,54 @@
fi fi
HOSTNAME=$1 HOSTNAME=$1
FLAKE_DIR=$(pwd)
echo "🚀 Bootstrapping NixOS: $HOSTNAME" if [ ! -f /etc/os-release ]; then
echo "Cannot determine OS"
# Check if on NixOS
if [ -f /etc/os-release ]; then
. /etc/os-release
if [ "$ID" = "nixos" ]; then
echo " Running on NixOS"
sudo nixos-rebuild switch --flake ".#$HOSTNAME"
echo " NixOS system configured"
else
echo " Not on NixOS - installing home-manager only"
home-manager switch --flake ".#youruser@linux"
echo " Home manager configured"
fi
else
echo " Cannot determine OS"
exit 1 exit 1
fi fi
. /etc/os-release
if [ "$ID" != "nixos" ]; then
echo "Not on NixOS - installing home-manager only"
home-manager switch --flake "$FLAKE_DIR#youruser@linux"
echo "Home manager configured"
exit 0
fi
# Detect ISO/live environment: /nix/.rw-store is a tmpfs overlay
if grep -q "tmpfs /nix/.rw-store" /proc/mounts 2>/dev/null; then
echo "ISO environment detected - running full install for: $HOSTNAME"
# Step 1: Partition and format disk
echo "--- Step 1/4: Running disko ---"
sudo nix --extra-experimental-features "nix-command flakes" run \
github:nix-community/disko/latest -- \
--mode destroy,format,mount \
--flake "$FLAKE_DIR#$HOSTNAME"
# Step 2: Create swap file on installed root to relieve RAM pressure
echo "--- Step 2/4: Creating 2GB swap file ---"
sudo dd if=/dev/zero of=/mnt/swapfile bs=1M count=2048 status=progress
sudo chmod 600 /mnt/swapfile
sudo mkswap /mnt/swapfile
sudo swapon /mnt/swapfile
# Step 3: Expand /nix/.rw-store tmpfs (default is too small for install)
echo "--- Step 3/4: Expanding /nix/.rw-store to 3G ---"
sudo mount -o remount,size=3G /nix/.rw-store
# Step 4: Install NixOS
echo "--- Step 4/4: Running nixos-install ---"
sudo nixos-install --flake "$FLAKE_DIR#$HOSTNAME"
echo "Installation complete! Remove the ISO and reboot."
else
echo "Installed NixOS detected - switching configuration"
sudo nixos-rebuild switch --flake "$FLAKE_DIR#$HOSTNAME"
echo "NixOS system configured"
fi
''); '');
}; };
in { in {