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 sudo mv /etc/nixos ~/dots
31 sudo ln -s ~/dots /etc/
32 echo "Fixing permissions..."
33 sudo chown -R $(id -un):users ~/dots
34 sudo chown -R $(id -un) ~/dots/.*
35 echo "Configuration files moved and linked successfully!"
36fi
37
38# Setup fingerprint reader (optional)
39print_step "Fingerprint Reader Setup"
40read -p "Do you want to set up the fingerprint reader? (y/n): " setup_fingerprint
41if [[ "$setup_fingerprint" =~ ^[Yy]$ ]]; then
42 echo "Setting up fingerprint reader..."
43 echo "You may need to swipe your finger across the fingerprint sensor instead of simply laying it there."
44 sudo fprintd-enroll -f right-index-finger $(whoami)
45 echo "Verifying fingerprint..."
46 sudo fprintd-verify $(whoami)
47else
48 echo "Skipping fingerprint reader setup."
49fi
50
51# Git configuration
52print_step "Git Configuration"
53read -p "Do you want to configure Git? (y/n): " setup_git
54if [[ "$setup_git" =~ ^[Yy]$ ]]; then
55 read -p "Enter your Git taciturnaxolotl: " git_user
56 read -p "Enter your Git email: " git_email
57
58 git config --global user.name "$git_user"
59 git config --global user.email "$git_email"
60
61 echo "Git configuration complete!"
62fi
63
64# Rebuild system
65print_step "Rebuilding system"
66read -p "Do you want to rebuild the system to apply all changes? (y/n): " rebuild_system
67if [[ "$rebuild_system" =~ ^[Yy]$ ]]; then
68 echo "Rebuilding system..."
69 cd ~/dots
70
71 # Get the hostname to use for the rebuild
72 hostname=$(hostname)
73 echo "Current hostname: $hostname"
74
75 sudo nixos-rebuild switch --flake .#${hostname}
76 echo "System rebuilt successfully!"
77else
78 echo "Skipping system rebuild."
79fi
80
81print_step "Post-installation complete!"
82echo "Your NixOS setup is now complete! You may need to restart some applications or services for all changes to take effect."
83echo "To rebuild your system in the future, run: cd ~/dots && sudo nixos-rebuild switch --flake .#$(hostname)"
84echo "Enjoy your new NixOS installation!"