-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.nix
More file actions
227 lines (196 loc) · 5.91 KB
/
shell.nix
File metadata and controls
227 lines (196 loc) · 5.91 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
{ pkgs ? import <nixpkgs> {} }:
let
pythonEnv = pkgs.python3.withPackages (ps: with ps; [
fastapi
uvicorn
requests
pydantic
python-multipart
pytest
pytest-asyncio
mypy
httpx # For testing FastAPI
]);
# Script to load environment variables and run the app
startScript = pkgs.writeShellScriptBin "trueeye-start" ''
set -e
echo "🧿 TrueEye - Intelligent Media Literacy System"
echo "=============================================="
# Check if configuration file exists
if [ ! -f ".env" ]; then
if [ -f ".env.example" ]; then
echo "⚠️ No .env file found"
echo "📋 Copying .env.example to .env..."
cp .env.example .env
echo "✅ .env file created. You can edit it to change the configuration."
else
echo "❌ .env.example not found. Creating default configuration..."
cat > .env << 'EOF'
TE_PROVIDER=local
FLOW_API_URL=
PORT=8000
HOST=0.0.0.0
LOG_LEVEL=INFO
EOF
fi
fi
# Load environment variables
echo "🔧 Loading configuration from .env..."
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
# Default values if not defined
export PORT=''${PORT:-8000}
export HOST=''${HOST:-0.0.0.0}
export TE_PROVIDER=''${TE_PROVIDER:-local}
echo "📡 Provider: $TE_PROVIDER"
echo "🌐 Server: http://$HOST:$PORT"
if [ "$TE_PROVIDER" = "remote" ] && [ -z "$FLOW_API_URL" ]; then
echo "⚠️ Warning: FLOW_API_URL is not configured for remote mode"
fi
echo ""
echo "🚀 Starting TrueEye..."
echo " Press Ctrl+C to stop"
echo ""
# Run the application
exec ${pythonEnv}/bin/uvicorn trueeye.api:create_app --factory --host "$HOST" --port "$PORT" --reload
'';
# Development script with useful commands
devScript = pkgs.writeShellScriptBin "trueeye-dev" ''
set -e
echo "🧿 TrueEye - Development Mode"
echo "============================"
echo ""
echo "Available commands:"
echo " trueeye-start - Start the application"
echo " trueeye-test - Run tests"
echo " trueeye-config - Edit configuration"
echo " trueeye-help - Show this help"
echo ""
# If there are arguments, execute the specific command
if [ $# -gt 0 ]; then
case "$1" in
"start")
exec trueeye-start
;;
"test")
exec trueeye-test
;;
"config")
exec trueeye-config
;;
"help")
exec trueeye-help
;;
*)
echo "❌ Unknown command: $1"
echo "Use 'trueeye-help' to see available commands"
exit 1
;;
esac
else
# No arguments, start the application directly
exec trueeye-start
fi
'';
# Script to run tests
testScript = pkgs.writeShellScriptBin "trueeye-test" ''
set -e
echo "🧪 Running TrueEye tests..."
# Load environment variables for tests
if [ -f ".env" ]; then
export $(cat .env | grep -v '^#' | grep -v '^$' | xargs)
fi
cd ${toString ./.}
${pythonEnv}/bin/python -m pytest tests/ -v
'';
# Script to edit configuration
configScript = pkgs.writeShellScriptBin "trueeye-config" ''
set -e
# Check if .env exists
if [ ! -f ".env" ]; then
if [ -f ".env.example" ]; then
cp .env.example .env
echo "✅ .env file created from .env.example"
else
echo "❌ .env.example not found"
exit 1
fi
fi
# Try to open with available editor
if command -v code >/dev/null 2>&1; then
code .env
elif command -v nano >/dev/null 2>&1; then
nano .env
elif command -v vim >/dev/null 2>&1; then
vim .env
else
echo "📝 Current .env contents:"
echo "========================"
cat .env
echo ""
echo "⚠️ No text editor found available."
echo "You can edit the .env file manually."
fi
'';
# Help script
helpScript = pkgs.writeShellScriptBin "trueeye-help" ''
cat << 'EOF'
🧿 TrueEye - Intelligent Media Literacy System
AVAILABLE COMMANDS:
trueeye-dev - Development mode (default command)
trueeye-start - Start the web application
trueeye-test - Run test suite
trueeye-config - Edit configuration file (.env)
trueeye-help - Show this help
CONFIGURATION:
The application is configured via the .env file
If it doesn't exist, it will be created automatically from .env.example
OPERATION MODES:
• local : Test responses (no external connection)
• remote : Connect to LangFlow API (requires FLOW_API_URL)
USAGE EXAMPLES:
nix-shell # Enter shell and run app
nix-shell --run trueeye-dev # Run directly
nix-shell --run trueeye-test # Just run tests
ACCESS:
Once started, the application will be available at:
http://localhost:8000 (by default)
For more information, check the README.md file
EOF
'';
in
pkgs.mkShell {
buildInputs = [
pythonEnv
startScript
devScript
testScript
configScript
helpScript
pkgs.curl # For manual API testing
pkgs.jq # To format JSON responses
pkgs.gnumake # To use Makefile
];
shellHook = ''
# Environment configuration
export PYTHONPATH="${toString ./.}/src:$PYTHONPATH"
# Create .pytest_cache directory if it doesn't exist
mkdir -p .pytest_cache
echo "🧿 TrueEye Development Shell"
echo "============================"
echo ""
echo "✅ Python environment configured"
echo "✅ FastAPI and dependencies available"
echo "✅ Development tools ready"
echo ""
echo "🚀 To start the application:"
echo " trueeye-dev"
echo ""
echo "📚 To see all commands:"
echo " trueeye-help"
echo ""
# Auto-run if we're not in an interactive shell
if [ -n "$TRUEEYE_AUTO_START" ]; then
trueeye-dev
fi
'';
}