Kieran's opinionated (and probably slightly dumb) nix config
1#!/usr/bin/env bash 2 3# NixOS Post-Installation Script 4# This script automates the post-installation tasks after the first reboot 5 6set -e # Exit on any error 7 8echo "==== NixOS Post-Installation Setup ====" 9echo "This script will automate the post-installation tasks." 10 11# Function to print current step 12print_step() { 13 echo -e "\n\033[1;34m==== $1 ====\033[0m" 14} 15 16# Change password if needed 17print_step "Password Management" 18read -p "Do you want to change your password? (y/n): " change_password 19if [[ "$change_password" =~ ^[Yy]$ ]]; then 20 passwd 21 echo "Password changed successfully!" 22fi 23 24# Move config to local directory and fix permissions 25print_step "Setting up configuration files" 26if [ -L "/etc/nixos" ]; then 27 echo "Configuration is already properly set up." 28else 29 echo "Moving configuration to home directory..." 30 mkdir -p ~/etc 31 sudo mv /etc/nixos ~/etc/ 32 sudo ln -s ~/etc/nixos /etc/ 33 echo "Fixing permissions..." 34 sudo chown -R $(id -un):users ~/etc/nixos 35 sudo chown -R $(id -un) ~/etc/nixos/.* 36 echo "Configuration files moved and linked successfully!" 37fi 38 39# Setup fingerprint reader (optional) 40print_step "Fingerprint Reader Setup" 41read -p "Do you want to set up the fingerprint reader? (y/n): " setup_fingerprint 42if [[ "$setup_fingerprint" =~ ^[Yy]$ ]]; then 43 echo "Setting up fingerprint reader..." 44 echo "You may need to swipe your finger across the fingerprint sensor instead of simply laying it there." 45 sudo fprintd-enroll -f right-index-finger $(whoami) 46 echo "Verifying fingerprint..." 47 sudo fprintd-verify $(whoami) 48else 49 echo "Skipping fingerprint reader setup." 50fi 51 52# Git configuration 53print_step "Git Configuration" 54read -p "Do you want to configure Git? (y/n): " setup_git 55if [[ "$setup_git" =~ ^[Yy]$ ]]; then 56 read -p "Enter your Git taciturnaxolotl: " git_user 57 read -p "Enter your Git email: " git_email 58 59 git config --global user.name "$git_user" 60 git config --global user.email "$git_email" 61 62 echo "Git configuration complete!" 63fi 64 65# Rebuild system 66print_step "Rebuilding system" 67read -p "Do you want to rebuild the system to apply all changes? (y/n): " rebuild_system 68if [[ "$rebuild_system" =~ ^[Yy]$ ]]; then 69 echo "Rebuilding system..." 70 cd ~/etc/nixos 71 72 # Get the hostname to use for the rebuild 73 hostname=$(hostname) 74 echo "Current hostname: $hostname" 75 76 sudo nixos-rebuild switch --flake .#${hostname} 77 echo "System rebuilt successfully!" 78else 79 echo "Skipping system rebuild." 80fi 81 82print_step "Post-installation complete!" 83echo "Your NixOS setup is now complete! You may need to restart some applications or services for all changes to take effect." 84echo "To rebuild your system in the future, run: cd ~/etc/nixos && sudo nixos-rebuild switch --flake .#$(hostname)" 85echo "Enjoy your new NixOS installation!"