-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
101 lines (89 loc) · 4.08 KB
/
Copy pathsetup
File metadata and controls
101 lines (89 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
set -uo pipefail
errors=()
LOCAL_BIN="$HOME/.local/bin"
GPGID=0x03BC4AD253B82986
mkdir -p $LOCAL_BIN
# If $HOME/.local/bin not in path, add it
if [ -d "$LOCAL_BIN" ] && [[ ":$PATH:" != *":$LOCAL_BIN:"* ]]; then
PATH="${PATH:+"$PATH:"}$LOCAL_BIN"
fi
# Setup gpg
if ! gpg --receive-keys $GPGID; then
errors+=("GPG key retrieval failed — run 'gpg --receive-keys $GPGID' manually")
fi
# Install and initialize chezmoi in one go
if ! command -v chezmoi > /dev/null; then
if sh -c "$(curl -fsLS get.chezmoi.io)" -- -b $LOCAL_BIN init --apply git@github.com:nimser/private-dotfiles-devcontainer.git --exclude=encrypted; then
echo "🥁 Only non-encrypted files where applied. Please run 'chezmoi apply --include=encrypted' if needed."
else
errors+=("chezmoi init/apply failed — install chezmoi manually or check network connection")
fi
fi
# Install nix for dependencies that don't have a binary on github (would use mise otherwise)
# and detect install path from nix feature instead for devcontainers
for f in /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh /etc/profile.d/nix.sh ~/.nix-profile/etc/profile.d/nix.sh; do
if [ -f "$f" ]; then
source "$f"
break
fi
done
# Fallback: aggressively hunt for nix-env anywhere under /nix or ~/.nix-profile
if ! command -v nix-env &>/dev/null; then
for d in /nix/var/nix/profiles/default/bin ~/.nix-profile/bin; do
if [ -x "$d/nix-env" ]; then
export PATH="$PATH:$d"
break
fi
done
# Last resort: find the binary wherever it lives
if ! command -v nix-env &>/dev/null; then
nix_env_path=$(find /nix /root/.nix-profile "$HOME/.nix-profile" -name nix-env -type f 2>/dev/null | head -1 || true)
if [ -n "$nix_env_path" ] && [ -x "$nix_env_path" ]; then
export PATH="$PATH:$(dirname "$nix_env_path")"
fi
fi
fi
if ! command -v nix-env &>/dev/null && [ ! -d "/nix" ]; then
echo "🥁 nix-env command not found. Attempting to install Nix..."
if sh <(curl -L https://nixos.org/nix/install) --daemon --yes; then
if [ -f /etc/profile.d/nix.sh ]; then source /etc/profile.d/nix.sh; fi
else
errors+=("Nix installation failed — reinstall shell or source /etc/profile.d/nix.sh")
fi
fi
if command -v nix-env &>/dev/null; then
if [ -f $HOME/.config/nixpkgs/config.nix ]; then
# Set system type if not provided via cli
export SYSTEM_TYPE=${SYSTEM_TYPE:-server}
export NIX_REMOTE=""
# Install all packages defined in install.nix
if ! nix-env -f $HOME/.config/nixpkgs/install.nix -iA myPackages --impure; then
errors+=("nix-env install failed — run 'nix-env -f ~/.config/nixpkgs/install.nix -iA myPackages --impure' manually")
fi
else
echo "💥 WARNING: Nix configuration file not found"
echo "Ensure chezmoi has run and deployed it correctly."
errors+=("Nix config not found at ~/.config/nixpkgs/config.nix — check chezmoi apply")
fi
else
echo "⚠️ nix-env not available after install attempt — skipping nix package install"
echo " Restart your shell or run: source /etc/profile.d/nix.sh && nix-env -f $HOME/.config/nixpkgs/install.nix -iA myPackages --impure"
errors+=("nix-env not available — packages from install.nix were not installed")
fi
# Summary
if [ "${#errors[@]}" -gt 0 ]; then
echo ""
echo "╔════════════════════════════════════════════════════════╗"
echo "║ ⚠️ Setup completed with errors ║"
echo "╠════════════════════════════════════════════════════════╣"
for err in "${errors[@]}"; do
echo "║ ❌ $err"
done
echo "╚════════════════════════════════════════════════════════╝"
echo ""
echo " 🏁 Setup continues — workspace will still be usable. Fix the above at your convenience."
echo ""
fi
echo "✅ Finished setting up dotfiles"
exit 0