|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | +if ! command -v nix >/dev/null; then |
| 4 | + echo "Installing Nix package manager..." |
| 5 | + sh <(curl -L https://nixos.org/nix/install) --daemon |
| 6 | + if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then |
| 7 | + . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' |
| 8 | + fi |
| 9 | +fi |
| 10 | +REPO="https://github.com/qompassai/dotfiles" |
| 11 | +TARGET_DIR="$HOME/.dotfiles" |
| 12 | + |
| 13 | +if [ ! -d "$TARGET_DIR" ]; then |
| 14 | + git clone "$REPO" "$TARGET_DIR" |
| 15 | +else |
| 16 | + echo "Dotfiles already exist at $TARGET_DIR. Updating..." |
| 17 | + git -C "$TARGET_DIR" pull |
| 18 | +fi |
| 19 | +echo "Copying configuration files..." |
| 20 | +mkdir -p ~/.config |
| 21 | +rsync -av --no-perms --no-owner --no-group \ |
| 22 | + --include='home/' \ |
| 23 | + --exclude='*' \ |
| 24 | + "$TARGET_DIR/" "$HOME/.config/" |
| 25 | +if [ -d "$TARGET_DIR/.local" ]; then |
| 26 | + echo "Copying .local directory..." |
| 27 | + rsync -av --no-perms --no-owner --no-group \ |
| 28 | + "$TARGET_DIR/.local/" "$HOME/.local/" |
| 29 | +fi |
| 30 | +echo "Setting up Nix environment..." |
| 31 | +cd "$TARGET_DIR" |
| 32 | +nix flake update |
| 33 | + |
| 34 | +detect_shell() { |
| 35 | + if [ -n "$BASH_VERSION" ]; then |
| 36 | + echo "bash" |
| 37 | + elif [ -n "$ZSH_VERSION" ]; then |
| 38 | + echo "zsh" |
| 39 | + elif [ -n "$FISH_VERSION" ]; then |
| 40 | + echo "fish" |
| 41 | + else |
| 42 | + # Fallback to shell from $SHELL variable |
| 43 | + basename "${SHELL:-bash}" |
| 44 | + fi |
| 45 | +} |
| 46 | +USER_SHELL=$(detect_shell) |
| 47 | +echo "Detected shell: $USER_SHELL" |
| 48 | +nix develop --command "$USER_SHELL" |
0 commit comments