diff --git a/scripts/init.sh b/scripts/init.sh index 276860a..4f3a9bc 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -37,12 +37,20 @@ fi echo -e "${GREEN}Repository is in correct location: $TARGET_DIR${NC}" echo "" -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${NC}" +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 "${YELLOW}No hardware-configuration.nix found${NC}" - echo "Run 'sudo nixos-generate-config' first if this is a fresh install" + echo -e "${GREEN}hardware-configuration.nix already exists${NC}" fi if [ -L "$NIXOS_DIR" ]; then @@ -56,10 +64,17 @@ 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. Ensure hardware-configuration.nix exists in $TARGET_DIR" -echo " 2. Run 'git add .' to track files (required for flakes)" -echo " 3. Run 'sudo nixos-rebuild switch --flake .#lavitz'" +echo " 1. Review the configuration files" +echo " 2. Run 'sudo nixos-rebuild switch --flake .#lavitz' to apply"