Something went wrong. Try again.
Kieran's opinionated (and probably slightly dumb) nix config
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141#!/usr/bin/env bash
# NixOS Installation Script# This script automates the post-network setup installation process
set -e # Exit on any error
echo "==== NixOS Installation Automation ===="echo "This script will automate the installation process after network setup."echo "Make sure you have already set up network connectivity before running this script."
# Verify network connectivityecho -n "Checking network connectivity... "if ping -c 1 1.1.1.1 &> /dev/null; then echo "Success!"else echo "Failed!" echo "Error: No internet connection detected. Please set up your network first." echo "You can use the following commands to connect to WiFi:" echo " sudo systemctl start wpa_supplicant" echo " wpa_cli" echo " > add_network 0" echo " > set_network 0 ssid \"your SSID\"" echo " > set_network 0 psk \"your password\"" echo " > enable network 0" echo " > exit" exit 1fi
# Get sudo privileges and maintain themecho "Acquiring root permissions..."sudo -v# Keep sudo privileges activewhile true; do sudo -v; sleep 60; done &KEEP_SUDO_PID=$!
# Function to clean up the background sudo process on exitcleanup() { kill $KEEP_SUDO_PID 2>/dev/null}trap cleanup EXIT
# Check if git is already enabled in the configurationecho "Checking git configuration..."if grep -q "programs.git.enable = true" /etc/nixos/configuration.nix; then echo "Git is already enabled in configuration.nix"else echo "Enabling git..." sudo sed -i 's/^{$/{\n programs.git.enable = true;/' /etc/nixos/configuration.nix sudo nixos-rebuild switchfi
# Download and run the disk configurationecho "Downloading and running disk configuration..."curl -L https://github.com/taciturnaxolotl/dots/raw/main/moonlark/disk-config.nix -o /tmp/disk-config.nixsudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode destroy,format,mount /tmp/disk-config.nix
# Generate NixOS configurationecho "Generating NixOS configuration..."sudo nixos-generate-config --root /mntcd /mnt/etc/nixos
# Check if repository already existsecho "Setting up configuration..."if [ -d ".git" ]; then echo "Configuration already exists, pulling latest changes..." sudo git pullelse # Clone the repository to the NixOS configuration directory echo "Cloning nixos repository..." sudo rm -f * sudo git clone https://github.com/taciturnaxolotl/dots.git .fi
# Prompt user for SSH key setupecho ""echo "SSH Key Setup"read -p "Do you want to add an SSH private key? (y/n): " add_ssh_keyif [[ "$add_ssh_key" =~ ^[Yy]$ ]]; then echo "How would you like to add your SSH key?" echo "1) From a local file" echo "2) From a URL" read -p "Enter your choice (1/2): " ssh_key_method
sudo mkdir -p /mnt/etc/ssh/
if [[ "$ssh_key_method" == "1" ]]; then echo "Please enter the path to your SSH private key:" read ssh_key_path
if [ -f "$ssh_key_path" ]; then sudo cp "$ssh_key_path" /mnt/etc/ssh/id_rsa sudo chmod 600 /mnt/etc/ssh/id_rsa echo "SSH key added from local file!" else echo "Warning: SSH key file not found. Proceeding without SSH key." fi elif [[ "$ssh_key_method" == "2" ]]; then echo "Please enter the URL to download your SSH private key:" read ssh_key_url
echo "Downloading SSH key from URL..." if curl -s "$ssh_key_url" -o /tmp/downloaded_ssh_key; then sudo mv /tmp/downloaded_ssh_key /mnt/etc/ssh/id_rsa sudo chmod 600 /mnt/etc/ssh/id_rsa echo "SSH key successfully downloaded and added!" else echo "Warning: Failed to download SSH key from URL. Proceeding without SSH key." fi else echo "Invalid choice. Proceeding without SSH key." fielse echo "Proceeding without SSH key."fi
# Prompt for hostname configurationecho ""echo "Hostname Configuration"echo "Available configurations in this repo:"echo "1) moonlark (default)"read -p "Which configuration would you like to use? (Press Enter for moonlark): " hostname_choicehostname=${hostname_choice:-moonlark}
# Install the flakeecho "Installing the flake for configuration: $hostname"sudo nixos-install --flake .#${hostname} --no-root-passwd
echo "Installation complete! The system will now reboot."echo ""echo "After reboot, you'll need to complete these post-installation tasks:"echo "1. Change your password"echo "2. Move config to local directory: sudo mv /etc/nixos ~/dots"echo "3. Link to /etc/nixos: sudo ln -s ~/dots /etc"echo "4. Change permissions: sudo chown -R \$(id -un):users ~/dots"echo "5. Setup fingerprint reader (optional): sudo fprintd-enroll -f right-index-finger \$(whoami)"
read -p "Press Enter to unmount and reboot..."sudo umount -R /mntsudo reboot