Files
lavitz/scripts/init.sh
2026-01-22 11:18:44 -07:00

81 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
TARGET_DIR="$HOME/Development/lavitz"
NIXOS_DIR="/etc/nixos"
CURRENT_DIR=$(pwd)
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${GREEN}NixOS Configuration Setup${NC}"
echo ""
if [ "$CURRENT_DIR" != "$TARGET_DIR" ]; then
echo -e "${YELLOW}Repository is not in $TARGET_DIR${NC}"
if [ -d "$TARGET_DIR" ]; then
echo -e "${RED}$TARGET_DIR already exists!${NC}"
echo "Please remove it or move this repo manually."
exit 1
fi
echo "Creating ~/Development directory..."
mkdir -p "$HOME/Development"
echo "Moving repository to $TARGET_DIR..."
mv "$CURRENT_DIR" "$TARGET_DIR"
echo -e "${GREEN}Repository moved to $TARGET_DIR${NC}"
echo ""
echo -e "${YELLOW}Please cd to $TARGET_DIR and run 'make init' again${NC}"
exit 0
fi
echo -e "${GREEN}Repository is in correct location: $TARGET_DIR${NC}"
echo ""
if [ ! -f "$TARGET_DIR/hardware-configuration.nix" ]; then
if [ -f "/etc/nixos/hardware-configuration.nix" ]; then
cp /etc/nixos/hardware-configuration.nix "$TARGET_DIR/hardware-configuration.nix"
echo -e "${GREEN}Copied hardware-configuration.nix from /etc/nixos${NC}"
elif [ -f "/etc/nixos.bak/hardware-configuration.nix" ]; then
cp /etc/nixos.bak/hardware-configuration.nix "$TARGET_DIR/hardware-configuration.nix"
echo -e "${GREEN}Copied hardware-configuration.nix from /etc/nixos.bak${NC}"
else
echo -e "${YELLOW}Generating hardware-configuration.nix...${NC}"
sudo nixos-generate-config --show-hardware-config > "$TARGET_DIR/hardware-configuration.nix"
echo -e "${GREEN}Generated hardware-configuration.nix${NC}"
fi
else
echo -e "${GREEN}hardware-configuration.nix already exists${NC}"
fi
if [ -L "$NIXOS_DIR" ]; then
echo -e "${YELLOW}/etc/nixos is already a symlink${NC}"
sudo rm "$NIXOS_DIR"
elif [ -d "$NIXOS_DIR" ]; then
echo -e "${YELLOW}Backing up existing /etc/nixos to /etc/nixos.bak${NC}"
sudo mv "$NIXOS_DIR" "${NIXOS_DIR}.bak"
fi
echo "Creating symlink: $TARGET_DIR -> $NIXOS_DIR"
sudo ln -sf "$TARGET_DIR" "$NIXOS_DIR"
if [ -d "$TARGET_DIR/.git" ]; then
echo ""
echo -e "${GREEN}Initializing git repository...${NC}"
cd "$TARGET_DIR"
git add .
echo -e "${GREEN}Files staged for commit${NC}"
fi
echo ""
echo -e "${GREEN}Setup complete!${NC}"
echo ""
echo "Next steps:"
echo " 1. Review the configuration files"
echo " 2. Run 'sudo nixos-rebuild switch --flake .#lavitz' to apply"