-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
Β·156 lines (135 loc) Β· 5.2 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
Β·156 lines (135 loc) Β· 5.2 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
# Home Manager with Nix setup script
set -e
# Parse command line arguments
LIVE_MODE=false
if [[ "$1" == "--live" || "$1" == "-l" ]]; then
LIVE_MODE=true
fi
if [[ "$LIVE_MODE" == "true" ]]; then
echo "π Starting Home Manager Live Mode..."
echo "Monitoring nix files for changes..."
else
echo "π Setting up Home Manager with Nix..."
fi
echo ""
# Check if nix is installed
if ! command -v nix &> /dev/null; then
echo "β Error: Nix is not installed."
echo "Please install Nix first with:"
echo " curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install"
exit 1
fi
echo "β
Nix is installed"
echo "βΉοΈ Using direct flake activation (no separate Home Manager installation needed)"
# Function to apply home manager configuration
apply_config() {
echo "π Applying configuration..."
if nix --extra-experimental-features "nix-command flakes" run .#homeConfigurations.aragao.activationPackage; then
echo "β
Home Manager configuration applied successfully!"
return 0
else
echo "β Failed to apply Home Manager configuration"
return 1
fi
}
# Update flake inputs to latest versions (using experimental features)
echo "π Updating flake inputs to latest versions..."
if nix --extra-experimental-features "nix-command flakes" flake update; then
echo "β
Flake inputs updated"
else
echo "β οΈ Failed to update flake inputs, continuing with existing versions..."
fi
# Validate flake configuration (using experimental features)
echo "π Validating flake configuration..."
if ! nix --extra-experimental-features "nix-command flakes" flake check 2>/dev/null; then
echo "β Flake validation failed. Please check your configuration."
exit 1
fi
echo "β
Flake configuration is valid"
# Apply Home Manager configuration
echo ""
echo "π Applying Home Manager configuration..."
# Apply the configuration
if apply_config; then
# Verify that Home Manager nix settings are applied
echo "π Verifying nix experimental features are enabled..."
if nix --help | grep -q "flakes" 2>/dev/null; then
echo "β
Nix experimental features are working"
else
echo "β οΈ Nix experimental features may not be fully applied"
echo " You may need to restart your shell or terminal"
fi
echo ""
echo "π Setup complete!"
echo ""
echo "Next steps:"
echo " 1. Update your Git email in home.nix if needed"
echo " 2. Restart your terminal to apply all changes"
echo " 3. Your fish shell is available with custom aliases and prompt"
echo ""
echo "To make future changes:"
echo " - Edit home.nix"
echo " - Run: nix run .#homeConfigurations.aragao.activationPackage"
echo " - Or use the traditional: home-manager switch --flake .#aragao"
echo ""
else
echo "β Failed to apply Home Manager configuration"
echo "Check the error messages above and try again."
exit 1
fi
# Live mode - monitor files and auto-apply changes
if [[ "$LIVE_MODE" == "true" ]]; then
echo ""
echo "π Entering live mode - monitoring nix files for changes..."
echo "Press Ctrl+C to exit live mode"
echo ""
# Create a temporary script for the live mode command
LIVE_SCRIPT=$(mktemp)
cat > "$LIVE_SCRIPT" << 'EOF'
#!/bin/bash
# Debounce function to prevent multiple rapid executions
if [[ -f /tmp/nix-live-mode.lock ]]; then
echo "β³ Update already in progress, skipping..."
exit 0
fi
# Create lock file
touch /tmp/nix-live-mode.lock
echo "π Nix file changed - reapplying configuration..."
echo "β° $(date)"
# Apply configuration
if nix --extra-experimental-features "nix-command flakes" run .#homeConfigurations.aragao.activationPackage 2>&1; then
echo "β
Configuration applied successfully!"
else
echo "β Configuration failed - check your nix files"
echo "π Error details were shown above"
echo "π Continuing to monitor for file changes..."
fi
# Remove lock file after a short delay to allow for file operations to complete
sleep 1
rm -f /tmp/nix-live-mode.lock
echo "π Watching for more changes..."
echo ""
EOF
chmod +x "$LIVE_SCRIPT"
# Monitor all .nix files and flake.lock for changes
# Alternative: Use inotifywait for more reliable file monitoring (if available)
if command -v inotifywait &> /dev/null; then
echo "π Using inotifywait for file monitoring (more reliable)"
echo "π Waiting for file changes... (no initial update)"
while true; do
# Wait for file changes, then execute the update script
inotifywait -q -e modify,create,delete -r . --include=".*\.nix$" --include="flake\.lock" 2>/dev/null
if [[ $? -eq 0 ]]; then
"$LIVE_SCRIPT"
fi
done
else
echo "π Using entr for file monitoring"
echo "π Waiting for file changes... (no initial update)"
# Use entr without -r flag to avoid automatic restarts
find . -name "*.nix" -o -name "flake.lock" | entr "$LIVE_SCRIPT"
fi
# Clean up temporary script on exit
trap "rm -f '$LIVE_SCRIPT' /tmp/nix-live-mode.lock; echo 'π§Ή Cleaned up live mode files'; exit" INT TERM EXIT
fi