Skip to content

Commit c903f43

Browse files
fix: repair pre-installed venv instead of nuking on import failure
The basalt golden image pre-installs /opt/cua/venv with cua-computer-server at build time. But on first boot, if the import check fails (e.g., library path mismatch between build-time and boot-time python), the script was deleting the entire venv and reinstalling from PyPI — adding ~10 minutes to first-boot startup. Now tries an in-place pip repair before falling back to full reinstall. This should make the pre-installed venv survive minor environment differences and keep boot time under 2 minutes.
1 parent c29ca14 commit c903f43

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

configuration.nix

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,27 @@ let
140140
# evdev needs kernel headers to build
141141
export C_INCLUDE_PATH="${pkgs.linuxHeaders}/include"
142142
143-
# Check if venv exists AND has computer_server installed
144-
if /opt/cua/venv/bin/python -c 'import computer_server' 2>/dev/null; then
143+
# Fast path: if the venv has computer_server installed, skip entirely.
144+
# Use the venv's own python to avoid PATH/library mismatches.
145+
if [ -x /opt/cua/venv/bin/python ] && /opt/cua/venv/bin/python -c 'import computer_server' 2>/dev/null; then
145146
echo "CUA API venv already set up, skipping"
146147
exit 0
147148
fi
148149
149-
# Remove broken venv if it exists
150+
# If venv exists but import failed, try an in-place repair before nuking.
151+
if [ -d /opt/cua/venv ] && [ -x /opt/cua/venv/bin/pip ]; then
152+
echo "Venv exists but computer_server import failed — attempting in-place repair..."
153+
/opt/cua/venv/bin/pip install cua-computer-server 2>/dev/null && {
154+
if /opt/cua/venv/bin/python -c 'import computer_server' 2>/dev/null; then
155+
echo "Repair succeeded, skipping full reinstall"
156+
chown -R cua:cua /opt/cua
157+
exit 0
158+
fi
159+
}
160+
echo "Repair failed, falling through to full reinstall"
161+
fi
162+
163+
# Full reinstall as last resort
150164
rm -rf /opt/cua/venv
151165
152166
echo "Setting up CUA API server..."

0 commit comments

Comments
 (0)